1 jest.setTimeout(120000);
14 import { CommunityView } from 'lemmy-js-client';
16 beforeAll(async () => {
20 function assertCommunityFederation(
21 communityOne: CommunityView,
22 communityTwo: CommunityView
24 expect(communityOne.community.actor_id).toBe(communityTwo.community.actor_id);
25 expect(communityOne.community.name).toBe(communityTwo.community.name);
26 expect(communityOne.community.title).toBe(communityTwo.community.title);
27 expect(communityOne.community.description).toBe(
28 communityTwo.community.description
30 expect(communityOne.community.icon).toBe(communityTwo.community.icon);
31 expect(communityOne.community.banner).toBe(communityTwo.community.banner);
32 expect(communityOne.community.published).toBe(
33 communityTwo.community.published
35 expect(communityOne.creator.actor_id).toBe(communityTwo.creator.actor_id);
36 expect(communityOne.community.nsfw).toBe(communityTwo.community.nsfw);
37 expect(communityOne.community.category_id).toBe(
38 communityTwo.community.category_id
40 expect(communityOne.community.removed).toBe(communityTwo.community.removed);
41 expect(communityOne.community.deleted).toBe(communityTwo.community.deleted);
44 test('Create community', async () => {
45 let communityRes = await createCommunity(alpha);
46 expect(communityRes.community_view.community.name).toBeDefined();
49 let prevName = communityRes.community_view.community.name;
50 let communityRes2: any = await createCommunity(alpha, prevName);
51 expect(communityRes2['error']).toBe('community_already_exists');
54 // Cache the community on beta, make sure it has the other fields
55 let searchShort = `!${prevName}@lemmy-alpha:8541`;
56 let search = await searchForCommunity(beta, searchShort);
57 let communityOnBeta = search.communities[0];
58 assertCommunityFederation(communityOnBeta, communityRes.community_view);
61 test('Delete community', async () => {
62 let communityRes = await createCommunity(beta);
65 // Cache the community on Alpha
66 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
67 let search = await searchForCommunity(alpha, searchShort);
68 let communityOnAlpha = search.communities[0];
69 assertCommunityFederation(communityOnAlpha, communityRes.community_view);
72 // Follow the community from alpha
73 let follow = await followCommunity(
76 communityOnAlpha.community.id
79 // Make sure the follow response went through
80 expect(follow.community_view.community.local).toBe(false);
83 let deleteCommunityRes = await deleteCommunity(
86 communityRes.community_view.community.id
88 expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
91 // Make sure it got deleted on A
92 let communityOnAlphaDeleted = await getCommunity(
94 communityOnAlpha.community.id
96 expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true);
100 let undeleteCommunityRes = await deleteCommunity(
103 communityRes.community_view.community.id
105 expect(undeleteCommunityRes.community_view.community.deleted).toBe(false);
108 // Make sure it got undeleted on A
109 let communityOnAlphaUnDeleted = await getCommunity(
111 communityOnAlpha.community.id
113 expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe(
118 test('Remove community', async () => {
119 let communityRes = await createCommunity(beta);
122 // Cache the community on Alpha
123 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
124 let search = await searchForCommunity(alpha, searchShort);
125 let communityOnAlpha = search.communities[0];
126 assertCommunityFederation(communityOnAlpha, communityRes.community_view);
129 // Follow the community from alpha
130 let follow = await followCommunity(
133 communityOnAlpha.community.id
136 // Make sure the follow response went through
137 expect(follow.community_view.community.local).toBe(false);
140 let removeCommunityRes = await removeCommunity(
143 communityRes.community_view.community.id
145 expect(removeCommunityRes.community_view.community.removed).toBe(true);
148 // Make sure it got Removed on A
149 let communityOnAlphaRemoved = await getCommunity(
151 communityOnAlpha.community.id
153 expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true);
157 let unremoveCommunityRes = await removeCommunity(
160 communityRes.community_view.community.id
162 expect(unremoveCommunityRes.community_view.community.removed).toBe(false);
165 // Make sure it got undeleted on A
166 let communityOnAlphaUnRemoved = await getCommunity(
168 communityOnAlpha.community.id
170 expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe(
175 test('Search for beta community', async () => {
176 let communityRes = await createCommunity(beta);
177 expect(communityRes.community_view.community.name).toBeDefined();
180 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
181 let search = await searchForCommunity(alpha, searchShort);
182 let communityOnAlpha = search.communities[0];
183 assertCommunityFederation(communityOnAlpha, communityRes.community_view);