tweak tests more

This commit is contained in:
phiresky 2023-09-18 19:58:20 +00:00
parent 7dd857e00b
commit dff54d5e39
4 changed files with 42 additions and 27 deletions

View file

@ -342,6 +342,8 @@ test("Federated comment like", async () => {
});
test("Reply to a comment from another instance, get notification", async () => {
await alpha.client.markAllAsRead({ auth: alpha.auth });
let betaCommunity = (await resolveBetaCommunity(alpha)).community;
if (!betaCommunity) {
throw "Missing beta community";
@ -404,16 +406,20 @@ test("Reply to a comment from another instance, get notification", async () => {
// check inbox of replies on alpha, fetching read/unread both
let alphaRepliesRes = await getReplies(alpha);
expect(alphaRepliesRes.replies.length).toBe(1);
expect(alphaRepliesRes.replies[0].comment.content).toBeDefined();
expect(alphaRepliesRes.replies[0].community.local).toBe(false);
expect(alphaRepliesRes.replies[0].creator.local).toBe(false);
expect(alphaRepliesRes.replies[0].counts.score).toBe(1);
const alphaReply = alphaRepliesRes.replies.find(
r => r.comment.id === alphaComment.comment.id,
);
expect(alphaReply).toBeDefined();
if (!alphaReply) throw Error();
expect(alphaReply.comment.content).toBeDefined();
expect(alphaReply.community.local).toBe(false);
expect(alphaReply.creator.local).toBe(false);
expect(alphaReply.counts.score).toBe(1);
// ToDo: interesting alphaRepliesRes.replies[0].comment_reply.id is 1, meaning? how did that come about?
expect(alphaRepliesRes.replies[0].comment.id).toBe(alphaComment.comment.id);
expect(alphaReply.comment.id).toBe(alphaComment.comment.id);
// this is a new notification, getReplies fetch was for read/unread both, confirm it is unread.
expect(alphaRepliesRes.replies[0].comment_reply.read).toBe(false);
assertCommentFederation(alphaRepliesRes.replies[0], replyRes.comment_view);
expect(alphaReply.comment_reply.read).toBe(false);
assertCommentFederation(alphaReply, replyRes.comment_view);
});
test("Mention beta from alpha", async () => {
@ -494,7 +500,8 @@ test("A and G subscribe to B (center) A posts, G mentions B, it gets announced t
expect(alphaPost.post_view.community.local).toBe(true);
// Make sure gamma sees it
let gammaPost = (await resolvePost(gamma, alphaPost.post_view.post)).post;
let gammaPost = (await resolvePost(gamma, alphaPost.post_view.post, false))!
.post;
if (!gammaPost) {
throw "Missing gamma post";

View file

@ -237,7 +237,7 @@ test("Admin actions in remote community are not federated to origin", async () =
expect(banRes.banned).toBe(true);
// ban doesnt federate to community's origin instance alpha
let alphaPost = (await resolvePost(alpha, gammaPost.post)).post;
let alphaPost = (await resolvePost(alpha, gammaPost.post, false)).post;
expect(alphaPost?.creator_banned_from_community).toBe(false);
// and neither to gamma

View file

@ -83,10 +83,10 @@ test("Create a post", async () => {
// Make sure that post is liked on beta
const res = await waitUntil(
() => resolvePost(beta, postRes.post_view.post),
res => res.post?.counts.score === 1,
() => resolvePost(beta, postRes.post_view.post).catch(e => null),
res => res?.post?.counts.score === 1,
);
let betaPost = res.post;
let betaPost = res?.post;
expect(betaPost).toBeDefined();
expect(betaPost?.community.local).toBe(true);
@ -177,7 +177,7 @@ test("Sticky a post", async () => {
}
let postRes = await createPost(alpha, betaCommunity.community.id);
let betaPost1 = (await resolvePost(beta, postRes.post_view.post)).post;
let betaPost1 = (await resolvePost(beta, postRes.post_view.post, false)).post;
if (!betaPost1) {
throw "Missing beta post1";
}
@ -201,7 +201,8 @@ test("Sticky a post", async () => {
expect(betaPost2?.post.featured_community).toBe(false);
// Make sure that gamma cannot sticky the post on beta
let gammaPost = (await resolvePost(gamma, postRes.post_view.post)).post;
let gammaPost = (await resolvePost(gamma, postRes.post_view.post, false))
.post;
if (!gammaPost) {
throw "Missing gamma post";
}
@ -320,7 +321,8 @@ test("Remove a post from admin and community on different instance", async () =>
}
let postRes = await createPost(gamma, gammaCommunity.id);
let alphaPost = (await resolvePost(alpha, postRes.post_view.post)).post;
let alphaPost = (await resolvePost(alpha, postRes.post_view.post, false))
.post;
if (!alphaPost) {
throw "Missing alpha post";
}
@ -329,7 +331,7 @@ test("Remove a post from admin and community on different instance", async () =>
expect(removedPost.post_view.post.name).toBe(postRes.post_view.post.name);
// Make sure lemmy beta sees post is NOT removed
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
let betaPost = (await resolvePost(beta, postRes.post_view.post, false)).post;
if (!betaPost) {
throw "Missing beta post";
}
@ -533,7 +535,7 @@ test("A and G subscribe to B (center) A posts, it gets announced to G", async ()
let postRes = await createPost(alpha, betaCommunity.community.id);
expect(postRes.post_view.post).toBeDefined();
let betaPost = (await resolvePost(gamma, postRes.post_view.post)).post;
let betaPost = (await resolvePost(gamma, postRes.post_view.post, false)).post;
expect(betaPost?.post.name).toBeDefined();
});
@ -546,7 +548,8 @@ test("Report a post", async () => {
let postRes = await createPost(beta, betaCommunity.community.id);
expect(postRes.post_view.post).toBeDefined();
let alphaPost = (await resolvePost(alpha, postRes.post_view.post)).post;
let alphaPost = (await resolvePost(alpha, postRes.post_view.post, false))
.post;
if (!alphaPost) {
throw "Missing alpha post";
}
@ -554,12 +557,16 @@ test("Report a post", async () => {
await reportPost(alpha, alphaPost.post.id, randomString(10))
).post_report_view.post_report;
let betaReport = (
await waitUntil(
() => listPostReports(beta),
res => !!res.post_reports[0],
)
).post_reports[0].post_report;
let betaReport = (await waitUntil(
() =>
listPostReports(beta).then(p =>
p.post_reports.find(
r =>
r.post_report.original_post_name === alphaReport.original_post_name,
),
),
res => !!res,
))!.post_report;
expect(betaReport).toBeDefined();
expect(betaReport.resolved).toBe(false);
expect(betaReport.original_post_name).toBe(alphaReport.original_post_name);
@ -588,7 +595,7 @@ test("Sanitize HTML", async () => {
"<script>alert('xss');</script> hello &"'",
);
let alphaPost = (await resolvePost(alpha, post.post_view.post)).post;
let alphaPost = (await resolvePost(alpha, post.post_view.post, false)).post;
// second escaping over federation, avoid double escape of &
expect(alphaPost?.post.body).toBe(
"<script>alert('xss');</script> hello &"'",

View file

@ -296,10 +296,11 @@ export async function lockPost(
export async function resolvePost(
api: API,
post: Post,
localOnly = true,
): Promise<ResolveObjectResponse> {
let form: ResolveObject = {
q: post.ap_id,
auth: api.auth,
auth: localOnly ? null : api.auth,
};
return api.client.resolveObject(form);
}