1 jest.setTimeout(120000);
2 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.unwrapOr("none")).toBe(
28 communityTwo.community.description.unwrapOr("none")
30 expect(communityOne.community.icon.unwrapOr("none")).toBe(communityTwo.community.icon.unwrapOr("none"));
31 expect(communityOne.community.banner.unwrapOr("none")).toBe(communityTwo.community.banner.unwrapOr("none"));
32 expect(communityOne.community.published).toBe(
33 communityTwo.community.published
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 betaCommunity = (await resolveCommunity(beta, searchShort)).community.unwrap();
52 assertCommunityFederation(betaCommunity, communityRes.community_view);
55 test('Delete community', async () => {
56 let communityRes = await createCommunity(beta);
58 // Cache the community on Alpha
59 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
60 let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community.unwrap();
61 assertCommunityFederation(alphaCommunity, communityRes.community_view);
63 // Follow the community from alpha
64 let follow = await followCommunity(
67 alphaCommunity.community.id
70 // Make sure the follow response went through
71 expect(follow.community_view.community.local).toBe(false);
73 let deleteCommunityRes = await deleteCommunity(
76 communityRes.community_view.community.id
78 expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
79 expect(deleteCommunityRes.community_view.community.title).toBe(communityRes.community_view.community.title);
81 // Make sure it got deleted on A
82 let communityOnAlphaDeleted = await getCommunity(
84 alphaCommunity.community.id
86 expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true);
89 let undeleteCommunityRes = await deleteCommunity(
92 communityRes.community_view.community.id
94 expect(undeleteCommunityRes.community_view.community.deleted).toBe(false);
96 // Make sure it got undeleted on A
97 let communityOnAlphaUnDeleted = await getCommunity(
99 alphaCommunity.community.id
101 expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe(
106 test('Remove community', async () => {
107 let communityRes = await createCommunity(beta);
109 // Cache the community on Alpha
110 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
111 let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community.unwrap();
112 assertCommunityFederation(alphaCommunity, communityRes.community_view);
114 // Follow the community from alpha
115 let follow = await followCommunity(
118 alphaCommunity.community.id
121 // Make sure the follow response went through
122 expect(follow.community_view.community.local).toBe(false);
124 let removeCommunityRes = await removeCommunity(
127 communityRes.community_view.community.id
129 expect(removeCommunityRes.community_view.community.removed).toBe(true);
130 expect(removeCommunityRes.community_view.community.title).toBe(communityRes.community_view.community.title);
132 // Make sure it got Removed on A
133 let communityOnAlphaRemoved = await getCommunity(
135 alphaCommunity.community.id
137 expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true);
140 let unremoveCommunityRes = await removeCommunity(
143 communityRes.community_view.community.id
145 expect(unremoveCommunityRes.community_view.community.removed).toBe(false);
147 // Make sure it got undeleted on A
148 let communityOnAlphaUnRemoved = await getCommunity(
150 alphaCommunity.community.id
152 expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe(
157 test('Search for beta community', async () => {
158 let communityRes = await createCommunity(beta);
159 expect(communityRes.community_view.community.name).toBeDefined();
161 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
162 let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community.unwrap();
163 assertCommunityFederation(alphaCommunity, communityRes.community_view);