1 jest.setTimeout(120000);
13 import { CommunityView } from 'lemmy-js-client';
15 beforeAll(async () => {
19 function assertCommunityFederation(
20 communityOne: CommunityView,
21 communityTwo: CommunityView
23 expect(communityOne.community.actor_id).toBe(communityTwo.community.actor_id);
24 expect(communityOne.community.name).toBe(communityTwo.community.name);
25 expect(communityOne.community.title).toBe(communityTwo.community.title);
26 expect(communityOne.community.description).toBe(
27 communityTwo.community.description
29 expect(communityOne.community.icon).toBe(communityTwo.community.icon);
30 expect(communityOne.community.banner).toBe(communityTwo.community.banner);
31 expect(communityOne.community.published).toBe(
32 communityTwo.community.published
34 expect(communityOne.creator.actor_id).toBe(communityTwo.creator.actor_id);
35 expect(communityOne.community.nsfw).toBe(communityTwo.community.nsfw);
36 expect(communityOne.community.category_id).toBe(
37 communityTwo.community.category_id
39 expect(communityOne.community.removed).toBe(communityTwo.community.removed);
40 expect(communityOne.community.deleted).toBe(communityTwo.community.deleted);
43 test('Create community', async () => {
44 let communityRes = await createCommunity(alpha);
45 expect(communityRes.community_view.community.name).toBeDefined();
48 let prevName = communityRes.community_view.community.name;
49 let communityRes2: any = await createCommunity(alpha, prevName);
50 expect(communityRes2['error']).toBe('community_already_exists');
52 // Cache the community on beta, make sure it has the other fields
53 let searchShort = `!${prevName}@lemmy-alpha:8541`;
54 let search = await searchForCommunity(beta, searchShort);
55 let communityOnBeta = search.communities[0];
56 assertCommunityFederation(communityOnBeta, communityRes.community_view);
59 test('Delete community', async () => {
60 let communityRes = await createCommunity(beta);
62 // Cache the community on Alpha
63 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
64 let search = await searchForCommunity(alpha, searchShort);
65 let communityOnAlpha = search.communities[0];
66 assertCommunityFederation(communityOnAlpha, communityRes.community_view);
68 // Follow the community from alpha
69 let follow = await followCommunity(
72 communityOnAlpha.community.id
75 // Make sure the follow response went through
76 expect(follow.community_view.community.local).toBe(false);
78 let deleteCommunityRes = await deleteCommunity(
81 communityRes.community_view.community.id
83 expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
85 // Make sure it got deleted on A
86 let communityOnAlphaDeleted = await getCommunity(
88 communityOnAlpha.community.id
90 expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true);
93 let undeleteCommunityRes = await deleteCommunity(
96 communityRes.community_view.community.id
98 expect(undeleteCommunityRes.community_view.community.deleted).toBe(false);
100 // Make sure it got undeleted on A
101 let communityOnAlphaUnDeleted = await getCommunity(
103 communityOnAlpha.community.id
105 expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe(
110 test('Remove community', async () => {
111 let communityRes = await createCommunity(beta);
113 // Cache the community on Alpha
114 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
115 let search = await searchForCommunity(alpha, searchShort);
116 let communityOnAlpha = search.communities[0];
117 assertCommunityFederation(communityOnAlpha, communityRes.community_view);
119 // Follow the community from alpha
120 let follow = await followCommunity(
123 communityOnAlpha.community.id
126 // Make sure the follow response went through
127 expect(follow.community_view.community.local).toBe(false);
129 let removeCommunityRes = await removeCommunity(
132 communityRes.community_view.community.id
134 expect(removeCommunityRes.community_view.community.removed).toBe(true);
136 // Make sure it got Removed on A
137 let communityOnAlphaRemoved = await getCommunity(
139 communityOnAlpha.community.id
141 expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true);
144 let unremoveCommunityRes = await removeCommunity(
147 communityRes.community_view.community.id
149 expect(unremoveCommunityRes.community_view.community.removed).toBe(false);
151 // Make sure it got undeleted on A
152 let communityOnAlphaUnRemoved = await getCommunity(
154 communityOnAlpha.community.id
156 expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe(
161 test('Search for beta community', async () => {
162 let communityRes = await createCommunity(beta);
163 expect(communityRes.community_view.community.name).toBeDefined();
165 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
166 let search = await searchForCommunity(alpha, searchShort);
167 let communityOnAlpha = search.communities[0];
168 assertCommunityFederation(communityOnAlpha, communityRes.community_view);