Fixing api tests.

This commit is contained in:
Dessalines 2024-12-02 18:23:12 -05:00
parent 83988cd9bf
commit 82a14fc5fa
5 changed files with 73 additions and 51 deletions

View file

@ -28,7 +28,7 @@
"eslint": "^9.14.0", "eslint": "^9.14.0",
"eslint-plugin-prettier": "^5.1.3", "eslint-plugin-prettier": "^5.1.3",
"jest": "^29.5.0", "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", "prettier": "^3.2.5",
"ts-jest": "^29.1.0", "ts-jest": "^29.1.0",
"typescript": "^5.5.4", "typescript": "^5.5.4",

View file

@ -30,8 +30,8 @@ importers:
specifier: ^29.5.0 specifier: ^29.5.0
version: 29.7.0(@types/node@22.9.0) version: 29.7.0(@types/node@22.9.0)
lemmy-js-client: lemmy-js-client:
specifier: 0.20.0-instance-blocks.5 specifier: 0.20.0-reports-combined.2
version: 0.20.0-instance-blocks.5 version: 0.20.0-reports-combined.2
prettier: prettier:
specifier: ^3.2.5 specifier: ^3.2.5
version: 3.3.3 version: 3.3.3
@ -1167,8 +1167,8 @@ packages:
resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==}
engines: {node: '>=6'} engines: {node: '>=6'}
lemmy-js-client@0.20.0-instance-blocks.5: lemmy-js-client@0.20.0-reports-combined.2:
resolution: {integrity: sha512-wDuRFzg32lbbJr4cNmd+cbzjgw+okw2/d5AujYjAm4gv0OEFfsYhP3QQ2WscwUR5HJTdzsR7IIyiBnvmaEUzUw==} resolution: {integrity: sha512-ZquK08ggeHhFVHMxz42vZvZ3/UgPHYcvMT3MaNevqCJFMFgiXg0+1HWUctVAaZrj8ooiRTiVqupelEhq6LKKTQ==}
leven@3.1.0: leven@3.1.0:
resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==}
@ -3077,7 +3077,7 @@ snapshots:
kleur@3.0.3: {} 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: {} leven@3.1.0: {}

View file

