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 await expect(createCommunity(alpha, prevName)).rejects.toBe(
56 "community_already_exists",
59 // Cache the community on beta, make sure it has the other fields
60 let searchShort = `!${prevName}@lemmy-alpha:8541`;
61 let betaCommunity = (await resolveCommunity(beta, searchShort)).community;
62 assertCommunityFederation(betaCommunity, communityRes.community_view);
65 test("Delete community", async () => {
66 let communityRes = await createCommunity(beta);
68 // Cache the community on Alpha
69 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
70 let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
71 if (!alphaCommunity) {
72 throw "Missing alpha community";
74 assertCommunityFederation(alphaCommunity, communityRes.community_view);
76 // Follow the community from alpha
77 let follow = await followCommunity(alpha, true, alphaCommunity.community.id);
79 // Make sure the follow response went through
80 expect(follow.community_view.community.local).toBe(false);
82 let deleteCommunityRes = await deleteCommunity(
85 communityRes.community_view.community.id,
87 expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
88 expect(deleteCommunityRes.community_view.community.title).toBe(
89 communityRes.community_view.community.title,
92 // Make sure it got deleted on A
93 let communityOnAlphaDeleted = await getCommunity(
95 alphaCommunity.community.id,
97 expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true);
100 let undeleteCommunityRes = await deleteCommunity(
103 communityRes.community_view.community.id,
105 expect(undeleteCommunityRes.community_view.community.deleted).toBe(false);
107 // Make sure it got undeleted on A
108 let communityOnAlphaUnDeleted = await getCommunity(
110 alphaCommunity.community.id,
112 expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe(
117 test("Remove community", async () => {
118 let communityRes = await createCommunity(beta);
120 // Cache the community on Alpha
121 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
122 let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
123 if (!alphaCommunity) {
124 throw "Missing alpha community";
126 assertCommunityFederation(alphaCommunity, communityRes.community_view);
128 // Follow the community from alpha
129 let follow = await followCommunity(alpha, true, alphaCommunity.community.id);
131 // Make sure the follow response went through
132 expect(follow.community_view.community.local).toBe(false);
134 let removeCommunityRes = await removeCommunity(
137 communityRes.community_view.community.id,
139 expect(removeCommunityRes.community_view.community.removed).toBe(true);
140 expect(removeCommunityRes.community_view.community.title).toBe(
141 communityRes.community_view.community.title,
144 // Make sure it got Removed on A
145 let communityOnAlphaRemoved = await getCommunity(
147 alphaCommunity.community.id,
149 expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true);
152 let unremoveCommunityRes = await removeCommunity(
155 communityRes.community_view.community.id,
157 expect(unremoveCommunityRes.community_view.community.removed).toBe(false);
159 // Make sure it got undeleted on A
160 let communityOnAlphaUnRemoved = await getCommunity(
162 alphaCommunity.community.id,
164 expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe(
169 test("Search for beta community", async () => {
170 let communityRes = await createCommunity(beta);
171 expect(communityRes.community_view.community.name).toBeDefined();
173 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
174 let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
175 assertCommunityFederation(alphaCommunity, communityRes.community_view);
178 test("Admin actions in remote community are not federated to origin", async () => {
179 // create a community on alpha
180 let communityRes = (await createCommunity(alpha)).community_view;
181 expect(communityRes.community.name).toBeDefined();
183 // gamma follows community and posts in it
184 let gammaCommunity = (
185 await resolveCommunity(gamma, communityRes.community.actor_id)
187 if (!gammaCommunity) {
188 throw "Missing gamma community";
190 await followCommunity(gamma, true, gammaCommunity.community.id);
192 await resolveCommunity(gamma, communityRes.community.actor_id)
194 if (!gammaCommunity) {
195 throw "Missing gamma community";
197 expect(gammaCommunity.subscribed).toBe("Subscribed");
198 let gammaPost = (await createPost(gamma, gammaCommunity.community.id))
200 expect(gammaPost.post.id).toBeDefined();
201 expect(gammaPost.creator_banned_from_community).toBe(false);
203 // admin of beta decides to ban gamma from community
204 let betaCommunity = (
205 await resolveCommunity(beta, communityRes.community.actor_id)
207 if (!betaCommunity) {
208 throw "Missing beta community";
210 let bannedUserInfo1 = (await getSite(gamma)).my_user?.local_user_view.person;
211 if (!bannedUserInfo1) {
212 throw "Missing banned user 1";
214 let bannedUserInfo2 = (await resolvePerson(beta, bannedUserInfo1.actor_id))
216 if (!bannedUserInfo2) {
217 throw "Missing banned user 2";
219 let banRes = await banPersonFromCommunity(
221 bannedUserInfo2.person.id,
222 betaCommunity.community.id,
226 expect(banRes.banned).toBe(true);
228 // ban doesnt federate to community's origin instance alpha
229 let alphaPost = (await resolvePost(alpha, gammaPost.post)).post;
230 expect(alphaPost?.creator_banned_from_community).toBe(false);
232 // and neither to gamma
233 let gammaPost2 = await getPost(gamma, gammaPost.post.id);
234 expect(gammaPost2.post_view.creator_banned_from_community).toBe(false);