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.community.nsfw).toBe(communityTwo.community.nsfw);
35 expect(communityOne.community.removed).toBe(communityTwo.community.removed);
36 expect(communityOne.community.deleted).toBe(communityTwo.community.deleted);
39 test('Create community', async () => {
40 let communityRes = await createCommunity(alpha);
41 expect(communityRes.community_view.community.name).toBeDefined();
44 let prevName = communityRes.community_view.community.name;
45 let communityRes2: any = await createCommunity(alpha, prevName);
46 expect(communityRes2['error']).toBe('community_already_exists');
48 // Cache the community on beta, make sure it has the other fields
49 let searchShort = `!${prevName}@lemmy-alpha:8541`;
50 let betaCommunity = (await resolveCommunity(beta, searchShort)).community;
51 assertCommunityFederation(betaCommunity, communityRes.community_view);
54 test('Delete community', async () => {
55 let communityRes = await createCommunity(beta);
57 // Cache the community on Alpha
58 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
59 let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
60 assertCommunityFederation(alphaCommunity, communityRes.community_view);
62 // Follow the community from alpha
63 let follow = await followCommunity(
66 alphaCommunity.community.id
69 // Make sure the follow response went through
70 expect(follow.community_follower_view.community.local).toBe(false);
72 let deleteCommunityRes = await deleteCommunity(
75 communityRes.community_view.community.id
77 expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
78 expect(deleteCommunityRes.community_view.community.title).toBe(communityRes.community_view.community.title);
80 // Make sure it got deleted on A
81 let communityOnAlphaDeleted = await getCommunity(
83 alphaCommunity.community.id
85 expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true);
88 let undeleteCommunityRes = await deleteCommunity(
91 communityRes.community_view.community.id
93 expect(undeleteCommunityRes.community_view.community.deleted).toBe(false);
95 // Make sure it got undeleted on A
96 let communityOnAlphaUnDeleted = await getCommunity(
98 alphaCommunity.community.id
100 expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe(
105 test('Remove community', async () => {
106 let communityRes = await createCommunity(beta);
108 // Cache the community on Alpha
109 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
110 let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
111 assertCommunityFederation(alphaCommunity, communityRes.community_view);
113 // Follow the community from alpha
114 let follow = await followCommunity(
117 alphaCommunity.community.id
120 // Make sure the follow response went through
121 expect(follow.community_follower_view.community.local).toBe(false);
123 let removeCommunityRes = await removeCommunity(
126 communityRes.community_view.community.id
128 expect(removeCommunityRes.community_view.community.removed).toBe(true);
129 expect(removeCommunityRes.community_view.community.title).toBe(communityRes.community_view.community.title);
131 // Make sure it got Removed on A
132 let communityOnAlphaRemoved = await getCommunity(
134 alphaCommunity.community.id
136 expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true);
139 let unremoveCommunityRes = await removeCommunity(
142 communityRes.community_view.community.id
144 expect(unremoveCommunityRes.community_view.community.removed).toBe(false);
146 // Make sure it got undeleted on A
147 let communityOnAlphaUnRemoved = await getCommunity(
149 alphaCommunity.community.id
151 expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe(
156 test('Search for beta community', async () => {
157 let communityRes = await createCommunity(beta);
158 expect(communityRes.community_view.community.name).toBeDefined();
160 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
161 let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
162 assertCommunityFederation(alphaCommunity, communityRes.community_view);