1 jest.setTimeout(120000);
16 searchForBetaCommunity,
30 } from 'lemmy-js-client';
32 let betaCommunity: Community;
34 beforeAll(async () => {
36 let search = await searchForBetaCommunity(alpha);
37 betaCommunity = search.communities[0];
40 afterAll(async () => {
41 await unfollowRemotes(alpha);
42 await unfollowRemotes(gamma);
43 await unfollowRemotes(delta);
44 await unfollowRemotes(epsilon);
47 function assertPostFederation(
50 expect(postOne.ap_id).toBe(postTwo.ap_id);
51 expect(postOne.name).toBe(postTwo.name);
52 expect(postOne.body).toBe(postTwo.body);
53 expect(postOne.url).toBe(postTwo.url);
54 expect(postOne.nsfw).toBe(postTwo.nsfw);
55 expect(postOne.embed_title).toBe(postTwo.embed_title);
56 expect(postOne.embed_description).toBe(postTwo.embed_description);
57 expect(postOne.embed_html).toBe(postTwo.embed_html);
58 expect(postOne.published).toBe(postTwo.published);
59 expect(postOne.community_actor_id).toBe(postTwo.community_actor_id);
60 expect(postOne.locked).toBe(postTwo.locked);
61 expect(postOne.removed).toBe(postTwo.removed);
62 expect(postOne.deleted).toBe(postTwo.deleted);
65 test('Create a post', async () => {
66 let postRes = await createPost(alpha, betaCommunity.id);
67 expect(postRes.post).toBeDefined();
68 expect(postRes.post.community_local).toBe(false);
69 expect(postRes.post.creator_local).toBe(true);
70 expect(postRes.post.score).toBe(1);
72 // Make sure that post is liked on beta
73 let searchBeta = await searchPost(beta, postRes.post);
74 let betaPost = searchBeta.posts[0];
76 expect(betaPost).toBeDefined();
77 expect(betaPost.community_local).toBe(true);
78 expect(betaPost.creator_local).toBe(false);
79 expect(betaPost.score).toBe(1);
80 assertPostFederation(betaPost, postRes.post);
82 // Delta only follows beta, so it should not see an alpha ap_id
83 let searchDelta = await searchPost(delta, postRes.post);
84 expect(searchDelta.posts[0]).toBeUndefined();
86 // Epsilon has alpha blocked, it should not see the alpha post
87 let searchEpsilon = await searchPost(epsilon, postRes.post);
88 expect(searchEpsilon.posts[0]).toBeUndefined();
91 test('Create a post in a non-existent community', async () => {
92 let postRes = await createPost(alpha, -2);
93 expect(postRes).toStrictEqual({ error: 'couldnt_create_post' });
96 test('Unlike a post', async () => {
97 let postRes = await createPost(alpha, betaCommunity.id);
98 let unlike = await likePost(alpha, 0, postRes.post);
99 expect(unlike.post.score).toBe(0);
101 // Try to unlike it again, make sure it stays at 0
102 let unlike2 = await likePost(alpha, 0, postRes.post);
103 expect(unlike2.post.score).toBe(0);
105 // Make sure that post is unliked on beta
106 let searchBeta = await searchPost(beta, postRes.post);
107 let betaPost = searchBeta.posts[0];
108 expect(betaPost).toBeDefined();
109 expect(betaPost.community_local).toBe(true);
110 expect(betaPost.creator_local).toBe(false);
111 expect(betaPost.score).toBe(0);
112 assertPostFederation(betaPost, postRes.post);
115 test('Update a post', async () => {
116 let postRes = await createPost(alpha, betaCommunity.id);
118 let updatedName = 'A jest test federated post, updated';
119 let updatedPost = await updatePost(alpha, postRes.post);
120 expect(updatedPost.post.name).toBe(updatedName);
121 expect(updatedPost.post.community_local).toBe(false);
122 expect(updatedPost.post.creator_local).toBe(true);
124 // Make sure that post is updated on beta
125 let searchBeta = await searchPost(beta, postRes.post);
126 let betaPost = searchBeta.posts[0];
127 expect(betaPost.community_local).toBe(true);
128 expect(betaPost.creator_local).toBe(false);
129 expect(betaPost.name).toBe(updatedName);
130 assertPostFederation(betaPost, updatedPost.post);
132 // Make sure lemmy beta cannot update the post
133 let updatedPostBeta = await updatePost(beta, betaPost);
134 expect(updatedPostBeta).toStrictEqual({ error: 'no_post_edit_allowed' });
137 test('Sticky a post', async () => {
138 let postRes = await createPost(alpha, betaCommunity.id);
140 let stickiedPostRes = await stickyPost(alpha, true, postRes.post);
141 expect(stickiedPostRes.post.stickied).toBe(true);
142 // Make sure that post is stickied on beta
143 let searchBeta = await searchPost(beta, postRes.post);
144 let betaPost = searchBeta.posts[0];
145 expect(betaPost.community_local).toBe(true);
146 expect(betaPost.creator_local).toBe(false);
147 expect(betaPost.stickied).toBe(true);
150 let unstickiedPost = await stickyPost(alpha, false, postRes.post);
151 expect(unstickiedPost.post.stickied).toBe(false);
153 // Make sure that post is unstickied on beta
154 let searchBeta2 = await searchPost(beta, postRes.post);
155 let betaPost2 = searchBeta2.posts[0];
156 expect(betaPost2.community_local).toBe(true);
157 expect(betaPost2.creator_local).toBe(false);
158 expect(betaPost2.stickied).toBe(false);
160 // Make sure that gamma cannot sticky the post on beta
161 let searchGamma = await searchPost(gamma, postRes.post);
162 let gammaPost = searchGamma.posts[0];
163 let gammaTrySticky = await stickyPost(gamma, true, gammaPost);
164 let searchBeta3 = await searchPost(beta, postRes.post);
165 let betaPost3 = searchBeta3.posts[0];
166 expect(gammaTrySticky.post.stickied).toBe(true);
167 expect(betaPost3.stickied).toBe(false);
170 test('Lock a post', async () => {
171 let postRes = await createPost(alpha, betaCommunity.id);
174 let lockedPostRes = await lockPost(alpha, true, postRes.post);
175 expect(lockedPostRes.post.locked).toBe(true);
177 // Make sure that post is locked on beta
178 let searchBeta = await searchPostLocal(beta, postRes.post);
179 let betaPost1 = searchBeta.posts[0];
180 expect(betaPost1.locked).toBe(true);
182 // Try to make a new comment there, on alpha
183 let comment = await createComment(alpha, postRes.post.id);
184 expect(comment['error']).toBe('locked');
187 let unlockedPost = await lockPost(alpha, false, postRes.post);
188 expect(unlockedPost.post.locked).toBe(false);
190 // Make sure that post is unlocked on beta
191 let searchBeta2 = await searchPost(beta, postRes.post);
192 let betaPost2 = searchBeta2.posts[0];
193 expect(betaPost2.community_local).toBe(true);
194 expect(betaPost2.creator_local).toBe(false);
195 expect(betaPost2.locked).toBe(false);
197 // Try to create a new comment, on beta
198 let commentBeta = await createComment(beta, betaPost2.id);
199 expect(commentBeta).toBeDefined();
202 test('Delete a post', async () => {
203 let postRes = await createPost(alpha, betaCommunity.id);
204 expect(postRes.post).toBeDefined();
206 let deletedPost = await deletePost(alpha, true, postRes.post);
207 expect(deletedPost.post.deleted).toBe(true);
209 // Make sure lemmy beta sees post is deleted
210 let searchBeta = await searchPost(beta, postRes.post);
211 let betaPost = searchBeta.posts[0];
212 // This will be undefined because of the tombstone
213 expect(betaPost).toBeUndefined();
216 let undeletedPost = await deletePost(alpha, false, postRes.post);
217 expect(undeletedPost.post.deleted).toBe(false);
219 // Make sure lemmy beta sees post is undeleted
220 let searchBeta2 = await searchPost(beta, postRes.post);
221 let betaPost2 = searchBeta2.posts[0];
222 expect(betaPost2.deleted).toBe(false);
223 assertPostFederation(betaPost2, undeletedPost.post);
225 // Make sure lemmy beta cannot delete the post
226 let deletedPostBeta = await deletePost(beta, true, betaPost2);
227 expect(deletedPostBeta).toStrictEqual({ error: 'no_post_edit_allowed' });
230 test('Remove a post from admin and community on different instance', async () => {
231 let postRes = await createPost(alpha, betaCommunity.id);
233 let removedPost = await removePost(alpha, true, postRes.post);
234 expect(removedPost.post.removed).toBe(true);
236 // Make sure lemmy beta sees post is NOT removed
237 let searchBeta = await searchPost(beta, postRes.post);
238 let betaPost = searchBeta.posts[0];
239 expect(betaPost.removed).toBe(false);
242 let undeletedPost = await removePost(alpha, false, postRes.post);
243 expect(undeletedPost.post.removed).toBe(false);
245 // Make sure lemmy beta sees post is undeleted
246 let searchBeta2 = await searchPost(beta, postRes.post);
247 let betaPost2 = searchBeta2.posts[0];
248 expect(betaPost2.removed).toBe(false);
249 assertPostFederation(betaPost2, undeletedPost.post);
252 test('Remove a post from admin and community on same instance', async () => {
253 await followBeta(alpha);
254 let postRes = await createPost(alpha, betaCommunity.id);
255 expect(postRes.post).toBeDefined();
257 // Get the id for beta
258 let searchBeta = await searchPost(beta, postRes.post);
259 let betaPost = searchBeta.posts[0];
260 expect(betaPost).toBeDefined();
262 // The beta admin removes it (the community lives on beta)
263 let removePostRes = await removePost(beta, true, betaPost);
264 expect(removePostRes.post.removed).toBe(true);
266 // Make sure lemmy alpha sees post is removed
267 let alphaPost = await getPost(alpha, postRes.post.id);
268 expect(alphaPost.post.removed).toBe(true);
269 assertPostFederation(alphaPost.post, removePostRes.post);
272 let undeletedPost = await removePost(beta, false, betaPost);
273 expect(undeletedPost.post.removed).toBe(false);
275 // Make sure lemmy alpha sees post is undeleted
276 let alphaPost2 = await getPost(alpha, postRes.post.id);
277 expect(alphaPost2.post.removed).toBe(false);
278 assertPostFederation(alphaPost2.post, undeletedPost.post);
279 await unfollowRemotes(alpha);
282 test('Search for a post', async () => {
283 await unfollowRemotes(alpha);
284 let postRes = await createPost(alpha, betaCommunity.id);
285 expect(postRes.post).toBeDefined();
287 let searchBeta = await searchPost(beta, postRes.post);
289 expect(searchBeta.posts[0].name).toBeDefined();
292 test('A and G subscribe to B (center) A posts, it gets announced to G', async () => {
293 await followBeta(alpha);
294 await followBeta(gamma);
295 let postRes = await createPost(alpha, betaCommunity.id);
296 expect(postRes.post).toBeDefined();
298 let search2 = await searchPostLocal(gamma, postRes.post);
299 expect(search2.posts[0].name).toBeDefined();
300 await unfollowRemotes(alpha);
301 await unfollowRemotes(gamma);
304 test('Enforce site ban for federated user', async () => {
306 let alphaShortname = `@lemmy_alpha@lemmy-alpha:8541`;
307 let userSearch = await searchForUser(beta, alphaShortname);
308 let alphaUser = userSearch.users[0];
309 expect(alphaUser).toBeDefined();
311 // ban alpha from beta site
312 let banAlpha = await banUserFromSite(beta, alphaUser.id, true);
313 expect(banAlpha.banned).toBe(true);
315 // Alpha makes post on beta
316 let postRes = await createPost(alpha, betaCommunity.id);
317 expect(postRes.post).toBeDefined();
318 expect(postRes.post.community_local).toBe(false);
319 expect(postRes.post.creator_local).toBe(true);
320 expect(postRes.post.score).toBe(1);
322 // Make sure that post doesn't make it to beta
323 let searchBeta = await searchPostLocal(beta, postRes.post);
324 let betaPost = searchBeta.posts[0];
325 expect(betaPost).toBeUndefined();
328 let unBanAlpha = await banUserFromSite(beta, alphaUser.id, false);
329 expect(unBanAlpha.banned).toBe(false);
332 test('Enforce community ban for federated user', async () => {
333 let alphaShortname = `@lemmy_alpha@lemmy-alpha:8541`;
334 let userSearch = await searchForUser(beta, alphaShortname);
335 let alphaUser = userSearch.users[0];
336 expect(alphaUser).toBeDefined();
338 // ban alpha from beta site
339 await banUserFromCommunity(beta, alphaUser.id, 2, false);
340 let banAlpha = await banUserFromCommunity(beta, alphaUser.id, 2, true);
341 expect(banAlpha.banned).toBe(true);
343 // Alpha makes post on beta
344 let postRes = await createPost(alpha, betaCommunity.id);
345 expect(postRes.post).toBeDefined();
346 expect(postRes.post.community_local).toBe(false);
347 expect(postRes.post.creator_local).toBe(true);
348 expect(postRes.post.score).toBe(1);
350 // Make sure that post doesn't make it to beta community
351 let searchBeta = await searchPostLocal(beta, postRes.post);
352 let betaPost = searchBeta.posts[0];
353 expect(betaPost).toBeUndefined();
356 let unBanAlpha = await banUserFromCommunity(beta, alphaUser.id, 2, false);
357 expect(unBanAlpha.banned).toBe(false);