From 7bd3b20ae08a64324029491ddb3ce4295ba16787 Mon Sep 17 00:00:00 2001 From: RocketDerp <113625597+RocketDerp@users.noreply.github.com> Date: Tue, 18 Jul 2023 12:42:12 -0700 Subject: [PATCH] Far more robust "Report a comment" test. Many comments about situation, this is currently failing because gamma does not get the report --- api_tests/src/comment.spec.ts | 60 +++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/api_tests/src/comment.spec.ts b/api_tests/src/comment.spec.ts index 4dcb405af..04b1c316e 100644 --- a/api_tests/src/comment.spec.ts +++ b/api_tests/src/comment.spec.ts @@ -574,31 +574,63 @@ test("Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde }); test("Report a comment", async () => { - let betaCommunity = (await resolveBetaCommunity(beta)).community; + let betaCommunityRes = await resolveBetaCommunity(beta); + // ToDo: this does not check for JSON { error: "message" } + let betaCommunity = betaCommunityRes?.community; if (!betaCommunity) { throw "Missing beta community"; } - let postRes = (await createPost(beta, betaCommunity.community.id)).post_view - .post; - expect(postRes).toBeDefined(); - let commentRes = (await createComment(beta, postRes.id)).comment_view.comment; - expect(commentRes).toBeDefined(); - let alphaComment = (await resolveComment(alpha, commentRes)).comment?.comment; + // NOTE: createPost tests outbound Internet connection + let betaPost = await createPost(beta, betaCommunity.community.id); + // let betaPost = await createNoLinkPost(beta, betaCommunity.community.id); + expect(betaPost.post_view?.post).toBeDefined(); + // ToDo: not enough of a test, "{ error: 'couldnt_send_webmention' }" passes + let createCommentRes = await createComment(beta, betaPost.post_view.post.id); + expect(createCommentRes?.comment_view?.comment).toBeDefined(); + let commentRes = createCommentRes.comment_view.comment; + + let alphaCommentRes = await resolveComment(alpha, commentRes); + let alphaComment = alphaCommentRes?.comment?.comment; + // ToDo: this does not check for JSON { error: "message" } if (!alphaComment) { throw "Missing alpha comment"; } - - let alphaReport = ( - await reportComment(alpha, alphaComment.id, randomString(10)) - ).comment_report_view.comment_report; - - let betaReport = (await listCommentReports(beta)).comment_reports[0] - .comment_report; + expect(alphaCommentRes?.comment?.comment).toBeDefined(); + + // For the sake of completeness, also confirm Gamma has the comment before later checking if reported. + // This raises an issue with replication design: gamma has only resolved the comment, it did not have anyone subscribe and join that community. + // Or is that automatically done by beforeAll function? + // Should this test be using nore normal getComments instead of resolveComment? + let gammaCommentRes = await resolveComment(alpha, commentRes); + // ToDo: this does not check for JSON { error: "message" } + expect(gammaCommentRes?.comment?.comment).toBeDefined(); + + // Alpha will report the comment (reminder that the comment was made on beta, so this is a remote action). + let alphaReportRes = await reportComment(alpha, alphaComment.id, randomString(10)); + // ToDo: this does not check for JSON { error: "message" } + expect(alphaReportRes?.comment_report_view?.comment_report).toBeDefined(); + let alphaReport = alphaReportRes.comment_report_view.comment_report; + + let betaReports = await listCommentReports(beta); + expect(betaReports?.comment_reports?.length).toBe(1); + let betaReport = betaReports.comment_reports[0].comment_report; expect(betaReport).toBeDefined(); expect(betaReport.resolved).toBe(false); expect(betaReport.original_comment_text).toBe( alphaReport.original_comment_text, ); expect(betaReport.reason).toBe(alphaReport.reason); + + // This is testing replication from remote-home-remote(s) (alpha-beta-gamma) + // The sitaution could be that a remote moderator is on Gamma and needs to see the report in doing their moderator duty. + let gammaReports = await listCommentReports(gamma); + expect(gammaReports?.comment_reports?.length).toBe(1); + let gammaReport = gammaReports.comment_reports[0].comment_report; + expect(gammaReport).toBeDefined(); + expect(gammaReport.resolved).toBe(false); + expect(gammaReport.original_comment_text).toBe( + alphaReport.original_comment_text, + ); + expect(gammaReport.reason).toBe(alphaReport.reason); });