1 jest.setTimeout(120000);
12 searchForBetaCommunity,
26 import { PostResponse } from 'lemmy-js-client';
28 let postRes: PostResponse;
30 beforeAll(async () => {
32 await followBeta(alpha);
33 await followBeta(gamma);
34 let search = await searchForBetaCommunity(alpha);
36 postRes = await createPost(
38 search.communities.filter(c => c.local == false)[0].id
42 afterAll(async () => {
43 await unfollowRemotes(alpha);
44 await unfollowRemotes(gamma);
47 test('Create a comment', async () => {
48 let commentRes = await createComment(alpha, postRes.post.id);
49 expect(commentRes.comment.content).toBeDefined();
50 expect(commentRes.comment.community_local).toBe(false);
51 expect(commentRes.comment.creator_local).toBe(true);
52 expect(commentRes.comment.score).toBe(1);
55 // Make sure that comment is liked on beta
56 let searchBeta = await searchComment(beta, commentRes.comment);
57 let betaComment = searchBeta.comments[0];
58 expect(betaComment).toBeDefined();
59 expect(betaComment.community_local).toBe(true);
60 expect(betaComment.creator_local).toBe(false);
61 expect(betaComment.score).toBe(1);
64 test('Create a comment in a non-existent post', async () => {
65 let commentRes = await createComment(alpha, -1);
66 expect(commentRes).toStrictEqual({ error: 'couldnt_find_post' });
69 test('Update a comment', async () => {
70 let commentRes = await createComment(alpha, postRes.post.id);
72 let updateCommentRes = await updateComment(alpha, commentRes.comment.id);
73 expect(updateCommentRes.comment.content).toBe(
74 'A jest test federated comment update'
76 expect(updateCommentRes.comment.community_local).toBe(false);
77 expect(updateCommentRes.comment.creator_local).toBe(true);
80 // Make sure that post is updated on beta
81 let searchBeta = await searchComment(beta, commentRes.comment);
82 let betaComment = searchBeta.comments[0];
83 expect(betaComment.content).toBe('A jest test federated comment update');
86 test('Delete a comment', async () => {
87 let commentRes = await createComment(alpha, postRes.post.id);
90 let deleteCommentRes = await deleteComment(
95 expect(deleteCommentRes.comment.deleted).toBe(true);
98 // Make sure that comment is undefined on beta
99 let searchBeta = await searchComment(beta, commentRes.comment);
100 let betaComment = searchBeta.comments[0];
101 expect(betaComment).toBeUndefined();
104 let undeleteCommentRes = await deleteComment(
107 commentRes.comment.id
109 expect(undeleteCommentRes.comment.deleted).toBe(false);
112 // Make sure that comment is undeleted on beta
113 let searchBeta2 = await searchComment(beta, commentRes.comment);
114 let betaComment2 = searchBeta2.comments[0];
115 expect(betaComment2.deleted).toBe(false);
118 test('Remove a comment from admin and community on the same instance', async () => {
119 let commentRes = await createComment(alpha, postRes.post.id);
122 // Get the id for beta
123 let betaCommentId = (await searchComment(beta, commentRes.comment))
126 // The beta admin removes it (the community lives on beta)
127 let removeCommentRes = await removeComment(beta, true, betaCommentId);
128 expect(removeCommentRes.comment.removed).toBe(true);
131 // Make sure that comment is removed on alpha (it gets pushed since an admin from beta removed it)
132 let refetchedPost = await getPost(alpha, postRes.post.id);
133 expect(refetchedPost.comments[0].removed).toBe(true);
135 let unremoveCommentRes = await removeComment(beta, false, betaCommentId);
136 expect(unremoveCommentRes.comment.removed).toBe(false);
139 // Make sure that comment is unremoved on beta
140 let refetchedPost2 = await getPost(alpha, postRes.post.id);
141 expect(refetchedPost2.comments[0].removed).toBe(false);
144 test('Remove a comment from admin and community on different instance', async () => {
145 let alphaUser = await registerUser(alpha);
146 let newAlphaApi: API = {
147 client: alpha.client,
151 // New alpha user creates a community, post, and comment.
152 let newCommunity = await createCommunity(newAlphaApi);
154 let newPost = await createPost(newAlphaApi, newCommunity.community.id);
156 let commentRes = await createComment(newAlphaApi, newPost.post.id);
157 expect(commentRes.comment.content).toBeDefined();
160 // Beta searches that to cache it, then removes it
161 let searchBeta = await searchComment(beta, commentRes.comment);
162 let betaComment = searchBeta.comments[0];
163 let removeCommentRes = await removeComment(beta, true, betaComment.id);
164 expect(removeCommentRes.comment.removed).toBe(true);
167 // Make sure its not removed on alpha
168 let refetchedPost = await getPost(newAlphaApi, newPost.post.id);
169 expect(refetchedPost.comments[0].removed).toBe(false);
172 test('Unlike a comment', async () => {
173 let commentRes = await createComment(alpha, postRes.post.id);
175 let unlike = await likeComment(alpha, 0, commentRes.comment);
176 expect(unlike.comment.score).toBe(0);
179 // Make sure that post is unliked on beta
180 let searchBeta = await searchComment(beta, commentRes.comment);
181 let betaComment = searchBeta.comments[0];
182 expect(betaComment).toBeDefined();
183 expect(betaComment.community_local).toBe(true);
184 expect(betaComment.creator_local).toBe(false);
185 expect(betaComment.score).toBe(0);
188 test('Federated comment like', async () => {
189 let commentRes = await createComment(alpha, postRes.post.id);
192 // Find the comment on beta
193 let searchBeta = await searchComment(beta, commentRes.comment);
194 let betaComment = searchBeta.comments[0];
196 let like = await likeComment(beta, 1, betaComment);
197 expect(like.comment.score).toBe(2);
200 // Get the post from alpha, check the likes
201 let post = await getPost(alpha, postRes.post.id);
202 expect(post.comments[0].score).toBe(2);
205 test('Reply to a comment', async () => {
206 // Create a comment on alpha, find it on beta
207 let commentRes = await createComment(alpha, postRes.post.id);
209 let searchBeta = await searchComment(beta, commentRes.comment);
210 let betaComment = searchBeta.comments[0];
212 // find that comment id on beta
215 let replyRes = await createComment(beta, betaComment.post_id, betaComment.id);
216 expect(replyRes.comment.content).toBeDefined();
217 expect(replyRes.comment.community_local).toBe(true);
218 expect(replyRes.comment.creator_local).toBe(true);
219 expect(replyRes.comment.parent_id).toBe(betaComment.id);
220 expect(replyRes.comment.score).toBe(1);
223 // Make sure that comment is seen on alpha
224 // TODO not sure why, but a searchComment back to alpha, for the ap_id of betas
225 // comment, isn't working.
226 // let searchAlpha = await searchComment(alpha, replyRes.comment);
227 let post = await getPost(alpha, postRes.post.id);
228 let alphaComment = post.comments[0];
229 expect(alphaComment.content).toBeDefined();
230 expect(alphaComment.parent_id).toBe(post.comments[1].id);
231 expect(alphaComment.community_local).toBe(false);
232 expect(alphaComment.creator_local).toBe(false);
233 expect(alphaComment.score).toBe(1);
236 test('Mention beta', async () => {
237 // Create a mention on alpha
238 let mentionContent = 'A test mention of @lemmy_beta@lemmy-beta:8550';
239 let commentRes = await createComment(alpha, postRes.post.id);
241 let mentionRes = await createComment(
244 commentRes.comment.id,
247 expect(mentionRes.comment.content).toBeDefined();
248 expect(mentionRes.comment.community_local).toBe(false);
249 expect(mentionRes.comment.creator_local).toBe(true);
250 expect(mentionRes.comment.score).toBe(1);
253 let mentionsRes = await getMentions(beta);
254 expect(mentionsRes.mentions[0].content).toBeDefined();
255 expect(mentionsRes.mentions[0].community_local).toBe(true);
256 expect(mentionsRes.mentions[0].creator_local).toBe(false);
257 expect(mentionsRes.mentions[0].score).toBe(1);
260 test('Comment Search', async () => {
261 let commentRes = await createComment(alpha, postRes.post.id);
263 let searchBeta = await searchComment(beta, commentRes.comment);
264 expect(searchBeta.comments[0].ap_id).toBe(commentRes.comment.ap_id);
267 test('A and G subscribe to B (center) A posts, G mentions B, it gets announced to A', async () => {
268 // Create a local post
269 let alphaPost = await createPost(alpha, 2);
270 expect(alphaPost.post.community_local).toBe(true);
273 // Make sure gamma sees it
274 let search = await searchPost(gamma, alphaPost.post);
275 let gammaPost = search.posts[0];
278 'A jest test federated comment announce, lets mention @lemmy_beta@lemmy-beta:8550';
279 let commentRes = await createComment(
285 expect(commentRes.comment.content).toBe(commentContent);
286 expect(commentRes.comment.community_local).toBe(false);
287 expect(commentRes.comment.creator_local).toBe(true);
288 expect(commentRes.comment.score).toBe(1);
291 // Make sure alpha sees it
292 let alphaPost2 = await getPost(alpha, alphaPost.post.id);
293 expect(alphaPost2.comments[0].content).toBe(commentContent);
294 expect(alphaPost2.comments[0].community_local).toBe(true);
295 expect(alphaPost2.comments[0].creator_local).toBe(false);
296 expect(alphaPost2.comments[0].score).toBe(1);
298 // Make sure beta has mentions
299 let mentionsRes = await getMentions(beta);
300 expect(mentionsRes.mentions[0].content).toBe(commentContent);
301 expect(mentionsRes.mentions[0].community_local).toBe(false);
302 expect(mentionsRes.mentions[0].creator_local).toBe(false);
303 // TODO this is failing because fetchInReplyTos aren't getting score
304 // expect(mentionsRes.mentions[0].score).toBe(1);
307 test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedded comments, A subs to B, B updates the lowest level comment, A fetches both the post and all the inreplyto comments for that post.', async () => {
308 // Unfollow all remote communities
309 let followed = await unfollowRemotes(alpha);
311 followed.communities.filter(c => c.community_local == false).length
314 // B creates a post, and two comments, should be invisible to A
315 let postRes = await createPost(beta, 2);
316 expect(postRes.post.name).toBeDefined();
319 let parentCommentContent = 'An invisible top level comment from beta';
320 let parentCommentRes = await createComment(
326 expect(parentCommentRes.comment.content).toBe(parentCommentContent);
329 // B creates a comment, then a child one of that.
330 let childCommentContent = 'An invisible child comment from beta';
331 let childCommentRes = await createComment(
334 parentCommentRes.comment.id,
337 expect(childCommentRes.comment.content).toBe(childCommentContent);
341 let follow = await followBeta(alpha);
342 expect(follow.community.local).toBe(false);
343 expect(follow.community.name).toBe('main');
346 // An update to the child comment on beta, should push the post, parent, and child to alpha now
347 let updatedCommentContent = 'An update child comment from beta';
348 let updateRes = await updateComment(
350 childCommentRes.comment.id,
351 updatedCommentContent
353 expect(updateRes.comment.content).toBe(updatedCommentContent);
356 // Get the post from alpha
357 let search = await searchPost(alpha, postRes.post);
358 let alphaPostB = search.posts[0];
361 let alphaPost = await getPost(alpha, alphaPostB.id);
362 expect(alphaPost.post.name).toBeDefined();
363 expect(alphaPost.comments[1].content).toBe(parentCommentContent);
364 expect(alphaPost.comments[0].content).toBe(updatedCommentContent);
365 expect(alphaPost.post.community_local).toBe(false);
366 expect(alphaPost.post.creator_local).toBe(false);