From 82a14fc5fa8c6fbc19450775075a61b101d920f4 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 2 Dec 2024 18:23:12 -0500 Subject: [PATCH] Fixing api tests. --- api_tests/package.json | 2 +- api_tests/pnpm-lock.yaml | 10 +++--- api_tests/src/comment.spec.ts | 32 +++++++++++++------ api_tests/src/post.spec.ts | 58 +++++++++++++++++++++++------------ api_tests/src/shared.ts | 22 ++++--------- 5 files changed, 73 insertions(+), 51 deletions(-) diff --git a/api_tests/package.json b/api_tests/package.json index ef47bf192..7eb7f0593 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -28,7 +28,7 @@ "eslint": "^9.14.0", "eslint-plugin-prettier": "^5.1.3", "jest": "^29.5.0", - "lemmy-js-client": "0.20.0-instance-blocks.5", + "lemmy-js-client": "0.20.0-reports-combined.2", "prettier": "^3.2.5", "ts-jest": "^29.1.0", "typescript": "^5.5.4", diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index a95e80726..91efa2716 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^29.5.0 version: 29.7.0(@types/node@22.9.0) lemmy-js-client: - specifier: 0.20.0-instance-blocks.5 - version: 0.20.0-instance-blocks.5 + specifier: 0.20.0-reports-combined.2 + version: 0.20.0-reports-combined.2 prettier: specifier: ^3.2.5 version: 3.3.3 @@ -1167,8 +1167,8 @@ packages: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} - lemmy-js-client@0.20.0-instance-blocks.5: - resolution: {integrity: sha512-wDuRFzg32lbbJr4cNmd+cbzjgw+okw2/d5AujYjAm4gv0OEFfsYhP3QQ2WscwUR5HJTdzsR7IIyiBnvmaEUzUw==} + lemmy-js-client@0.20.0-reports-combined.2: + resolution: {integrity: sha512-ZquK08ggeHhFVHMxz42vZvZ3/UgPHYcvMT3MaNevqCJFMFgiXg0+1HWUctVAaZrj8ooiRTiVqupelEhq6LKKTQ==} leven@3.1.0: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} @@ -3077,7 +3077,7 @@ snapshots: kleur@3.0.3: {} - lemmy-js-client@0.20.0-instance-blocks.5: {} + lemmy-js-client@0.20.0-reports-combined.2: {} leven@3.1.0: {} diff --git a/api_tests/src/comment.spec.ts b/api_tests/src/comment.spec.ts index edc588db7..94404f449 100644 --- a/api_tests/src/comment.spec.ts +++ b/api_tests/src/comment.spec.ts @@ -22,7 +22,6 @@ import { createCommunity, registerUser, reportComment, - listCommentReports, randomString, unfollows, getComments, @@ -38,8 +37,14 @@ import { blockCommunity, delay, saveUserSettings, + listReports, } from "./shared"; -import { CommentView, CommunityView, SaveUserSettings } from "lemmy-js-client"; +import { + CommentReportView, + CommentView, + CommunityView, + SaveUserSettings, +} from "lemmy-js-client"; let betaCommunity: CommunityView | undefined; let postOnAlphaRes: PostResponse; @@ -796,13 +801,22 @@ test("Report a comment", async () => { let alphaReport = (await reportComment(alpha, alphaComment.id, reason)) .comment_report_view.comment_report; - let betaReport = (await waitUntil( - () => - listCommentReports(beta).then(r => - r.comment_reports.find(rep => rep.comment_report.reason === reason), - ), - e => !!e, - ))!.comment_report; + let betaReport = ( + (await waitUntil( + () => + listReports(beta).then(p => + p.reports.find(r => { + switch (r.type_) { + case "Comment": + return r.comment_report.reason === reason; + default: + return false; + } + }), + ), + e => !!e, + )!) as CommentReportView + ).comment_report; expect(betaReport).toBeDefined(); expect(betaReport.resolved).toBe(false); expect(betaReport.original_comment_text).toBe( diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index a6063e0a2..7dd7dd483 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -27,7 +27,6 @@ import { followCommunity, banPersonFromCommunity, reportPost, - listPostReports, randomString, registerUser, getSite, @@ -38,10 +37,11 @@ import { alphaUrl, loginUser, createCommunity, + listReports, } from "./shared"; import { PostView } from "lemmy-js-client/dist/types/PostView"; import { AdminBlockInstanceParams } from "lemmy-js-client/dist/types/AdminBlockInstanceParams"; -import { EditSite, ResolveObject } from "lemmy-js-client"; +import { EditSite, PostReportView, ResolveObject } from "lemmy-js-client"; let betaCommunity: CommunityView | undefined; @@ -690,16 +690,25 @@ test("Report a post", async () => { expect(gammaReport).toBeDefined(); // Report was federated to community instance - let betaReport = (await waitUntil( - () => - listPostReports(beta).then(p => - p.post_reports.find( - r => - r.post_report.original_post_name === gammaReport.original_post_name, + let betaReport = ( + (await waitUntil( + () => + listReports(beta).then(p => + p.reports.find(r => { + switch (r.type_) { + case "Post": + return ( + r.post_report.original_post_name === + gammaReport.original_post_name + ); + default: + return false; + } + }), ), - ), - res => !!res, - ))!.post_report; + res => !!res, + ))! as PostReportView + ).post_report; expect(betaReport).toBeDefined(); expect(betaReport.resolved).toBe(false); expect(betaReport.original_post_name).toBe(gammaReport.original_post_name); @@ -709,16 +718,25 @@ test("Report a post", async () => { await unfollowRemotes(alpha); // Report was federated to poster's instance - let alphaReport = (await waitUntil( - () => - listPostReports(alpha).then(p => - p.post_reports.find( - r => - r.post_report.original_post_name === gammaReport.original_post_name, + let alphaReport = ( + (await waitUntil( + () => + listReports(alpha).then(p => + p.reports.find(r => { + switch (r.type_) { + case "Post": + return ( + r.post_report.original_post_name === + gammaReport.original_post_name + ); + default: + return false; + } + }), ), - ), - res => !!res, - ))!.post_report; + res => !!res, + ))! as PostReportView + ).post_report; expect(alphaReport).toBeDefined(); expect(alphaReport.resolved).toBe(false); expect(alphaReport.original_post_name).toBe(gammaReport.original_post_name); diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index 9b0662959..a46fd104a 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -1,5 +1,4 @@ import { - AdminBlockInstanceParams, ApproveCommunityPendingFollower, BlockCommunity, BlockCommunityResponse, @@ -16,6 +15,8 @@ import { LemmyHttp, ListCommunityPendingFollows, ListCommunityPendingFollowsResponse, + ListReports, + ListReportsResponse, PersonId, PostView, PrivateMessageReportResponse, @@ -74,12 +75,8 @@ import { PrivateMessagesResponse } from "lemmy-js-client/dist/types/PrivateMessa import { GetPrivateMessages } from "lemmy-js-client/dist/types/GetPrivateMessages"; import { PostReportResponse } from "lemmy-js-client/dist/types/PostReportResponse"; import { CreatePostReport } from "lemmy-js-client/dist/types/CreatePostReport"; -import { ListPostReportsResponse } from "lemmy-js-client/dist/types/ListPostReportsResponse"; -import { ListPostReports } from "lemmy-js-client/dist/types/ListPostReports"; import { CommentReportResponse } from "lemmy-js-client/dist/types/CommentReportResponse"; 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"; import { GetPersonDetailsResponse } from "lemmy-js-client/dist/types/GetPersonDetailsResponse"; @@ -807,11 +804,11 @@ export async function reportPost( return api.createPostReport(form); } -export async function listPostReports( +export async function listReports( api: LemmyHttp, -): Promise { - let form: ListPostReports = {}; - return api.listPostReports(form); +): Promise { + let form: ListReports = {}; + return api.listReports(form); } export async function reportComment( @@ -838,13 +835,6 @@ export async function reportPrivateMessage( return api.createPrivateMessageReport(form); } -export async function listCommentReports( - api: LemmyHttp, -): Promise { - let form: ListCommentReports = {}; - return api.listCommentReports(form); -} - export function getPosts( api: LemmyHttp, listingType?: ListingType,