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.removed).toBe(communityTwo.community.removed);
37 expect(communityOne.community.deleted).toBe(communityTwo.community.deleted);
40 test('Create community', async () => {
41 let communityRes = await createCommunity(alpha);
42 expect(communityRes.community_view.community.name).toBeDefined();
45 let prevName = communityRes.community_view.community.name;
46 let communityRes2: any = await createCommunity(alpha, prevName);
47 expect(communityRes2['error']).toBe('community_already_exists');
49 // Cache the community on beta, make sure it has the other fields
50 let searchShort = `!${prevName}@lemmy-alpha:8541`;
51 let search = await searchForCommunity(beta, searchShort);
52 let communityOnBeta = search.communities[0];
53 assertCommunityFederation(communityOnBeta, communityRes.community_view);
56 test('Delete community', async () => {
57 let communityRes = await createCommunity(beta);
59 // Cache the community on Alpha
60 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
61 let search = await searchForCommunity(alpha, searchShort);
62 let communityOnAlpha = search.communities[0];
63 assertCommunityFederation(communityOnAlpha, communityRes.community_view);
65 // Follow the community from alpha
66 let follow = await followCommunity(
69 communityOnAlpha.community.id
72 // Make sure the follow response went through
73 expect(follow.community_view.community.local).toBe(false);
75 let deleteCommunityRes = await deleteCommunity(
78 communityRes.community_view.community.id
80 expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
82 // Make sure it got deleted on A
83 let communityOnAlphaDeleted = await getCommunity(
85 communityOnAlpha.community.id
87 expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true);
90 let undeleteCommunityRes = await deleteCommunity(
93 communityRes.community_view.community.id
95 expect(undeleteCommunityRes.community_view.community.deleted).toBe(false);
97 // Make sure it got undeleted on A
98 let communityOnAlphaUnDeleted = await getCommunity(
100 communityOnAlpha.community.id
102 expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe(
107 test('Remove community', async () => {
108 let communityRes = await createCommunity(beta);
110 // Cache the community on Alpha
111 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
112 let search = await searchForCommunity(alpha, searchShort);
113 let communityOnAlpha = search.communities[0];
114 assertCommunityFederation(communityOnAlpha, communityRes.community_view);
116 // Follow the community from alpha
117 let follow = await followCommunity(
120 communityOnAlpha.community.id
123 // Make sure the follow response went through
124 expect(follow.community_view.community.local).toBe(false);
126 let removeCommunityRes = await removeCommunity(
129 communityRes.community_view.community.id
131 expect(removeCommunityRes.community_view.community.removed).toBe(true);
133 // Make sure it got Removed on A
134 let communityOnAlphaRemoved = await getCommunity(
136 communityOnAlpha.community.id
138 expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true);
141 let unremoveCommunityRes = await removeCommunity(
144 communityRes.community_view.community.id
146 expect(unremoveCommunityRes.community_view.community.removed).toBe(false);
148 // Make sure it got undeleted on A
149 let communityOnAlphaUnRemoved = await getCommunity(
151 communityOnAlpha.community.id
153 expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe(
158 test('Search for beta community', async () => {
159 let communityRes = await createCommunity(beta);
160 expect(communityRes.community_view.community.name).toBeDefined();
162 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
163 let search = await searchForCommunity(alpha, searchShort);
164 let communityOnAlpha = search.communities[0];
165 assertCommunityFederation(communityOnAlpha, communityRes.community_view);