1 jest.setTimeout(120000);
3 import { CommunityView } from "lemmy-js-client/dist/types/CommunityView";
15 banPersonFromCommunity,
23 beforeAll(async () => {
27 function assertCommunityFederation(
28 communityOne?: CommunityView,
29 communityTwo?: CommunityView,
31 expect(communityOne?.community.actor_id).toBe(
32 communityTwo?.community.actor_id,
34 expect(communityOne?.community.name).toBe(communityTwo?.community.name);
35 expect(communityOne?.community.title).toBe(communityTwo?.community.title);
36 expect(communityOne?.community.description).toBe(
37 communityTwo?.community.description,
39 expect(communityOne?.community.icon).toBe(communityTwo?.community.icon);
40 expect(communityOne?.community.banner).toBe(communityTwo?.community.banner);
41 expect(communityOne?.community.published).toBe(
42 communityTwo?.community.published,
44 expect(communityOne?.community.nsfw).toBe(communityTwo?.community.nsfw);
45 expect(communityOne?.community.removed).toBe(communityTwo?.community.removed);
46 expect(communityOne?.community.deleted).toBe(communityTwo?.community.deleted);
49 test("Create community", async () => {
50 let communityRes = await createCommunity(alpha);
51 expect(communityRes.community_view.community.name).toBeDefined();
54 let prevName = communityRes.community_view.community.name;
55 let communityRes2: any = await createCommunity(alpha, prevName);
56 expect(communityRes2["error"]).toBe("community_already_exists");
58 // Cache the community on beta, make sure it has the other fields
59 let searchShort = `!${prevName}@lemmy-alpha:8541`;
60 let betaCommunity = (await resolveCommunity(beta, searchShort)).community;
61 assertCommunityFederation(betaCommunity, communityRes.community_view);
64 test("Delete community", async () => {
65 let communityRes = await createCommunity(beta);
67 // Cache the community on Alpha
68 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
69 let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
70 if (!alphaCommunity) {
71 throw "Missing alpha community";
73 assertCommunityFederation(alphaCommunity, communityRes.community_view);
75 // Follow the community from alpha
76 let follow = await followCommunity(alpha, true, alphaCommunity.community.id);
78 // Make sure the follow response went through
79 expect(follow.community_view.community.local).toBe(false);
81 let deleteCommunityRes = await deleteCommunity(
84 communityRes.community_view.community.id,
86 expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
87 expect(deleteCommunityRes.community_view.community.title).toBe(
88 communityRes.community_view.community.title,
91 // Make sure it got deleted on A
92 let communityOnAlphaDeleted = await getCommunity(
94 alphaCommunity.community.id,
96 expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true);
99 let undeleteCommunityRes = await deleteCommunity(
102 communityRes.community_view.community.id,
104 expect(undeleteCommunityRes.community_view.community.deleted).toBe(false);
106 // Make sure it got undeleted on A
107 let communityOnAlphaUnDeleted = await getCommunity(
109 alphaCommunity.community.id,
111 expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe(
116 test("Remove community", async () => {
117 let communityRes = await createCommunity(beta);
119 // Cache the community on Alpha
120 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
121 let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
122 if (!alphaCommunity) {
123 throw "Missing alpha community";
125 assertCommunityFederation(alphaCommunity, communityRes.community_view);
127 // Follow the community from alpha
128 let follow = await followCommunity(alpha, true, alphaCommunity.community.id);
130 // Make sure the follow response went through
131 expect(follow.community_view.community.local).toBe(false);
133 let removeCommunityRes = await removeCommunity(
136 communityRes.community_view.community.id,
138 expect(removeCommunityRes.community_view.community.removed).toBe(true);
139 expect(removeCommunityRes.community_view.community.title).toBe(
140 communityRes.community_view.community.title,
143 // Make sure it got Removed on A
144 let communityOnAlphaRemoved = await getCommunity(
146 alphaCommunity.community.id,
148 expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true);
151 let unremoveCommunityRes = await removeCommunity(
154 communityRes.community_view.community.id,
156 expect(unremoveCommunityRes.community_view.community.removed).toBe(false);
158 // Make sure it got undeleted on A
159 let communityOnAlphaUnRemoved = await getCommunity(
161 alphaCommunity.community.id,
163 expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe(
168 test("Search for beta community", async () => {
169 let communityRes = await createCommunity(beta);
170 expect(communityRes.community_view.community.name).toBeDefined();
172 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
173 let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
174 assertCommunityFederation(alphaCommunity, communityRes.community_view);
177 test("Admin actions in remote community are not federated to origin", async () => {
178 // create a community on alpha
179 let communityRes = (await createCommunity(alpha)).community_view;
180 expect(communityRes.community.name).toBeDefined();
182 // gamma follows community and posts in it
183 let gammaCommunity = (
184 await resolveCommunity(gamma, communityRes.community.actor_id)
186 if (!gammaCommunity) {
187 throw "Missing gamma community";
189 await followCommunity(gamma, true, gammaCommunity.community.id);
191 await resolveCommunity(gamma, communityRes.community.actor_id)
193 if (!gammaCommunity) {
194 throw "Missing gamma community";
196 expect(gammaCommunity.subscribed).toBe("Subscribed");
197 let gammaPost = (await createPost(gamma, gammaCommunity.community.id))
199 expect(gammaPost.post.id).toBeDefined();
200 expect(gammaPost.creator_banned_from_community).toBe(false);
202 // admin of beta decides to ban gamma from community
203 let betaCommunity = (
204 await resolveCommunity(beta, communityRes.community.actor_id)
206 if (!betaCommunity) {
207 throw "Missing beta community";
209 let bannedUserInfo1 = (await getSite(gamma)).my_user?.local_user_view.person;
210 if (!bannedUserInfo1) {
211 throw "Missing banned user 1";
213 let bannedUserInfo2 = (await resolvePerson(beta, bannedUserInfo1.actor_id))
215 if (!bannedUserInfo2) {
216 throw "Missing banned user 2";
218 let banRes = await banPersonFromCommunity(
220 bannedUserInfo2.person.id,
221 betaCommunity.community.id,
225 expect(banRes.banned).toBe(true);
227 // ban doesnt federate to community's origin instance alpha
228 let alphaPost = (await resolvePost(alpha, gammaPost.post)).post;
229 expect(alphaPost?.creator_banned_from_community).toBe(false);
231 // and neither to gamma
232 let gammaPost2 = await getPost(gamma, gammaPost.post.id);
233 expect(gammaPost2.post_view.creator_banned_from_community).toBe(false);