11 searchForBetaCommunity,
24 import { PostResponse } from '../interfaces';
26 let postRes: PostResponse;
28 beforeAll(async () => {
30 await followBeta(alpha);
31 await followBeta(gamma);
32 let search = await searchForBetaCommunity(alpha);
33 postRes = await createPost(
35 search.communities.filter(c => c.local == false)[0].id
39 afterAll(async () => {
40 await unfollowRemotes(alpha);
41 await unfollowRemotes(gamma);
44 test('Create a comment', async () => {
45 let commentRes = await createComment(alpha, postRes.post.id);
46 expect(commentRes.comment.content).toBeDefined();
47 expect(commentRes.comment.community_local).toBe(false);
48 expect(commentRes.comment.creator_local).toBe(true);
49 expect(commentRes.comment.score).toBe(1);
51 // Make sure that comment is liked on beta
52 let searchBeta = await searchComment(beta, commentRes.comment);
53 let betaComment = searchBeta.comments[0];
54 expect(betaComment).toBeDefined();
55 expect(betaComment.community_local).toBe(true);
56 expect(betaComment.creator_local).toBe(false);
57 expect(betaComment.score).toBe(1);
60 test('Update a comment', async () => {
61 let commentRes = await createComment(alpha, postRes.post.id);
62 let updateCommentRes = await updateComment(alpha, commentRes.comment.id);
63 expect(updateCommentRes.comment.content).toBe(
64 'A jest test federated comment update'
66 expect(updateCommentRes.comment.community_local).toBe(false);
67 expect(updateCommentRes.comment.creator_local).toBe(true);
69 // Make sure that post is updated on beta
70 let searchBeta = await searchComment(beta, commentRes.comment);
71 let betaComment = searchBeta.comments[0];
72 expect(betaComment.content).toBe('A jest test federated comment update');
75 test('Delete a comment', async () => {
76 let commentRes = await createComment(alpha, postRes.post.id);
77 let deleteCommentRes = await deleteComment(
82 expect(deleteCommentRes.comment.deleted).toBe(true);
84 // Make sure that comment is deleted on beta
85 // The search doesnt work below, because it returns a tombstone / http::gone
86 // let searchBeta = await searchComment(beta, commentRes.comment);
87 // console.log(searchBeta);
88 // let betaComment = searchBeta.comments[0];
89 // Create a fake post, just to get the previous new post id
90 let createdBetaPostJustToGetId = await createPost(beta, 2);
91 let betaPost = await getPost(beta, createdBetaPostJustToGetId.post.id - 1);
92 let betaComment = betaPost.comments[0];
93 expect(betaComment.deleted).toBe(true);
95 let undeleteCommentRes = await deleteComment(
100 expect(undeleteCommentRes.comment.deleted).toBe(false);
102 // Make sure that comment is undeleted on beta
103 let searchBeta2 = await searchComment(beta, commentRes.comment);
104 let betaComment2 = searchBeta2.comments[0];
105 expect(betaComment2.deleted).toBe(false);
108 test('Remove a comment', async () => {
109 let commentRes = await createComment(alpha, postRes.post.id);
111 // Get the id for beta
112 let betaCommentId = (await searchComment(beta, commentRes.comment))
115 // The beta admin removes it (the community lives on beta)
116 let removeCommentRes = await removeComment(beta, true, betaCommentId);
117 expect(removeCommentRes.comment.removed).toBe(true);
119 // Make sure that comment is removed on alpha (it gets pushed since an admin from beta removed it)
120 let refetchedPost = await getPost(alpha, postRes.post.id);
121 expect(refetchedPost.comments[0].removed).toBe(true);
123 let unremoveCommentRes = await removeComment(beta, false, betaCommentId);
124 expect(unremoveCommentRes.comment.removed).toBe(false);
126 // Make sure that comment is unremoved on beta
127 let refetchedPost2 = await getPost(alpha, postRes.post.id);
128 expect(refetchedPost2.comments[0].removed).toBe(false);
131 test('Remove a comment from an admin on a different instance, make sure its not removed on the original', async () => {
132 let alphaUser = await registerUser(alpha);
133 let newAlphaApi: API = {
138 // New alpha user creates a community, post, and comment.
139 let newCommunity = await createCommunity(newAlphaApi);
140 let newPost = await createPost(newAlphaApi, newCommunity.community.id);
141 let commentRes = await createComment(newAlphaApi, newPost.post.id);
142 expect(commentRes.comment.content).toBeDefined();
144 // Beta searches that to cache it, then removes it
145 let searchBeta = await searchComment(beta, commentRes.comment);
146 let betaComment = searchBeta.comments[0];
147 let removeCommentRes = await removeComment(beta, true, betaComment.id);
148 expect(removeCommentRes.comment.removed).toBe(true);
150 // Make sure its not removed on alpha
151 let refetchedPost = await getPost(newAlphaApi, newPost.post.id);
152 expect(refetchedPost.comments[0].removed).toBe(false);
155 test('Unlike a comment', async () => {
156 let commentRes = await createComment(alpha, postRes.post.id);
157 let unlike = await likeComment(alpha, 0, commentRes.comment);
158 expect(unlike.comment.score).toBe(0);
160 // Make sure that post is unliked on beta
161 let searchBeta = await searchComment(beta, commentRes.comment);
162 let betaComment = searchBeta.comments[0];
163 expect(betaComment).toBeDefined();
164 expect(betaComment.community_local).toBe(true);
165 expect(betaComment.creator_local).toBe(false);
166 expect(betaComment.score).toBe(0);
169 test('Federated comment like', async () => {
170 let commentRes = await createComment(alpha, postRes.post.id);
172 // Find the comment on beta
173 let searchBeta = await searchComment(beta, commentRes.comment);
174 let betaComment = searchBeta.comments[0];
176 let like = await likeComment(beta, 1, betaComment);
177 expect(like.comment.score).toBe(2);
179 // Get the post from alpha, check the likes
180 let post = await getPost(alpha, postRes.post.id);
181 expect(post.comments[0].score).toBe(2);
184 test('Reply to a comment', async () => {
185 // Create a comment on alpha, find it on beta
186 let commentRes = await createComment(alpha, postRes.post.id);
187 let searchBeta = await searchComment(beta, commentRes.comment);
188 let betaComment = searchBeta.comments[0];
190 // find that comment id on beta
193 let replyRes = await createComment(beta, betaComment.post_id, betaComment.id);
194 expect(replyRes.comment.content).toBeDefined();
195 expect(replyRes.comment.community_local).toBe(true);
196 expect(replyRes.comment.creator_local).toBe(true);
197 expect(replyRes.comment.parent_id).toBe(betaComment.id);
198 expect(replyRes.comment.score).toBe(1);
200 // Make sure that comment is seen on alpha
201 // TODO not sure why, but a searchComment back to alpha, for the ap_id of betas
202 // comment, isn't working.
203 // let searchAlpha = await searchComment(alpha, replyRes.comment);
204 let post = await getPost(alpha, postRes.post.id);
205 let alphaComment = post.comments[0];
206 expect(alphaComment.content).toBeDefined();
207 expect(alphaComment.parent_id).toBe(post.comments[1].id);
208 expect(alphaComment.community_local).toBe(false);
209 expect(alphaComment.creator_local).toBe(false);
210 expect(alphaComment.score).toBe(1);
213 test('Mention beta', async () => {
214 // Create a mention on alpha
215 let mentionContent = 'A test mention of @lemmy_beta@lemmy-beta:8550';
216 let commentRes = await createComment(alpha, postRes.post.id);
217 let mentionRes = await createComment(
220 commentRes.comment.id,
223 expect(mentionRes.comment.content).toBeDefined();
224 expect(mentionRes.comment.community_local).toBe(false);
225 expect(mentionRes.comment.creator_local).toBe(true);
226 expect(mentionRes.comment.score).toBe(1);
228 let mentionsRes = await getMentions(beta);
229 expect(mentionsRes.mentions[0].content).toBeDefined();
230 expect(mentionsRes.mentions[0].community_local).toBe(true);
231 expect(mentionsRes.mentions[0].creator_local).toBe(false);
232 expect(mentionsRes.mentions[0].score).toBe(1);
235 test('Comment Search', async () => {
236 let commentRes = await createComment(alpha, postRes.post.id);
237 let searchBeta = await searchComment(beta, commentRes.comment);
238 expect(searchBeta.comments[0].ap_id).toBe(commentRes.comment.ap_id);
241 test('A and G subscribe to B (center) A posts, G mentions B, it gets announced to A', async () => {
242 // Create a local post
243 let alphaPost = await createPost(alpha, 2);
244 expect(alphaPost.post.community_local).toBe(true);
246 // Make sure gamma sees it
247 let search = await searchPost(gamma, alphaPost.post);
248 let gammaPost = search.posts[0];
251 'A jest test federated comment announce, lets mention @lemmy_beta@lemmy-beta:8550';
252 let commentRes = await createComment(
258 expect(commentRes.comment.content).toBe(commentContent);
259 expect(commentRes.comment.community_local).toBe(false);
260 expect(commentRes.comment.creator_local).toBe(true);
261 expect(commentRes.comment.score).toBe(1);
263 // Make sure alpha sees it
264 let alphaPost2 = await getPost(alpha, alphaPost.post.id);
265 expect(alphaPost2.comments[0].content).toBe(commentContent);
266 expect(alphaPost2.comments[0].community_local).toBe(true);
267 expect(alphaPost2.comments[0].creator_local).toBe(false);
268 expect(alphaPost2.comments[0].score).toBe(1);
270 // Make sure beta has mentions
271 let mentionsRes = await getMentions(beta);
272 expect(mentionsRes.mentions[0].content).toBe(commentContent);
273 expect(mentionsRes.mentions[0].community_local).toBe(false);
274 expect(mentionsRes.mentions[0].creator_local).toBe(false);
275 // TODO this is failing because fetchInReplyTos aren't getting score
276 // expect(mentionsRes.mentions[0].score).toBe(1);
279 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 () => {
280 // Unfollow all remote communities
281 let followed = await unfollowRemotes(alpha);
283 followed.communities.filter(c => c.community_local == false).length
286 // B creates a post, and two comments, should be invisible to A
287 let postRes = await createPost(beta, 2);
288 expect(postRes.post.name).toBeDefined();
290 let parentCommentContent = 'An invisible top level comment from beta';
291 let parentCommentRes = await createComment(
297 expect(parentCommentRes.comment.content).toBe(parentCommentContent);
299 // B creates a comment, then a child one of that.
300 let childCommentContent = 'An invisible child comment from beta';
301 let childCommentRes = await createComment(
304 parentCommentRes.comment.id,
307 expect(childCommentRes.comment.content).toBe(childCommentContent);
310 let follow = await followBeta(alpha);
311 expect(follow.community.local).toBe(false);
312 expect(follow.community.name).toBe('main');
314 // An update to the child comment on beta, should push the post, parent, and child to alpha now
315 let updatedCommentContent = 'An update child comment from beta';
316 let updateRes = await updateComment(
318 childCommentRes.comment.id,
319 updatedCommentContent
321 expect(updateRes.comment.content).toBe(updatedCommentContent);
323 // Get the post from alpha
324 let createFakeAlphaPostToGetId = await createPost(alpha, 2);
325 let alphaPost = await getPost(alpha, createFakeAlphaPostToGetId.post.id - 1);
326 expect(alphaPost.post.name).toBeDefined();
327 expect(alphaPost.comments[1].content).toBe(parentCommentContent);
328 expect(alphaPost.comments[0].content).toBe(updatedCommentContent);
329 expect(alphaPost.post.community_local).toBe(false);
330 expect(alphaPost.post.creator_local).toBe(false);