@ -22,7 +22,6 @@ import {
createCommunity, createCommunity,
registerUser, registerUser,
reportComment, reportComment,
listCommentReports,
randomString, randomString,
unfollows, unfollows,
getComments, getComments,
@ -38,8 +37,14 @@ import {
blockCommunity, blockCommunity,
delay, delay,
saveUserSettings, saveUserSettings,
listReports,
} from "./shared"; } from "./shared";
import { CommentView, CommunityView, SaveUserSettings } from "lemmy-js-client"; import {
CommentReportView,
CommentView,
CommunityView,
SaveUserSettings,
} from "lemmy-js-client";
let betaCommunity: CommunityView | undefined; let betaCommunity: CommunityView | undefined;
let postOnAlphaRes: PostResponse; let postOnAlphaRes: PostResponse;
@ -796,13 +801,22 @@ test("Report a comment", async () => {
let alphaReport = (await reportComment(alpha, alphaComment.id, reason)) let alphaReport = (await reportComment(alpha, alphaComment.id, reason))
.comment_report_view.comment_report; .comment_report_view.comment_report;
let betaReport = (await waitUntil( let betaReport = (
(await waitUntil(
() => () =>
listCommentReports(beta).then(r => listReports(beta).then(p =>
r.comment_reports.find(rep => rep.comment_report.reason === reason), p.reports.find(r => {
switch (r.type_) {
case "Comment":
return r.comment_report.reason === reason;
default:
return false;
}
}),
), ),
e => !!e, e => !!e,
))!.comment_report; )!) as CommentReportView
).comment_report;
expect(betaReport).toBeDefined(); expect(betaReport).toBeDefined();
expect(betaReport.resolved).toBe(false); expect(betaReport.resolved).toBe(false);
expect(betaReport.original_comment_text).toBe( expect(betaReport.original_comment_text).toBe(

View file

@ -27,7 +27,6 @@ import {
followCommunity, followCommunity,
banPersonFromCommunity, banPersonFromCommunity,
reportPost, reportPost,
listPostReports,
randomString, randomString,
registerUser, registerUser,
getSite, getSite,
@ -38,10 +37,11 @@ import {
alphaUrl, alphaUrl,
loginUser, loginUser,
createCommunity, createCommunity,
listReports,
} from "./shared"; } from "./shared";
import { PostView } from "lemmy-js-client/dist/types/PostView"; import { PostView } from "lemmy-js-client/dist/types/PostView";
import { AdminBlockInstanceParams } from "lemmy-js-client/dist/types/AdminBlockInstanceParams"; 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; let betaCommunity: CommunityView | undefined;
@ -690,16 +690,25 @@ test("Report a post", async () => {
expect(gammaReport).toBeDefined(); expect(gammaReport).toBeDefined();
// Report was federated to community instance // Report was federated to community instance
let betaReport = (await waitUntil( let betaReport = (
(await waitUntil(
() => () =>
listPostReports(beta).then(p => listReports(beta).then(p =>
p.post_reports.find( p.reports.find(r => {
r => switch (r.type_) {
r.post_report.original_post_name === gammaReport.original_post_name, case "Post":
), return (
r.post_report.original_post_name ===
gammaReport.original_post_name
);
default:
return false;
}
}),
), ),
res => !!res, res => !!res,
))!.post_report; ))! as PostReportView
).post_report;
expect(betaReport).toBeDefined(); expect(betaReport).toBeDefined();
expect(betaReport.resolved).toBe(false); expect(betaReport.resolved).toBe(false);
expect(betaReport.original_post_name).toBe(gammaReport.original_post_name); expect(betaReport.original_post_name).toBe(gammaReport.original_post_name);
@ -709,16 +718,25 @@ test("Report a post", async () => {
await unfollowRemotes(alpha); await unfollowRemotes(alpha);
// Report was federated to poster's instance // Report was federated to poster's instance
let alphaReport = (await waitUntil( let alphaReport = (
(await waitUntil(
() => () =>
listPostReports(alpha).then(p => listReports(alpha).then(p =>
p.post_reports.find( p.reports.find(r => {
r => switch (r.type_) {
r.post_report.original_post_name === gammaReport.original_post_name, case "Post":
), return (
r.post_report.original_post_name ===
gammaReport.original_post_name
);
default:
return false;
}
}),
), ),
res => !!res, res => !!res,
))!.post_report; ))! as PostReportView
).post_report;
expect(alphaReport).toBeDefined(); expect(alphaReport).toBeDefined();
expect(alphaReport.resolved).toBe(false); expect(alphaReport.resolved).toBe(false);
expect(alphaReport.original_post_name).toBe(gammaReport.original_post_name); expect(alphaReport.original_post_name).toBe(gammaReport.original_post_name);

View file

@ -1,5 +1,4 @@
import { import {
AdminBlockInstanceParams,
ApproveCommunityPendingFollower, ApproveCommunityPendingFollower,
BlockCommunity, BlockCommunity,
BlockCommunityResponse, BlockCommunityResponse,
@ -16,6 +15,8 @@ import {
LemmyHttp, LemmyHttp,
ListCommunityPendingFollows, ListCommunityPendingFollows,
ListCommunityPendingFollowsResponse, ListCommunityPendingFollowsResponse,
ListReports,
ListReportsResponse,
PersonId, PersonId,
PostView, PostView,
PrivateMessageReportResponse, PrivateMessageReportResponse,
@ -74,12 +75,8 @@ import { PrivateMessagesResponse } from "lemmy-js-client/dist/types/PrivateMessa
import { GetPrivateMessages } from "lemmy-js-client/dist/types/GetPrivateMessages"; import { GetPrivateMessages } from "lemmy-js-client/dist/types/GetPrivateMessages";
import { PostReportResponse } from "lemmy-js-client/dist/types/PostReportResponse"; import { PostReportResponse } from "lemmy-js-client/dist/types/PostReportResponse";
import { CreatePostReport } from "lemmy-js-client/dist/types/CreatePostReport"; 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 { CommentReportResponse } from "lemmy-js-client/dist/types/CommentReportResponse";
import { CreateCommentReport } from "lemmy-js-client/dist/types/CreateCommentReport"; 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 { GetPostsResponse } from "lemmy-js-client/dist/types/GetPostsResponse";
import { GetPosts } from "lemmy-js-client/dist/types/GetPosts"; import { GetPosts } from "lemmy-js-client/dist/types/GetPosts";
import { GetPersonDetailsResponse } from "lemmy-js-client/dist/types/GetPersonDetailsResponse"; import { GetPersonDetailsResponse } from "lemmy-js-client/dist/types/GetPersonDetailsResponse";
@ -807,11 +804,11 @@ export async function reportPost(
return api.createPostReport(form); return api.createPostReport(form);
} }
export async function listPostReports( export async function listReports(
api: LemmyHttp, api: LemmyHttp,
): Promise<ListPostReportsResponse> { ): Promise<ListReportsResponse> {
let form: ListPostReports = {}; let form: ListReports = {};
return api.listPostReports(form); return api.listReports(form);
} }
export async function reportComment( export async function reportComment(
@ -838,13 +835,6 @@ export async function reportPrivateMessage(
return api.createPrivateMessageReport(form); return api.createPrivateMessageReport(form);
} }
export async function listCommentReports(
api: LemmyHttp,
): Promise<ListCommentReportsResponse> {
let form: ListCommentReports = {};
return api.listCommentReports(form);
}
export function getPosts( export function getPosts(
api: LemmyHttp, api: LemmyHttp,
listingType?: ListingType, listingType?: ListingType,