2020-09-15 19:26:47 +00:00
|
|
|
jest.setTimeout(120000);
|
2022-07-30 03:55:59 +00:00
|
|
|
|
2023-04-26 04:26:10 +00:00
|
|
|
import { CommunityView } from "lemmy-js-client/dist/types/CommunityView";
|
2020-08-04 14:57:37 +00:00
|
|
|
import {
|
|
|
|
alpha,
|
|
|
|
beta,
|
2022-10-10 15:20:36 +00:00
|
|
|
gamma,
|
2020-08-04 14:57:37 +00:00
|
|
|
setupLogins,
|
2021-08-23 15:25:39 +00:00
|
|
|
resolveCommunity,
|
2020-08-04 14:57:37 +00:00
|
|
|
createCommunity,
|
|
|
|
deleteCommunity,
|
|
|
|
removeCommunity,
|
2020-11-05 20:19:06 +00:00
|
|
|
getCommunity,
|
|
|
|
followCommunity,
|
2022-10-10 15:20:36 +00:00
|
|
|
banPersonFromCommunity,
|
|
|
|
resolvePerson,
|
|
|
|
getSite,
|
|
|
|
createPost,
|
|
|
|
getPost,
|
|
|
|
resolvePost,
|
2023-07-26 17:51:11 +00:00
|
|
|
registerUser,
|
|
|
|
getPosts,
|
2023-08-31 11:07:45 +00:00
|
|
|
getComments,
|
|
|
|
createComment,
|
2023-08-22 15:10:21 +00:00
|
|
|
getCommunityByName,
|
2023-09-20 09:56:13 +00:00
|
|
|
blockInstance,
|
2023-09-09 16:25:03 +00:00
|
|
|
waitUntil,
|
2023-09-21 10:42:28 +00:00
|
|
|
alphaUrl,
|
2023-10-17 14:34:38 +00:00
|
|
|
delta,
|
2023-10-16 10:03:49 +00:00
|
|
|
betaAllowedInstances,
|
|
|
|
searchPostLocal,
|
2023-10-17 14:34:38 +00:00
|
|
|
resolveBetaCommunity,
|
|
|
|
longDelay,
|
2022-10-27 09:24:07 +00:00
|
|
|
} from "./shared";
|
2023-10-16 10:03:49 +00:00
|
|
|
import { EditSite, LemmyHttp } from "lemmy-js-client";
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
await setupLogins();
|
|
|
|
});
|
|
|
|
|
2020-09-17 15:41:51 +00:00
|
|
|
function assertCommunityFederation(
|
2023-01-04 15:59:26 +00:00
|
|
|
communityOne?: CommunityView,
|
2023-07-06 13:10:38 +00:00
|
|
|
communityTwo?: CommunityView,
|
2020-12-20 21:16:57 +00:00
|
|
|
) {
|
2023-01-04 15:59:26 +00:00
|
|
|
expect(communityOne?.community.actor_id).toBe(
|
2023-07-06 13:10:38 +00:00
|
|
|
communityTwo?.community.actor_id,
|
2023-01-04 15:59:26 +00:00
|
|
|
);
|
|
|
|
expect(communityOne?.community.name).toBe(communityTwo?.community.name);
|
|
|
|
expect(communityOne?.community.title).toBe(communityTwo?.community.title);
|
|
|
|
expect(communityOne?.community.description).toBe(
|
2023-07-06 13:10:38 +00:00
|
|
|
communityTwo?.community.description,
|
2023-01-04 15:59:26 +00:00
|
|
|
);
|
|
|
|
expect(communityOne?.community.icon).toBe(communityTwo?.community.icon);
|
|
|
|
expect(communityOne?.community.banner).toBe(communityTwo?.community.banner);
|
|
|
|
expect(communityOne?.community.published).toBe(
|
2023-07-06 13:10:38 +00:00
|
|
|
communityTwo?.community.published,
|
2023-01-04 15:59:26 +00:00
|
|
|
);
|
|
|
|
expect(communityOne?.community.nsfw).toBe(communityTwo?.community.nsfw);
|
|
|
|
expect(communityOne?.community.removed).toBe(communityTwo?.community.removed);
|
|
|
|
expect(communityOne?.community.deleted).toBe(communityTwo?.community.deleted);
|
2020-09-17 15:41:51 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
test("Create community", async () => {
|
2020-08-04 14:57:37 +00:00
|
|
|
let communityRes = await createCommunity(alpha);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(communityRes.community_view.community.name).toBeDefined();
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// A dupe check
|
2020-12-20 21:16:57 +00:00
|
|
|
let prevName = communityRes.community_view.community.name;
|
2023-07-21 09:47:56 +00:00
|
|
|
await expect(createCommunity(alpha, prevName)).rejects.toBe(
|
|
|
|
"community_already_exists",
|
|
|
|
);
|
2020-09-15 19:26:47 +00:00
|
|
|
|
|
|
|
// Cache the community on beta, make sure it has the other fields
|
|
|
|
let searchShort = `!${prevName}@lemmy-alpha:8541`;
|
2023-01-04 15:59:26 +00:00
|
|
|
let betaCommunity = (await resolveCommunity(beta, searchShort)).community;
|
2021-08-23 15:25:39 +00:00
|
|
|
assertCommunityFederation(betaCommunity, communityRes.community_view);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
test("Delete community", async () => {
|
2020-08-04 14:57:37 +00:00
|
|
|
let communityRes = await createCommunity(beta);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
|
|
|
// Cache the community on Alpha
|
2020-12-20 21:16:57 +00:00
|
|
|
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
|
2023-01-04 15:59:26 +00:00
|
|
|
let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
|
|
|
|
if (!alphaCommunity) {
|
|
|
|
throw "Missing alpha community";
|
|
|
|
}
|
2021-08-23 15:25:39 +00:00
|
|
|
assertCommunityFederation(alphaCommunity, communityRes.community_view);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
|
|
|
// Follow the community from alpha
|
2022-10-27 09:24:07 +00:00
|
|
|
let follow = await followCommunity(alpha, true, alphaCommunity.community.id);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
|
|
|
// Make sure the follow response went through
|
2022-05-26 15:17:04 +00:00
|
|
|
expect(follow.community_view.community.local).toBe(false);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
let deleteCommunityRes = await deleteCommunity(
|
|
|
|
beta,
|
|
|
|
true,
|
2023-07-06 13:10:38 +00:00
|
|
|
communityRes.community_view.community.id,
|
2020-08-04 14:57:37 +00:00
|
|
|
);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
|
2022-10-27 09:24:07 +00:00
|
|
|
expect(deleteCommunityRes.community_view.community.title).toBe(
|
2023-07-06 13:10:38 +00:00
|
|
|
communityRes.community_view.community.title,
|
2022-10-27 09:24:07 +00:00
|
|
|
);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Make sure it got deleted on A
|
2023-09-09 16:25:03 +00:00
|
|
|
let communityOnAlphaDeleted = await waitUntil(
|
|
|
|
() => getCommunity(alpha, alphaCommunity!.community.id),
|
|
|
|
g => g.community_view.community.deleted,
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
|
|
|
expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Undelete
|
|
|
|
let undeleteCommunityRes = await deleteCommunity(
|
|
|
|
beta,
|
|
|
|
false,
|
2023-07-06 13:10:38 +00:00
|
|
|
communityRes.community_view.community.id,
|
2020-08-04 14:57:37 +00:00
|
|
|
);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(undeleteCommunityRes.community_view.community.deleted).toBe(false);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Make sure it got undeleted on A
|
2023-09-09 16:25:03 +00:00
|
|
|
let communityOnAlphaUnDeleted = await waitUntil(
|
|
|
|
() => getCommunity(alpha, alphaCommunity!.community.id),
|
|
|
|
g => !g.community_view.community.deleted,
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
|
|
|
expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe(
|
2023-07-06 13:10:38 +00:00
|
|
|
false,
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
test("Remove community", async () => {
|
2020-08-04 14:57:37 +00:00
|
|
|
let communityRes = await createCommunity(beta);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
|
|
|
// Cache the community on Alpha
|
2020-12-20 21:16:57 +00:00
|
|
|
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
|
2023-01-04 15:59:26 +00:00
|
|
|
let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
|
|
|
|
if (!alphaCommunity) {
|
|
|
|
throw "Missing alpha community";
|
|
|
|
}
|
2021-08-23 15:25:39 +00:00
|
|
|
assertCommunityFederation(alphaCommunity, communityRes.community_view);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
|
|
|
// Follow the community from alpha
|
2022-10-27 09:24:07 +00:00
|
|
|
let follow = await followCommunity(alpha, true, alphaCommunity.community.id);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
|
|
|
// Make sure the follow response went through
|
2022-05-26 15:17:04 +00:00
|
|
|
expect(follow.community_view.community.local).toBe(false);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
let removeCommunityRes = await removeCommunity(
|
|
|
|
beta,
|
|
|
|
true,
|
2023-07-06 13:10:38 +00:00
|
|
|
communityRes.community_view.community.id,
|
2020-08-04 14:57:37 +00:00
|
|
|
);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(removeCommunityRes.community_view.community.removed).toBe(true);
|
2022-10-27 09:24:07 +00:00
|
|
|
expect(removeCommunityRes.community_view.community.title).toBe(
|
2023-07-06 13:10:38 +00:00
|
|
|
communityRes.community_view.community.title,
|
2022-10-27 09:24:07 +00:00
|
|
|
);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-11-05 20:19:06 +00:00
|
|
|
// Make sure it got Removed on A
|
2023-09-09 16:25:03 +00:00
|
|
|
let communityOnAlphaRemoved = await waitUntil(
|
|
|
|
() => getCommunity(alpha, alphaCommunity!.community.id),
|
|
|
|
g => g.community_view.community.removed,
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
|
|
|
expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// unremove
|
|
|
|
let unremoveCommunityRes = await removeCommunity(
|
|
|
|
beta,
|
|
|
|
false,
|
2023-07-06 13:10:38 +00:00
|
|
|
communityRes.community_view.community.id,
|
2020-08-04 14:57:37 +00:00
|
|
|
);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(unremoveCommunityRes.community_view.community.removed).toBe(false);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-11-05 20:19:06 +00:00
|
|
|
// Make sure it got undeleted on A
|
2023-09-09 16:25:03 +00:00
|
|
|
let communityOnAlphaUnRemoved = await waitUntil(
|
|
|
|
() => getCommunity(alpha, alphaCommunity!.community.id),
|
|
|
|
g => !g.community_view.community.removed,
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
|
|
|
expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe(
|
2023-07-06 13:10:38 +00:00
|
|
|
false,
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
test("Search for beta community", async () => {
|
2020-11-05 20:19:06 +00:00
|
|
|
let communityRes = await createCommunity(beta);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(communityRes.community_view.community.name).toBeDefined();
|
2020-11-05 20:19:06 +00:00
|
|
|
|
2020-12-20 21:16:57 +00:00
|
|
|
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
|
2023-01-04 15:59:26 +00:00
|
|
|
let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
|
2021-08-23 15:25:39 +00:00
|
|
|
assertCommunityFederation(alphaCommunity, communityRes.community_view);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
2022-10-10 15:20:36 +00:00
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
test("Admin actions in remote community are not federated to origin", async () => {
|
2022-10-10 15:20:36 +00:00
|
|
|
// create a community on alpha
|
|
|
|
let communityRes = (await createCommunity(alpha)).community_view;
|
|
|
|
expect(communityRes.community.name).toBeDefined();
|
|
|
|
|
|
|
|
// gamma follows community and posts in it
|
2022-10-27 09:24:07 +00:00
|
|
|
let gammaCommunity = (
|
|
|
|
await resolveCommunity(gamma, communityRes.community.actor_id)
|
2023-01-04 15:59:26 +00:00
|
|
|
).community;
|
|
|
|
if (!gammaCommunity) {
|
|
|
|
throw "Missing gamma community";
|
|
|
|
}
|
|
|
|
await followCommunity(gamma, true, gammaCommunity.community.id);
|
2022-11-28 14:29:33 +00:00
|
|
|
gammaCommunity = (
|
2023-09-09 16:25:03 +00:00
|
|
|
await waitUntil(
|
|
|
|
() => resolveCommunity(gamma, communityRes.community.actor_id),
|
|
|
|
g => g.community?.subscribed === "Subscribed",
|
|
|
|
)
|
2023-01-04 15:59:26 +00:00
|
|
|
).community;
|
|
|
|
if (!gammaCommunity) {
|
|
|
|
throw "Missing gamma community";
|
|
|
|
}
|
2022-11-28 14:29:33 +00:00
|
|
|
expect(gammaCommunity.subscribed).toBe("Subscribed");
|
2022-10-27 09:24:07 +00:00
|
|
|
let gammaPost = (await createPost(gamma, gammaCommunity.community.id))
|
|
|
|
.post_view;
|
2022-10-10 15:20:36 +00:00
|
|
|
expect(gammaPost.post.id).toBeDefined();
|
|
|
|
expect(gammaPost.creator_banned_from_community).toBe(false);
|
|
|
|
|
|
|
|
// admin of beta decides to ban gamma from community
|
2022-10-27 09:24:07 +00:00
|
|
|
let betaCommunity = (
|
|
|
|
await resolveCommunity(beta, communityRes.community.actor_id)
|
2023-01-04 15:59:26 +00:00
|
|
|
).community;
|
|
|
|
if (!betaCommunity) {
|
|
|
|
throw "Missing beta community";
|
|
|
|
}
|
|
|
|
let bannedUserInfo1 = (await getSite(gamma)).my_user?.local_user_view.person;
|
|
|
|
if (!bannedUserInfo1) {
|
|
|
|
throw "Missing banned user 1";
|
|
|
|
}
|
|
|
|
let bannedUserInfo2 = (await resolvePerson(beta, bannedUserInfo1.actor_id))
|
2022-10-27 09:24:07 +00:00
|
|
|
.person;
|
2023-01-04 15:59:26 +00:00
|
|
|
if (!bannedUserInfo2) {
|
|
|
|
throw "Missing banned user 2";
|
|
|
|
}
|
2022-10-27 09:24:07 +00:00
|
|
|
let banRes = await banPersonFromCommunity(
|
|
|
|
beta,
|
|
|
|
bannedUserInfo2.person.id,
|
|
|
|
betaCommunity.community.id,
|
|
|
|
true,
|
2023-07-06 13:10:38 +00:00
|
|
|
true,
|
2022-10-27 09:24:07 +00:00
|
|
|
);
|
2023-10-19 17:21:05 +00:00
|
|
|
expect(banRes.success).toBe(true);
|
2022-10-10 15:20:36 +00:00
|
|
|
|
|
|
|
// ban doesnt federate to community's origin instance alpha
|
2023-09-21 12:01:22 +00:00
|
|
|
let alphaPost = (await resolvePost(alpha, gammaPost.post)).post;
|
2023-01-04 15:59:26 +00:00
|
|
|
expect(alphaPost?.creator_banned_from_community).toBe(false);
|
2022-10-10 15:20:36 +00:00
|
|
|
|
|
|
|
// and neither to gamma
|
2022-10-27 09:24:07 +00:00
|
|
|
let gammaPost2 = await getPost(gamma, gammaPost.post.id);
|
2022-10-10 15:20:36 +00:00
|
|
|
expect(gammaPost2.post_view.creator_banned_from_community).toBe(false);
|
|
|
|
});
|
2023-07-26 17:51:11 +00:00
|
|
|
|
|
|
|
test("moderator view", async () => {
|
|
|
|
// register a new user with their own community on alpha and post to it
|
2023-09-21 10:42:28 +00:00
|
|
|
let registerUserRes = await registerUser(alpha);
|
|
|
|
let otherUser = new LemmyHttp(alphaUrl, {
|
2023-09-25 10:37:45 +00:00
|
|
|
headers: { Authorization: `Bearer ${registerUserRes.jwt ?? ""}` },
|
2023-09-21 10:42:28 +00:00
|
|
|
});
|
2023-08-31 11:07:45 +00:00
|
|
|
|
2023-07-26 17:51:11 +00:00
|
|
|
let otherCommunity = (await createCommunity(otherUser)).community_view;
|
|
|
|
expect(otherCommunity.community.name).toBeDefined();
|
|
|
|
let otherPost = (await createPost(otherUser, otherCommunity.community.id))
|
|
|
|
.post_view;
|
|
|
|
expect(otherPost.post.id).toBeDefined();
|
|
|
|
|
2023-08-31 11:07:45 +00:00
|
|
|
let otherComment = (await createComment(otherUser, otherPost.post.id))
|
|
|
|
.comment_view;
|
|
|
|
expect(otherComment.comment.id).toBeDefined();
|
|
|
|
|
2023-07-26 17:51:11 +00:00
|
|
|
// create a community and post on alpha
|
|
|
|
let alphaCommunity = (await createCommunity(alpha)).community_view;
|
|
|
|
expect(alphaCommunity.community.name).toBeDefined();
|
|
|
|
let alphaPost = (await createPost(alpha, alphaCommunity.community.id))
|
|
|
|
.post_view;
|
|
|
|
expect(alphaPost.post.id).toBeDefined();
|
|
|
|
|
2023-08-31 11:07:45 +00:00
|
|
|
let alphaComment = (await createComment(otherUser, alphaPost.post.id))
|
|
|
|
.comment_view;
|
|
|
|
expect(alphaComment.comment.id).toBeDefined();
|
|
|
|
|
2023-07-26 17:51:11 +00:00
|
|
|
// other user also posts on alpha's community
|
|
|
|
let otherAlphaPost = (
|
|
|
|
await createPost(otherUser, alphaCommunity.community.id)
|
|
|
|
).post_view;
|
|
|
|
expect(otherAlphaPost.post.id).toBeDefined();
|
|
|
|
|
2023-08-31 11:07:45 +00:00
|
|
|
let otherAlphaComment = (
|
|
|
|
await createComment(otherUser, otherAlphaPost.post.id)
|
|
|
|
).comment_view;
|
|
|
|
expect(otherAlphaComment.comment.id).toBeDefined();
|
|
|
|
|
|
|
|
// alpha lists posts and comments on home page, should contain all posts that were made
|
|
|
|
let posts = (await getPosts(alpha, "All")).posts;
|
2023-07-26 17:51:11 +00:00
|
|
|
expect(posts).toBeDefined();
|
|
|
|
let postIds = posts.map(post => post.post.id);
|
2023-08-31 11:07:45 +00:00
|
|
|
|
|
|
|
let comments = (await getComments(alpha, undefined, "All")).comments;
|
|
|
|
expect(comments).toBeDefined();
|
|
|
|
let commentIds = comments.map(comment => comment.comment.id);
|
|
|
|
|
2023-07-26 17:51:11 +00:00
|
|
|
expect(postIds).toContain(otherPost.post.id);
|
2023-08-31 11:07:45 +00:00
|
|
|
expect(commentIds).toContain(otherComment.comment.id);
|
|
|
|
|
2023-07-26 17:51:11 +00:00
|
|
|
expect(postIds).toContain(alphaPost.post.id);
|
2023-08-31 11:07:45 +00:00
|
|
|
expect(commentIds).toContain(alphaComment.comment.id);
|
|
|
|
|
2023-07-26 17:51:11 +00:00
|
|
|
expect(postIds).toContain(otherAlphaPost.post.id);
|
2023-08-31 11:07:45 +00:00
|
|
|
expect(commentIds).toContain(otherAlphaComment.comment.id);
|
2023-07-26 17:51:11 +00:00
|
|
|
|
|
|
|
// in moderator view, alpha should not see otherPost, wich was posted on a community alpha doesn't moderate
|
2023-08-31 11:07:45 +00:00
|
|
|
posts = (await getPosts(alpha, "ModeratorView")).posts;
|
2023-07-26 17:51:11 +00:00
|
|
|
expect(posts).toBeDefined();
|
|
|
|
postIds = posts.map(post => post.post.id);
|
2023-08-31 11:07:45 +00:00
|
|
|
|
|
|
|
comments = (await getComments(alpha, undefined, "ModeratorView")).comments;
|
|
|
|
expect(comments).toBeDefined();
|
|
|
|
commentIds = comments.map(comment => comment.comment.id);
|
|
|
|
|
2023-07-26 17:51:11 +00:00
|
|
|
expect(postIds).not.toContain(otherPost.post.id);
|
2023-08-31 11:07:45 +00:00
|
|
|
expect(commentIds).not.toContain(otherComment.comment.id);
|
|
|
|
|
2023-07-26 17:51:11 +00:00
|
|
|
expect(postIds).toContain(alphaPost.post.id);
|
2023-08-31 11:07:45 +00:00
|
|
|
expect(commentIds).toContain(alphaComment.comment.id);
|
|
|
|
|
2023-07-26 17:51:11 +00:00
|
|
|
expect(postIds).toContain(otherAlphaPost.post.id);
|
2023-08-31 11:07:45 +00:00
|
|
|
expect(commentIds).toContain(otherAlphaComment.comment.id);
|
2023-07-26 17:51:11 +00:00
|
|
|
});
|
2023-08-22 15:10:21 +00:00
|
|
|
|
|
|
|
test("Get community for different casing on domain", async () => {
|
|
|
|
let communityRes = await createCommunity(alpha);
|
|
|
|
expect(communityRes.community_view.community.name).toBeDefined();
|
|
|
|
|
|
|
|
// A dupe check
|
|
|
|
let prevName = communityRes.community_view.community.name;
|
|
|
|
await expect(createCommunity(alpha, prevName)).rejects.toBe(
|
|
|
|
"community_already_exists",
|
|
|
|
);
|
|
|
|
|
|
|
|
// Cache the community on beta, make sure it has the other fields
|
|
|
|
let communityName = `${communityRes.community_view.community.name}@LEMMY-ALPHA:8541`;
|
|
|
|
let betaCommunity = (await getCommunityByName(beta, communityName))
|
|
|
|
.community_view;
|
|
|
|
assertCommunityFederation(betaCommunity, communityRes.community_view);
|
|
|
|
});
|
2023-09-20 09:56:13 +00:00
|
|
|
|
|
|
|
test("User blocks instance, communities are hidden", async () => {
|
|
|
|
// create community and post on beta
|
|
|
|
let communityRes = await createCommunity(beta);
|
|
|
|
expect(communityRes.community_view.community.name).toBeDefined();
|
|
|
|
let postRes = await createPost(
|
|
|
|
beta,
|
|
|
|
communityRes.community_view.community.id,
|
|
|
|
);
|
|
|
|
expect(postRes.post_view.post.id).toBeDefined();
|
|
|
|
|
|
|
|
// fetch post to alpha
|
2023-09-21 12:01:22 +00:00
|
|
|
let alphaPost = (await resolvePost(alpha, postRes.post_view.post)).post!;
|
2023-09-20 20:55:43 +00:00
|
|
|
expect(alphaPost.post).toBeDefined();
|
2023-09-20 09:56:13 +00:00
|
|
|
|
|
|
|
// post should be included in listing
|
|
|
|
let listing = await getPosts(alpha, "All");
|
|
|
|
let listing_ids = listing.posts.map(p => p.post.ap_id);
|
|
|
|
expect(listing_ids).toContain(postRes.post_view.post.ap_id);
|
|
|
|
|
|
|
|
// block the beta instance
|
2023-09-20 20:55:43 +00:00
|
|
|
await blockInstance(alpha, alphaPost.community.instance_id, true);
|
2023-09-20 09:56:13 +00:00
|
|
|
|
|
|
|
// after blocking, post should not be in listing
|
|
|
|
let listing2 = await getPosts(alpha, "All");
|
|
|
|
let listing_ids2 = listing2.posts.map(p => p.post.ap_id);
|
|
|
|
expect(listing_ids2.indexOf(postRes.post_view.post.ap_id)).toBe(-1);
|
|
|
|
|
|
|
|
// unblock instance again
|
2023-09-20 20:55:43 +00:00
|
|
|
await blockInstance(alpha, alphaPost.community.instance_id, false);
|
2023-09-20 09:56:13 +00:00
|
|
|
|
|
|
|
// post should be included in listing
|
|
|
|
let listing3 = await getPosts(alpha, "All");
|
|
|
|
let listing_ids3 = listing3.posts.map(p => p.post.ap_id);
|
|
|
|
expect(listing_ids3).toContain(postRes.post_view.post.ap_id);
|
|
|
|
});
|
2023-10-16 10:03:49 +00:00
|
|
|
|
2023-10-17 14:34:38 +00:00
|
|
|
test("Community follower count is federated", async () => {
|
|
|
|
// Follow the beta community from alpha
|
|
|
|
let resolved = await resolveBetaCommunity(alpha);
|
|
|
|
if (!resolved.community) {
|
|
|
|
throw "Missing beta community";
|
|
|
|
}
|
|
|
|
|
|
|
|
await followCommunity(alpha, true, resolved.community.community.id);
|
|
|
|
let followed = (
|
|
|
|
await waitUntil(
|
|
|
|
() => resolveBetaCommunity(alpha),
|
|
|
|
c => c.community?.subscribed === "Subscribed",
|
|
|
|
)
|
|
|
|
).community;
|
|
|
|
|
|
|
|
// Make sure there is 1 subscriber
|
|
|
|
expect(followed?.counts.subscribers).toBe(1);
|
|
|
|
|
|
|
|
// Follow the community from gamma
|
|
|
|
resolved = await resolveBetaCommunity(gamma);
|
|
|
|
if (!resolved.community) {
|
|
|
|
throw "Missing beta community";
|
|
|
|
}
|
|
|
|
|
|
|
|
await followCommunity(gamma, true, resolved.community.community.id);
|
|
|
|
followed = (
|
|
|
|
await waitUntil(
|
|
|
|
() => resolveBetaCommunity(gamma),
|
|
|
|
c => c.community?.subscribed === "Subscribed",
|
|
|
|
)
|
|
|
|
).community;
|
|
|
|
|
|
|
|
// Make sure there are 2 subscribers
|
|
|
|
expect(followed?.counts?.subscribers).toBe(2);
|
|
|
|
|
|
|
|
// Follow the community from delta
|
|
|
|
resolved = await resolveBetaCommunity(delta);
|
|
|
|
if (!resolved.community) {
|
|
|
|
throw "Missing beta community";
|
|
|
|
}
|
|
|
|
|
|
|
|
await followCommunity(delta, true, resolved.community.community.id);
|
|
|
|
followed = (
|
|
|
|
await waitUntil(
|
|
|
|
() => resolveBetaCommunity(delta),
|
|
|
|
c => c.community?.subscribed === "Subscribed",
|
|
|
|
)
|
|
|
|
).community;
|
|
|
|
|
|
|
|
// Make sure there are 3 subscribers
|
|
|
|
expect(followed?.counts?.subscribers).toBe(3);
|
|
|
|
});
|
|
|
|
|
2023-10-16 10:03:49 +00:00
|
|
|
test("Dont receive community activities after unsubscribe", async () => {
|
|
|
|
let communityRes = await createCommunity(alpha);
|
|
|
|
expect(communityRes.community_view.community.name).toBeDefined();
|
|
|
|
expect(communityRes.community_view.counts.subscribers).toBe(1);
|
|
|
|
|
|
|
|
let betaCommunity = (
|
|
|
|
await resolveCommunity(beta, communityRes.community_view.community.actor_id)
|
|
|
|
).community;
|
|
|
|
assertCommunityFederation(betaCommunity, communityRes.community_view);
|
|
|
|
|
|
|
|
// follow alpha community from beta
|
|
|
|
await followCommunity(beta, true, betaCommunity!.community.id);
|
|
|
|
|
|
|
|
// ensure that follower count was updated
|
|
|
|
let communityRes1 = await getCommunity(
|
|
|
|
alpha,
|
|
|
|
communityRes.community_view.community.id,
|
|
|
|
);
|
|
|
|
expect(communityRes1.community_view.counts.subscribers).toBe(2);
|
|
|
|
|
|
|
|
// temporarily block alpha, so that it doesnt know about unfollow
|
|
|
|
let editSiteForm: EditSite = {};
|
|
|
|
editSiteForm.allowed_instances = ["lemmy-epsilon"];
|
|
|
|
await beta.editSite(editSiteForm);
|
2023-10-17 14:34:38 +00:00
|
|
|
await longDelay();
|
2023-10-16 10:03:49 +00:00
|
|
|
|
|
|
|
// unfollow
|
|
|
|
await followCommunity(beta, false, betaCommunity!.community.id);
|
|
|
|
|
|
|
|
// ensure that alpha still sees beta as follower
|
|
|
|
let communityRes2 = await getCommunity(
|
|
|
|
alpha,
|
|
|
|
communityRes.community_view.community.id,
|
|
|
|
);
|
|
|
|
expect(communityRes2.community_view.counts.subscribers).toBe(2);
|
|
|
|
|
|
|
|
// unblock alpha
|
|
|
|
editSiteForm.allowed_instances = betaAllowedInstances;
|
|
|
|
await beta.editSite(editSiteForm);
|
2023-10-17 14:34:38 +00:00
|
|
|
await longDelay();
|
2023-10-16 10:03:49 +00:00
|
|
|
|
|
|
|
// create a post, it shouldnt reach beta
|
|
|
|
let postRes = await createPost(
|
|
|
|
alpha,
|
|
|
|
communityRes.community_view.community.id,
|
|
|
|
);
|
|
|
|
expect(postRes.post_view.post.id).toBeDefined();
|
2023-10-17 14:34:38 +00:00
|
|
|
// await longDelay();
|
2023-10-16 10:03:49 +00:00
|
|
|
|
|
|
|
let postResBeta = searchPostLocal(beta, postRes.post_view.post);
|
|
|
|
expect((await postResBeta).posts.length).toBe(0);
|
|
|
|
});
|