1 jest.setTimeout(120000);
6 searchForBetaCommunity,
18 } from 'lemmy-js-client';
20 beforeAll(async () => {
24 function assertCommunityFederation(
25 communityOne: Community,
26 communityTwo: Community) {
27 expect(communityOne.actor_id).toBe(communityTwo.actor_id);
28 expect(communityOne.name).toBe(communityTwo.name);
29 expect(communityOne.title).toBe(communityTwo.title);
30 expect(communityOne.description).toBe(communityTwo.description);
31 expect(communityOne.icon).toBe(communityTwo.icon);
32 expect(communityOne.banner).toBe(communityTwo.banner);
33 expect(communityOne.published).toBe(communityTwo.published);
34 expect(communityOne.creator_actor_id).toBe(communityTwo.creator_actor_id);
35 expect(communityOne.nsfw).toBe(communityTwo.nsfw);
36 expect(communityOne.category_id).toBe(communityTwo.category_id);
37 expect(communityOne.removed).toBe(communityTwo.removed);
38 expect(communityOne.deleted).toBe(communityTwo.deleted);
41 test('Create community', async () => {
42 let communityRes = await createCommunity(alpha);
43 expect(communityRes.community.name).toBeDefined();
46 let prevName = communityRes.community.name;
47 let communityRes2 = await createCommunity(alpha, prevName);
48 expect(communityRes2['error']).toBe('community_already_exists');
51 // Cache the community on beta, make sure it has the other fields
52 let searchShort = `!${prevName}@lemmy-alpha:8541`;
53 let search = await searchForCommunity(beta, searchShort);
54 let communityOnBeta = search.communities[0];
55 assertCommunityFederation(communityOnBeta, communityRes.community);
58 test('Delete community', async () => {
59 let communityRes = await createCommunity(beta);
62 // Cache the community on Alpha
63 let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`;
64 let search = await searchForCommunity(alpha, searchShort);
65 let communityOnAlpha = search.communities[0];
66 assertCommunityFederation(communityOnAlpha, communityRes.community);
69 // Follow the community from alpha
70 let follow = await followCommunity(alpha, true, communityOnAlpha.id);
72 // Make sure the follow response went through
73 expect(follow.community.local).toBe(false);
76 let deleteCommunityRes = await deleteCommunity(
79 communityRes.community.id
81 expect(deleteCommunityRes.community.deleted).toBe(true);
84 // Make sure it got deleted on A
85 let communityOnAlphaDeleted = await getCommunity(alpha, communityOnAlpha.id);
86 expect(communityOnAlphaDeleted.community.deleted).toBe(true);
90 let undeleteCommunityRes = await deleteCommunity(
93 communityRes.community.id
95 expect(undeleteCommunityRes.community.deleted).toBe(false);
98 // Make sure it got undeleted on A
99 let communityOnAlphaUnDeleted = await getCommunity(alpha, communityOnAlpha.id);
100 expect(communityOnAlphaUnDeleted.community.deleted).toBe(false);
103 test('Remove community', async () => {
104 let communityRes = await createCommunity(beta);
107 // Cache the community on Alpha
108 let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`;
109 let search = await searchForCommunity(alpha, searchShort);
110 let communityOnAlpha = search.communities[0];
111 assertCommunityFederation(communityOnAlpha, communityRes.community);
114 // Follow the community from alpha
115 let follow = await followCommunity(alpha, true, communityOnAlpha.id);
117 // Make sure the follow response went through
118 expect(follow.community.local).toBe(false);
121 let removeCommunityRes = await removeCommunity(
124 communityRes.community.id
126 expect(removeCommunityRes.community.removed).toBe(true);
129 // Make sure it got Removed on A
130 let communityOnAlphaRemoved = await getCommunity(alpha, communityOnAlpha.id);
131 expect(communityOnAlphaRemoved.community.removed).toBe(true);
135 let unremoveCommunityRes = await removeCommunity(
138 communityRes.community.id
140 expect(unremoveCommunityRes.community.removed).toBe(false);
143 // Make sure it got undeleted on A
144 let communityOnAlphaUnRemoved = await getCommunity(alpha, communityOnAlpha.id);
145 expect(communityOnAlphaUnRemoved.community.removed).toBe(false);
148 test('Search for beta community', async () => {
149 let communityRes = await createCommunity(beta);
150 expect(communityRes.community.name).toBeDefined();
153 let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`;
154 let search = await searchForCommunity(alpha, searchShort);
155 let communityOnAlpha = search.communities[0];
156 assertCommunityFederation(communityOnAlpha, communityRes.community);