11 searchForBetaCommunity,
21 import { PostResponse } from '../interfaces';
23 let postRes: PostResponse;
25 beforeAll(async () => {
27 await followBeta(alpha);
28 await followBeta(gamma);
29 let search = await searchForBetaCommunity(alpha);
30 postRes = await createPost(
32 search.communities.filter(c => c.local == false)[0].id
36 afterAll(async () => {
37 await unfollowRemotes(alpha);
38 await unfollowRemotes(gamma);
41 test('Create a comment', async () => {
42 let commentRes = await createComment(alpha, postRes.post.id);
43 expect(commentRes.comment.content).toBeDefined();
44 expect(commentRes.comment.community_local).toBe(false);
45 expect(commentRes.comment.creator_local).toBe(true);
46 expect(commentRes.comment.score).toBe(1);
48 // Make sure that comment is liked on beta
49 let searchBeta = await searchComment(beta, commentRes.comment);
50 let betaComment = searchBeta.comments[0];
51 expect(betaComment).toBeDefined();
52 expect(betaComment.community_local).toBe(true);
53 expect(betaComment.creator_local).toBe(false);
54 expect(betaComment.score).toBe(1);
57 test('Update a comment', async () => {
58 let commentRes = await createComment(alpha, postRes.post.id);
59 let updateCommentRes = await updateComment(alpha, commentRes.comment.id);
60 expect(updateCommentRes.comment.content).toBe(
61 'A jest test federated comment update'
63 expect(updateCommentRes.comment.community_local).toBe(false);
64 expect(updateCommentRes.comment.creator_local).toBe(true);
66 // Make sure that post is updated on beta
67 let searchBeta = await searchComment(beta, commentRes.comment);
68 let betaComment = searchBeta.comments[0];
69 expect(betaComment.content).toBe('A jest test federated comment update');
72 test('Delete a comment', async () => {
73 let commentRes = await createComment(alpha, postRes.post.id);
74 let deleteCommentRes = await deleteComment(
79 expect(deleteCommentRes.comment.deleted).toBe(true);
81 // Make sure that comment is deleted on beta
82 // The search doesnt work below, because it returns a tombstone / http::gone
83 // let searchBeta = await searchComment(beta, commentRes.comment);
84 // console.log(searchBeta);
85 // let betaComment = searchBeta.comments[0];
86 // Create a fake post, just to get the previous new post id
87 let createdBetaPostJustToGetId = await createPost(beta, 2);
88 let betaPost = await getPost(beta, createdBetaPostJustToGetId.post.id - 1);
89 let betaComment = betaPost.comments[0];
90 expect(betaComment.deleted).toBe(true);
92 let undeleteCommentRes = await deleteComment(
97 expect(undeleteCommentRes.comment.deleted).toBe(false);
99 // Make sure that comment is undeleted on beta
100 let searchBeta2 = await searchComment(beta, commentRes.comment);
101 let betaComment2 = searchBeta2.comments[0];
102 expect(betaComment2.deleted).toBe(false);
105 test('Remove a comment', async () => {
106 let commentRes = await createComment(alpha, postRes.post.id);
107 let removeCommentRes = await removeComment(
110 commentRes.comment.id
112 expect(removeCommentRes.comment.removed).toBe(true);
114 // Make sure that comment is removed on beta
115 let searchBeta = await searchComment(beta, commentRes.comment);
116 let betaComment = searchBeta.comments[0];
117 expect(betaComment.removed).toBe(true);
119 let unremoveCommentRes = await removeComment(
122 commentRes.comment.id
124 expect(unremoveCommentRes.comment.removed).toBe(false);
126 // Make sure that comment is unremoved on beta
127 let searchBeta2 = await searchComment(beta, commentRes.comment);
128 let betaComment2 = searchBeta2.comments[0];
129 expect(betaComment2.removed).toBe(false);
132 test('Unlike a comment', async () => {
133 let commentRes = await createComment(alpha, postRes.post.id);
134 let unlike = await likeComment(alpha, 0, commentRes.comment);
135 expect(unlike.comment.score).toBe(0);
137 // Make sure that post is unliked on beta
138 let searchBeta = await searchComment(beta, commentRes.comment);
139 let betaComment = searchBeta.comments[0];
140 expect(betaComment).toBeDefined();
141 expect(betaComment.community_local).toBe(true);
142 expect(betaComment.creator_local).toBe(false);
143 expect(betaComment.score).toBe(0);
146 test('Federated comment like', async () => {
147 let commentRes = await createComment(alpha, postRes.post.id);
149 // Find the comment on beta
150 let searchBeta = await searchComment(beta, commentRes.comment);
151 let betaComment = searchBeta.comments[0];
153 let like = await likeComment(beta, 1, betaComment);
154 expect(like.comment.score).toBe(2);
156 // Get the post from alpha, check the likes
157 let post = await getPost(alpha, postRes.post.id);
158 expect(post.comments[0].score).toBe(2);
161 test('Reply to a comment', async () => {
162 // Create a comment on alpha, find it on beta
163 let commentRes = await createComment(alpha, postRes.post.id);
164 let searchBeta = await searchComment(beta, commentRes.comment);
165 let betaComment = searchBeta.comments[0];
167 // find that comment id on beta
170 let replyRes = await createComment(beta, betaComment.post_id, betaComment.id);
171 expect(replyRes.comment.content).toBeDefined();
172 expect(replyRes.comment.community_local).toBe(true);
173 expect(replyRes.comment.creator_local).toBe(true);
174 expect(replyRes.comment.parent_id).toBe(betaComment.id);
175 expect(replyRes.comment.score).toBe(1);
177 // Make sure that comment is seen on alpha
178 // TODO not sure why, but a searchComment back to alpha, for the ap_id of betas
179 // comment, isn't working.
180 // let searchAlpha = await searchComment(alpha, replyRes.comment);
181 let post = await getPost(alpha, postRes.post.id);
182 let alphaComment = post.comments[0];
183 expect(alphaComment.content).toBeDefined();
184 expect(alphaComment.parent_id).toBe(post.comments[1].id);
185 expect(alphaComment.community_local).toBe(false);
186 expect(alphaComment.creator_local).toBe(false);
187 expect(alphaComment.score).toBe(1);
190 test('Mention beta', async () => {
191 // Create a mention on alpha
192 let mentionContent = 'A test mention of @lemmy_beta@lemmy-beta:8550';
193 let commentRes = await createComment(alpha, postRes.post.id);
194 let mentionRes = await createComment(
197 commentRes.comment.id,
200 expect(mentionRes.comment.content).toBeDefined();
201 expect(mentionRes.comment.community_local).toBe(false);
202 expect(mentionRes.comment.creator_local).toBe(true);
203 expect(mentionRes.comment.score).toBe(1);
205 let mentionsRes = await getMentions(beta);
206 expect(mentionsRes.mentions[0].content).toBeDefined();
207 expect(mentionsRes.mentions[0].community_local).toBe(true);
208 expect(mentionsRes.mentions[0].creator_local).toBe(false);
209 expect(mentionsRes.mentions[0].score).toBe(1);
212 test('Comment Search', async () => {
213 let commentRes = await createComment(alpha, postRes.post.id);
214 let searchBeta = await searchComment(beta, commentRes.comment);
215 expect(searchBeta.comments[0].ap_id).toBe(commentRes.comment.ap_id);
218 test('A and G subscribe to B (center) A posts, G mentions B, it gets announced to A', async () => {
219 // Create a local post
220 let alphaPost = await createPost(alpha, 2);
221 expect(alphaPost.post.community_local).toBe(true);
223 // Make sure gamma sees it
224 let search = await searchPost(gamma, alphaPost.post);
225 let gammaPost = search.posts[0];
228 'A jest test federated comment announce, lets mention @lemmy_beta@lemmy-beta:8550';
229 let commentRes = await createComment(
235 expect(commentRes.comment.content).toBe(commentContent);
236 expect(commentRes.comment.community_local).toBe(false);
237 expect(commentRes.comment.creator_local).toBe(true);
238 expect(commentRes.comment.score).toBe(1);
240 // Make sure alpha sees it
241 let alphaPost2 = await getPost(alpha, alphaPost.post.id);
242 expect(alphaPost2.comments[0].content).toBe(commentContent);
243 expect(alphaPost2.comments[0].community_local).toBe(true);
244 expect(alphaPost2.comments[0].creator_local).toBe(false);
245 expect(alphaPost2.comments[0].score).toBe(1);
247 // Make sure beta has mentions
248 let mentionsRes = await getMentions(beta);
249 expect(mentionsRes.mentions[0].content).toBe(commentContent);
250 expect(mentionsRes.mentions[0].community_local).toBe(false);
251 expect(mentionsRes.mentions[0].creator_local).toBe(false);
252 // TODO this is failing because fetchInReplyTos aren't getting score
253 // expect(mentionsRes.mentions[0].score).toBe(1);
256 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 () => {
257 // Unfollow all remote communities
258 let followed = await unfollowRemotes(alpha);
260 followed.communities.filter(c => c.community_local == false).length
263 // B creates a post, and two comments, should be invisible to A
264 let postRes = await createPost(beta, 2);
265 expect(postRes.post.name).toBeDefined();
267 let parentCommentContent = 'An invisible top level comment from beta';
268 let parentCommentRes = await createComment(
274 expect(parentCommentRes.comment.content).toBe(parentCommentContent);
276 // B creates a comment, then a child one of that.
277 let childCommentContent = 'An invisible child comment from beta';
278 let childCommentRes = await createComment(
281 parentCommentRes.comment.id,
284 expect(childCommentRes.comment.content).toBe(childCommentContent);
287 let follow = await followBeta(alpha);
288 expect(follow.community.local).toBe(false);
289 expect(follow.community.name).toBe('main');
291 // An update to the child comment on beta, should push the post, parent, and child to alpha now
292 let updatedCommentContent = 'An update child comment from beta';
293 let updateRes = await updateComment(
295 childCommentRes.comment.id,
296 updatedCommentContent
298 expect(updateRes.comment.content).toBe(updatedCommentContent);
300 // Get the post from alpha
301 let createFakeAlphaPostToGetId = await createPost(alpha, 2);
302 let alphaPost = await getPost(alpha, createFakeAlphaPostToGetId.post.id - 1);
303 expect(alphaPost.post.name).toBeDefined();
304 expect(alphaPost.comments[1].content).toBe(parentCommentContent);
305 expect(alphaPost.comments[0].content).toBe(updatedCommentContent);
306 expect(alphaPost.post.community_local).toBe(false);
307 expect(alphaPost.post.creator_local).toBe(false);