1 jest.setTimeout(120000);
2 import { CommunityView } from 'lemmy-js-client';
15 banPersonFromCommunity,
23 beforeAll(async () => {
27 function assertCommunityFederation(
28 communityOne: CommunityView,
29 communityTwo: CommunityView
31 expect(communityOne.community.actor_id).toBe(communityTwo.community.actor_id);
32 expect(communityOne.community.name).toBe(communityTwo.community.name);
33 expect(communityOne.community.title).toBe(communityTwo.community.title);
34 expect(communityOne.community.description.unwrapOr("none")).toBe(
35 communityTwo.community.description.unwrapOr("none")
37 expect(communityOne.community.icon.unwrapOr("none")).toBe(communityTwo.community.icon.unwrapOr("none"));
38 expect(communityOne.community.banner.unwrapOr("none")).toBe(communityTwo.community.banner.unwrapOr("none"));
39 expect(communityOne.community.published).toBe(
40 communityTwo.community.published
42 expect(communityOne.community.nsfw).toBe(communityTwo.community.nsfw);
43 expect(communityOne.community.removed).toBe(communityTwo.community.removed);
44 expect(communityOne.community.deleted).toBe(communityTwo.community.deleted);
47 test('Create community', async () => {
48 let communityRes = await createCommunity(alpha);
49 expect(communityRes.community_view.community.name).toBeDefined();
52 let prevName = communityRes.community_view.community.name;
53 let communityRes2: any = await createCommunity(alpha, prevName);
54 expect(communityRes2['error']).toBe('community_already_exists');
56 // Cache the community on beta, make sure it has the other fields
57 let searchShort = `!${prevName}@lemmy-alpha:8541`;
58 let betaCommunity = (await resolveCommunity(beta, searchShort)).community.unwrap();
59 assertCommunityFederation(betaCommunity, communityRes.community_view);
62 test('Delete community', async () => {
63 let communityRes = await createCommunity(beta);
65 // Cache the community on Alpha
66 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
67 let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community.unwrap();
68 assertCommunityFederation(alphaCommunity, communityRes.community_view);
70 // Follow the community from alpha
71 let follow = await followCommunity(
74 alphaCommunity.community.id
77 // Make sure the follow response went through
78 expect(follow.community_view.community.local).toBe(false);
80 let deleteCommunityRes = await deleteCommunity(
83 communityRes.community_view.community.id
85 expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
86 expect(deleteCommunityRes.community_view.community.title).toBe(communityRes.community_view.community.title);
88 // Make sure it got deleted on A
89 let communityOnAlphaDeleted = await getCommunity(
91 alphaCommunity.community.id
93 expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true);
96 let undeleteCommunityRes = await deleteCommunity(
99 communityRes.community_view.community.id
101 expect(undeleteCommunityRes.community_view.community.deleted).toBe(false);
103 // Make sure it got undeleted on A
104 let communityOnAlphaUnDeleted = await getCommunity(
106 alphaCommunity.community.id
108 expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe(
113 test('Remove community', async () => {
114 let communityRes = await createCommunity(beta);
116 // Cache the community on Alpha
117 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
118 let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community.unwrap();
119 assertCommunityFederation(alphaCommunity, communityRes.community_view);
121 // Follow the community from alpha
122 let follow = await followCommunity(
125 alphaCommunity.community.id
128 // Make sure the follow response went through
129 expect(follow.community_view.community.local).toBe(false);
131 let removeCommunityRes = await removeCommunity(
134 communityRes.community_view.community.id
136 expect(removeCommunityRes.community_view.community.removed).toBe(true);
137 expect(removeCommunityRes.community_view.community.title).toBe(communityRes.community_view.community.title);
139 // Make sure it got Removed on A
140 let communityOnAlphaRemoved = await getCommunity(
142 alphaCommunity.community.id
144 expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true);
147 let unremoveCommunityRes = await removeCommunity(
150 communityRes.community_view.community.id
152 expect(unremoveCommunityRes.community_view.community.removed).toBe(false);
154 // Make sure it got undeleted on A
155 let communityOnAlphaUnRemoved = await getCommunity(
157 alphaCommunity.community.id
159 expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe(
164 test('Search for beta community', async () => {
165 let communityRes = await createCommunity(beta);
166 expect(communityRes.community_view.community.name).toBeDefined();
168 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
169 let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community.unwrap();
170 assertCommunityFederation(alphaCommunity, communityRes.community_view);
173 test('Admin actions in remote community are not federated to origin', async () => {
174 // create a community on alpha
175 let communityRes = (await createCommunity(alpha)).community_view;
176 expect(communityRes.community.name).toBeDefined();
178 // gamma follows community and posts in it
179 let gammaCommunity = (await resolveCommunity(gamma, communityRes.community.actor_id)).community.unwrap();
180 let gammaFollow = (await followCommunity(gamma, true, gammaCommunity.community.id));
181 expect(gammaFollow.community_view.subscribed).toBe("Subscribed");
182 let gammaPost = (await createPost(gamma, gammaCommunity.community.id)).post_view;
183 expect(gammaPost.post.id).toBeDefined();
184 expect(gammaPost.creator_banned_from_community).toBe(false);
186 // admin of beta decides to ban gamma from community
187 let betaCommunity = (await resolveCommunity(beta, communityRes.community.actor_id)).community.unwrap();
188 let bannedUserInfo1 = (await getSite(gamma)).my_user.unwrap().local_user_view.person;
189 let bannedUserInfo2 = (await resolvePerson(beta, bannedUserInfo1.actor_id)).person.unwrap();
190 let banRes = (await banPersonFromCommunity(beta, bannedUserInfo2.person.id, betaCommunity.community.id, true, true));
192 expect(banRes.banned).toBe(true);
194 // ban doesnt federate to community's origin instance alpha
195 let alphaPost = (await resolvePost(alpha, gammaPost.post)).post.unwrap();
196 expect(alphaPost.creator_banned_from_community).toBe(false);
198 // and neither to gamma
199 let gammaPost2 = (await getPost(gamma, gammaPost.post.id));
200 expect(gammaPost2.post_view.creator_banned_from_community).toBe(false);