add test for moderator view

This commit is contained in:
biosfood 2023-06-28 17:16:24 +02:00
parent 0519bf566e
commit c63d41710e
2 changed files with 59 additions and 0 deletions

View file

@ -18,6 +18,9 @@ import {
createPost,
getPost,
resolvePost,
registerUser,
API,
getPosts,
} from "./shared";
beforeAll(async () => {
@ -232,3 +235,46 @@ test("Admin actions in remote community are not federated to origin", async () =
let gammaPost2 = await getPost(gamma, gammaPost.post.id);
expect(gammaPost2.post_view.creator_banned_from_community).toBe(false);
});
test("moderator view", async () => {
// register a new user with their own community on alpha and post to it
let otherUser: API = {
auth: (await registerUser(alpha)).jwt ?? "",
client: alpha.client,
};
expect(otherUser.auth).not.toBe("");
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();
// 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();
// other user also posts on alpha's community
let otherAlphaPost = (
await createPost(otherUser, alphaCommunity.community.id)
).post_view;
expect(otherAlphaPost.post.id).toBeDefined();
// alpha lists posts on home page, should contain all posts that were made
let posts = (await getPosts(alpha)).posts;
expect(posts).toBeDefined();
let postIds = posts.map(post => post.post.id);
expect(postIds).toContain(otherPost.post.id);
expect(postIds).toContain(alphaPost.post.id);
expect(postIds).toContain(otherAlphaPost.post.id);
// in moderator view, alpha should not see otherPost, wich was posted on a community alpha doesn't moderate
posts = (await getPosts(alpha, true)).posts;
expect(posts).toBeDefined();
postIds = posts.map(post => post.post.id);
expect(postIds).not.toContain(otherPost.post.id);
expect(postIds).toContain(alphaPost.post.id);
expect(postIds).toContain(otherAlphaPost.post.id);
});

View file

@ -58,6 +58,8 @@ import { CommentReportResponse } from "lemmy-js-client/dist/types/CommentReportR
import { CreateCommentReport } from "lemmy-js-client/dist/types/CreateCommentReport";
import { ListCommentReportsResponse } from "lemmy-js-client/dist/types/ListCommentReportsResponse";
import { ListCommentReports } from "lemmy-js-client/dist/types/ListCommentReports";
import { GetPostsResponse } from "lemmy-js-client/dist/types/GetPostsResponse";
import { GetPosts } from "lemmy-js-client/dist/types/GetPosts";
export interface API {
client: LemmyHttp;
@ -738,6 +740,17 @@ export async function listCommentReports(
return api.client.listCommentReports(form);
}
export function getPosts(
api: API,
moderator_view = false
): Promise<GetPostsResponse> {
let form: GetPosts | { moderator_view: boolean } = {
moderator_view,
auth: api.auth,
};
return api.client.getPosts(form as GetPosts);
}
export function delay(millis = 500) {
return new Promise(resolve => setTimeout(resolve, millis));
}