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(
38 communityTwo.community.icon.unwrapOr("none")
40 expect(communityOne.community.banner.unwrapOr("none")).toBe(
41 communityTwo.community.banner.unwrapOr("none")
43 expect(communityOne.community.published).toBe(
44 communityTwo.community.published
46 expect(communityOne.community.nsfw).toBe(communityTwo.community.nsfw);
47 expect(communityOne.community.removed).toBe(communityTwo.community.removed);
48 expect(communityOne.community.deleted).toBe(communityTwo.community.deleted);
51 test("Create community", async () => {
52 let communityRes = await createCommunity(alpha);
53 expect(communityRes.community_view.community.name).toBeDefined();
56 let prevName = communityRes.community_view.community.name;
57 let communityRes2: any = await createCommunity(alpha, prevName);
58 expect(communityRes2["error"]).toBe("community_already_exists");
60 // Cache the community on beta, make sure it has the other fields
61 let searchShort = `!${prevName}@lemmy-alpha:8541`;
63 await resolveCommunity(beta, searchShort)
65 assertCommunityFederation(betaCommunity, communityRes.community_view);
68 test("Delete community", async () => {
69 let communityRes = await createCommunity(beta);
71 // Cache the community on Alpha
72 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
73 let alphaCommunity = (
74 await resolveCommunity(alpha, searchShort)
76 assertCommunityFederation(alphaCommunity, communityRes.community_view);
78 // Follow the community from alpha
79 let follow = await followCommunity(alpha, true, alphaCommunity.community.id);
81 // Make sure the follow response went through
82 expect(follow.community_view.community.local).toBe(false);
84 let deleteCommunityRes = await deleteCommunity(
87 communityRes.community_view.community.id
89 expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
90 expect(deleteCommunityRes.community_view.community.title).toBe(
91 communityRes.community_view.community.title
94 // Make sure it got deleted on A
95 let communityOnAlphaDeleted = await getCommunity(
97 alphaCommunity.community.id
99 expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true);
102 let undeleteCommunityRes = await deleteCommunity(
105 communityRes.community_view.community.id
107 expect(undeleteCommunityRes.community_view.community.deleted).toBe(false);
109 // Make sure it got undeleted on A
110 let communityOnAlphaUnDeleted = await getCommunity(
112 alphaCommunity.community.id
114 expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe(
119 test("Remove community", async () => {
120 let communityRes = await createCommunity(beta);
122 // Cache the community on Alpha
123 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
124 let alphaCommunity = (
125 await resolveCommunity(alpha, searchShort)
126 ).community.unwrap();
127 assertCommunityFederation(alphaCommunity, communityRes.community_view);
129 // Follow the community from alpha
130 let follow = await followCommunity(alpha, true, alphaCommunity.community.id);
132 // Make sure the follow response went through
133 expect(follow.community_view.community.local).toBe(false);
135 let removeCommunityRes = await removeCommunity(
138 communityRes.community_view.community.id
140 expect(removeCommunityRes.community_view.community.removed).toBe(true);
141 expect(removeCommunityRes.community_view.community.title).toBe(
142 communityRes.community_view.community.title
145 // Make sure it got Removed on A
146 let communityOnAlphaRemoved = await getCommunity(
148 alphaCommunity.community.id
150 expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true);
153 let unremoveCommunityRes = await removeCommunity(
156 communityRes.community_view.community.id
158 expect(unremoveCommunityRes.community_view.community.removed).toBe(false);
160 // Make sure it got undeleted on A
161 let communityOnAlphaUnRemoved = await getCommunity(
163 alphaCommunity.community.id
165 expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe(
170 test("Search for beta community", async () => {
171 let communityRes = await createCommunity(beta);
172 expect(communityRes.community_view.community.name).toBeDefined();
174 let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
175 let alphaCommunity = (
176 await resolveCommunity(alpha, searchShort)
177 ).community.unwrap();
178 assertCommunityFederation(alphaCommunity, communityRes.community_view);
181 test("Admin actions in remote community are not federated to origin", async () => {
182 // create a community on alpha
183 let communityRes = (await createCommunity(alpha)).community_view;
184 expect(communityRes.community.name).toBeDefined();
186 // gamma follows community and posts in it
187 let gammaCommunity = (
188 await resolveCommunity(gamma, communityRes.community.actor_id)
189 ).community.unwrap();
190 let gammaFollow = await followCommunity(
193 gammaCommunity.community.id
195 expect(gammaFollow.community_view.subscribed).toBe("Subscribed");
196 let gammaPost = (await createPost(gamma, gammaCommunity.community.id))
198 expect(gammaPost.post.id).toBeDefined();
199 expect(gammaPost.creator_banned_from_community).toBe(false);
201 // admin of beta decides to ban gamma from community
202 let betaCommunity = (
203 await resolveCommunity(beta, communityRes.community.actor_id)
204 ).community.unwrap();
205 let bannedUserInfo1 = (await getSite(gamma)).my_user.unwrap().local_user_view
207 let bannedUserInfo2 = (
208 await resolvePerson(beta, bannedUserInfo1.actor_id)
210 let banRes = await banPersonFromCommunity(
212 bannedUserInfo2.person.id,
213 betaCommunity.community.id,
217 expect(banRes.banned).toBe(true);
219 // ban doesnt federate to community's origin instance alpha
220 let alphaPost = (await resolvePost(alpha, gammaPost.post)).post.unwrap();
221 expect(alphaPost.creator_banned_from_community).toBe(false);
223 // and neither to gamma
224 let gammaPost2 = await getPost(gamma, gammaPost.post.id);
225 expect(gammaPost2.post_view.creator_banned_from_community).toBe(false);