1 jest.setTimeout(120000);
15 } from 'lemmy-js-client';
17 beforeAll(async () => {
21 function assertCommunityFederation(
22 communityOne: Community,
23 communityTwo: Community) {
24 expect(communityOne.actor_id).toBe(communityTwo.actor_id);
25 expect(communityOne.name).toBe(communityTwo.name);
26 expect(communityOne.title).toBe(communityTwo.title);
27 expect(communityOne.description).toBe(communityTwo.description);
28 expect(communityOne.icon).toBe(communityTwo.icon);
29 expect(communityOne.banner).toBe(communityTwo.banner);
30 expect(communityOne.published).toBe(communityTwo.published);
31 expect(communityOne.creator_actor_id).toBe(communityTwo.creator_actor_id);
32 expect(communityOne.nsfw).toBe(communityTwo.nsfw);
33 expect(communityOne.category_id).toBe(communityTwo.category_id);
34 expect(communityOne.removed).toBe(communityTwo.removed);
35 expect(communityOne.deleted).toBe(communityTwo.deleted);
38 test('Create community', async () => {
39 let communityRes = await createCommunity(alpha);
40 expect(communityRes.community.name).toBeDefined();
43 let prevName = communityRes.community.name;
44 let communityRes2 = await createCommunity(alpha, prevName);
45 expect(communityRes2['error']).toBe('community_already_exists');
47 // Cache the community on beta, make sure it has the other fields
48 let searchShort = `!${prevName}@lemmy-alpha:8541`;
49 let search = await searchForCommunity(beta, searchShort);
50 let communityOnBeta = search.communities[0];
51 assertCommunityFederation(communityOnBeta, communityRes.community);
54 test('Delete community', async () => {
55 let communityRes = await createCommunity(beta);
57 // Cache the community on Alpha
58 let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`;
59 let search = await searchForCommunity(alpha, searchShort);
60 let communityOnAlpha = search.communities[0];
61 assertCommunityFederation(communityOnAlpha, communityRes.community);
63 // Follow the community from alpha
64 let follow = await followCommunity(alpha, true, communityOnAlpha.id);
66 // Make sure the follow response went through
67 expect(follow.community.local).toBe(false);
69 let deleteCommunityRes = await deleteCommunity(
72 communityRes.community.id
74 expect(deleteCommunityRes.community.deleted).toBe(true);
76 // Make sure it got deleted on A
77 let communityOnAlphaDeleted = await getCommunity(alpha, communityOnAlpha.id);
78 expect(communityOnAlphaDeleted.community.deleted).toBe(true);
81 let undeleteCommunityRes = await deleteCommunity(
84 communityRes.community.id
86 expect(undeleteCommunityRes.community.deleted).toBe(false);
88 // Make sure it got undeleted on A
89 let communityOnAlphaUnDeleted = await getCommunity(alpha, communityOnAlpha.id);
90 expect(communityOnAlphaUnDeleted.community.deleted).toBe(false);
93 test('Remove community', async () => {
94 let communityRes = await createCommunity(beta);
96 // Cache the community on Alpha
97 let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`;
98 let search = await searchForCommunity(alpha, searchShort);
99 let communityOnAlpha = search.communities[0];
100 assertCommunityFederation(communityOnAlpha, communityRes.community);
102 // Follow the community from alpha
103 let follow = await followCommunity(alpha, true, communityOnAlpha.id);
105 // Make sure the follow response went through
106 expect(follow.community.local).toBe(false);
108 let removeCommunityRes = await removeCommunity(
111 communityRes.community.id
113 expect(removeCommunityRes.community.removed).toBe(true);
115 // Make sure it got Removed on A
116 let communityOnAlphaRemoved = await getCommunity(alpha, communityOnAlpha.id);
117 expect(communityOnAlphaRemoved.community.removed).toBe(true);
120 let unremoveCommunityRes = await removeCommunity(
123 communityRes.community.id
125 expect(unremoveCommunityRes.community.removed).toBe(false);
127 // Make sure it got undeleted on A
128 let communityOnAlphaUnRemoved = await getCommunity(alpha, communityOnAlpha.id);
129 expect(communityOnAlphaUnRemoved.community.removed).toBe(false);
132 test('Search for beta community', async () => {
133 let communityRes = await createCommunity(beta);
134 expect(communityRes.community.name).toBeDefined();
136 let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`;
137 let search = await searchForCommunity(alpha, searchShort);
138 let communityOnAlpha = search.communities[0];
139 assertCommunityFederation(communityOnAlpha, communityRes.community);