mirror of https://github.com/LemmyNet/lemmy.git
tweak tests more
parent
7dd857e00b
commit
dff54d5e39
|
@ -342,6 +342,8 @@ test("Federated comment like", async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Reply to a comment from another instance, get notification", 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;
|
let betaCommunity = (await resolveBetaCommunity(alpha)).community;
|
||||||
if (!betaCommunity) {
|
if (!betaCommunity) {
|
||||||
throw "Missing beta community";
|
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
|
// check inbox of replies on alpha, fetching read/unread both
|
||||||
let alphaRepliesRes = await getReplies(alpha);
|
let alphaRepliesRes = await getReplies(alpha);
|
||||||
expect(alphaRepliesRes.replies.length).toBe(1);
|
const alphaReply = alphaRepliesRes.replies.find(
|
||||||
expect(alphaRepliesRes.replies[0].comment.content).toBeDefined();
|
r => r.comment.id === alphaComment.comment.id,
|
||||||
expect(alphaRepliesRes.replies[0].community.local).toBe(false);
|
);
|
||||||
expect(alphaRepliesRes.replies[0].creator.local).toBe(false);
|
expect(alphaReply).toBeDefined();
|
||||||
expect(alphaRepliesRes.replies[0].counts.score).toBe(1);
|
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?
|
// 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.
|
// 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);
|
expect(alphaReply.comment_reply.read).toBe(false);
|
||||||
assertCommentFederation(alphaRepliesRes.replies[0], replyRes.comment_view);
|
assertCommentFederation(alphaReply, replyRes.comment_view);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Mention beta from alpha", async () => {
|
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);
|
expect(alphaPost.post_view.community.local).toBe(true);
|
||||||
|
|
||||||
// Make sure gamma sees it
|
// 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) {
|
if (!gammaPost) {
|
||||||
throw "Missing gamma post";
|
throw "Missing gamma post";
|
||||||
|
|
|
@ -237,7 +237,7 @@ test("Admin actions in remote community are not federated to origin", async () =
|
||||||
expect(banRes.banned).toBe(true);
|
expect(banRes.banned).toBe(true);
|
||||||
|
|
||||||
// ban doesnt federate to community's origin instance alpha
|
// 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);
|
expect(alphaPost?.creator_banned_from_community).toBe(false);
|
||||||
|
|
||||||
// and neither to gamma
|
// and neither to gamma
|
||||||
|
|
|
@ -83,10 +83,10 @@ test("Create a post", async () => {
|
||||||
|
|
||||||
// Make sure that post is liked on beta
|
// Make sure that post is liked on beta
|
||||||
const res = await waitUntil(
|
const res = await waitUntil(
|
||||||
() => resolvePost(beta, postRes.post_view.post),
|
() => resolvePost(beta, postRes.post_view.post).catch(e => null),
|
||||||
res => res.post?.counts.score === 1,
|
res => res?.post?.counts.score === 1,
|
||||||
);
|
);
|
||||||
let betaPost = res.post;
|
let betaPost = res?.post;
|
||||||
|
|
||||||
expect(betaPost).toBeDefined();
|
expect(betaPost).toBeDefined();
|
||||||
expect(betaPost?.community.local).toBe(true);
|
expect(betaPost?.community.local).toBe(true);
|
||||||
|
@ -177,7 +177,7 @@ test("Sticky a post", async () => {
|
||||||
}
|
}
|
||||||
let postRes = await createPost(alpha, betaCommunity.community.id);
|
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) {
|
if (!betaPost1) {
|
||||||
throw "Missing beta post1";
|
throw "Missing beta post1";
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,8 @@ test("Sticky a post", async () => {
|
||||||
expect(betaPost2?.post.featured_community).toBe(false);
|
expect(betaPost2?.post.featured_community).toBe(false);
|
||||||
|
|
||||||
// Make sure that gamma cannot sticky the post on beta
|
// 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) {
|
if (!gammaPost) {
|
||||||
throw "Missing gamma post";
|
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 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) {
|
if (!alphaPost) {
|
||||||
throw "Missing alpha post";
|
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);
|
expect(removedPost.post_view.post.name).toBe(postRes.post_view.post.name);
|
||||||
|
|
||||||
// Make sure lemmy beta sees post is NOT removed
|
// 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) {
|
if (!betaPost) {
|
||||||
throw "Missing beta post";
|
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);
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
||||||
expect(postRes.post_view.post).toBeDefined();
|
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();
|
expect(betaPost?.post.name).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -546,7 +548,8 @@ test("Report a post", async () => {
|
||||||
let postRes = await createPost(beta, betaCommunity.community.id);
|
let postRes = await createPost(beta, betaCommunity.community.id);
|
||||||
expect(postRes.post_view.post).toBeDefined();
|
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) {
|
if (!alphaPost) {
|
||||||
throw "Missing alpha post";
|
throw "Missing alpha post";
|
||||||
}
|
}
|
||||||
|
@ -554,12 +557,16 @@ test("Report a post", async () => {
|
||||||
await reportPost(alpha, alphaPost.post.id, randomString(10))
|
await reportPost(alpha, alphaPost.post.id, randomString(10))
|
||||||
).post_report_view.post_report;
|
).post_report_view.post_report;
|
||||||
|
|
||||||
let betaReport = (
|
let betaReport = (await waitUntil(
|
||||||
await waitUntil(
|
() =>
|
||||||
() => listPostReports(beta),
|
listPostReports(beta).then(p =>
|
||||||
res => !!res.post_reports[0],
|
p.post_reports.find(
|
||||||
)
|
r =>
|
||||||
).post_reports[0].post_report;
|
r.post_report.original_post_name === alphaReport.original_post_name,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
res => !!res,
|
||||||
|
))!.post_report;
|
||||||
expect(betaReport).toBeDefined();
|
expect(betaReport).toBeDefined();
|
||||||
expect(betaReport.resolved).toBe(false);
|
expect(betaReport.resolved).toBe(false);
|
||||||
expect(betaReport.original_post_name).toBe(alphaReport.original_post_name);
|
expect(betaReport.original_post_name).toBe(alphaReport.original_post_name);
|
||||||
|
@ -588,7 +595,7 @@ test("Sanitize HTML", async () => {
|
||||||
"<script>alert('xss');</script> hello &"'",
|
"<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 &
|
// second escaping over federation, avoid double escape of &
|
||||||
expect(alphaPost?.post.body).toBe(
|
expect(alphaPost?.post.body).toBe(
|
||||||
"<script>alert('xss');</script> hello &"'",
|
"<script>alert('xss');</script> hello &"'",
|
||||||
|
|
|
@ -296,10 +296,11 @@ export async function lockPost(
|
||||||
export async function resolvePost(
|
export async function resolvePost(
|
||||||
api: API,
|
api: API,
|
||||||
post: Post,
|
post: Post,
|
||||||
|
localOnly = true,
|
||||||
): Promise<ResolveObjectResponse> {
|
): Promise<ResolveObjectResponse> {
|
||||||
let form: ResolveObject = {
|
let form: ResolveObject = {
|
||||||
q: post.ap_id,
|
q: post.ap_id,
|
||||||
auth: api.auth,
|
auth: localOnly ? null : api.auth,
|
||||||
};
|
};
|
||||||
return api.client.resolveObject(form);
|
return api.client.resolveObject(form);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue