Skip to content

Commit

Permalink
Merge branch 'main' into API-endpoint-for-listing-read-posts-LemmyNet…
Browse files Browse the repository at this point in the history
  • Loading branch information
leoseg authored Dec 20, 2024
2 parents 11f58b6 + 9d3a0ce commit 1f0cd0a
Show file tree
Hide file tree
Showing 55 changed files with 1,509 additions and 1,411 deletions.
2 changes: 1 addition & 1 deletion api_tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"eslint": "^9.14.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.5.0",
"lemmy-js-client": "0.20.0-api-v4.16",
"lemmy-js-client": "0.20.0-reports-combined.3",
"prettier": "^3.2.5",
"ts-jest": "^29.1.0",
"typescript": "^5.5.4",
Expand Down
10 changes: 5 additions & 5 deletions api_tests/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 28 additions & 9 deletions api_tests/src/comment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
createCommunity,
registerUser,
reportComment,
listCommentReports,
randomString,
unfollows,
getComments,
Expand All @@ -38,8 +37,15 @@ import {
blockCommunity,
delay,
saveUserSettings,
listReports,
} from "./shared";
import { CommentView, CommunityView, SaveUserSettings } from "lemmy-js-client";
import {
CommentReportView,
CommentView,
CommunityView,
ReportCombinedView,
SaveUserSettings,
} from "lemmy-js-client";

let betaCommunity: CommunityView | undefined;
let postOnAlphaRes: PostResponse;
Expand Down Expand Up @@ -796,13 +802,17 @@ 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 => {
return checkCommentReportReason(r, reason);
}),
),
e => !!e,
)!) as CommentReportView
).comment_report;
expect(betaReport).toBeDefined();
expect(betaReport.resolved).toBe(false);
expect(betaReport.original_comment_text).toBe(
Expand Down Expand Up @@ -877,3 +887,12 @@ test.skip("Fetch a deeply nested comment", async () => {
expect(betaComment!.comment!.comment).toBeDefined();
expect(betaComment?.comment?.post).toBeDefined();
});

function checkCommentReportReason(rcv: ReportCombinedView, reason: string) {
switch (rcv.type_) {
case "Comment":
return rcv.comment_report.reason === reason;
default:
return false;
}
}
5 changes: 2 additions & 3 deletions api_tests/src/community.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
followCommunity,
banPersonFromCommunity,
resolvePerson,
getSite,
createPost,
getPost,
resolvePost,
Expand All @@ -36,7 +35,7 @@ import {
userBlockInstance,
} from "./shared";
import { AdminAllowInstanceParams } from "lemmy-js-client/dist/types/AdminAllowInstanceParams";
import { EditCommunity, EditSite, GetPosts } from "lemmy-js-client";
import { EditCommunity, GetPosts } from "lemmy-js-client";

beforeAll(setupLogins);
afterAll(unfollows);
Expand Down Expand Up @@ -573,7 +572,7 @@ test("Remote mods can edit communities", async () => {
communityRes.community_view.community.id,
);

await expect(alphaCommunity.community_view.community.description).toBe(
expect(alphaCommunity.community_view.community.description).toBe(
"Example description",
);
});
Expand Down
1 change: 0 additions & 1 deletion api_tests/src/follow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
setupLogins,
resolveBetaCommunity,
followCommunity,
getSite,
waitUntil,
beta,
betaUrl,
Expand Down
1 change: 0 additions & 1 deletion api_tests/src/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
epsilon,
followCommunity,
gamma,
getSite,
imageFetchLimit,
registerUser,
resolveBetaCommunity,
Expand Down
58 changes: 37 additions & 21 deletions api_tests/src/post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,27 @@ import {
followCommunity,
banPersonFromCommunity,
reportPost,
listPostReports,
randomString,
registerUser,
getSite,
unfollows,
resolveCommunity,
waitUntil,
waitForPost,
alphaUrl,
loginUser,
createCommunity,
listReports,
getMyUser,
} 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,
PostReport,
PostReportView,
ReportCombinedView,
ResolveObject,
} from "lemmy-js-client";

let betaCommunity: CommunityView | undefined;

Expand Down Expand Up @@ -688,16 +693,17 @@ 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 => {
return checkPostReportName(r, gammaReport);
}),
),
),
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);
Expand All @@ -707,16 +713,17 @@ 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 => {
return checkPostReportName(r, gammaReport);
}),
),
),
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);
Expand Down Expand Up @@ -817,3 +824,12 @@ test("Rewrite markdown links", async () => {
`[link](http://lemmy-alpha:8541/post/${alphaPost1.post?.post.id})`,
);
});

function checkPostReportName(rcv: ReportCombinedView, report: PostReport) {
switch (rcv.type_) {
case "Post":
return rcv.post_report.original_post_name === report.original_post_name;
default:
return false;
}
}
26 changes: 9 additions & 17 deletions api_tests/src/shared.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
AdminBlockInstanceParams,
ApproveCommunityPendingFollower,
BlockCommunity,
BlockCommunityResponse,
Expand All @@ -16,6 +15,8 @@ import {
LemmyHttp,
ListCommunityPendingFollows,
ListCommunityPendingFollowsResponse,
ListReports,
ListReportsResponse,
MyUserInfo,
PersonId,
PostView,
Expand Down Expand Up @@ -75,12 +76,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";
Expand Down Expand Up @@ -210,7 +207,9 @@ async function allowInstance(api: LemmyHttp, instance: string) {
// Ignore errors from duplicate allows (because setup gets called for each test file)
try {
await api.adminAllowInstance(params);
} catch {}
} catch (error) {
// console.error(error);
}
}

export async function createPost(
Expand Down Expand Up @@ -809,11 +808,11 @@ export async function reportPost(
return api.createPostReport(form);
}

export async function listPostReports(
export async function listReports(
api: LemmyHttp,
): Promise<ListPostReportsResponse> {
let form: ListPostReports = {};
return api.listPostReports(form);
): Promise<ListReportsResponse> {
let form: ListReports = {};
return api.listReports(form);
}

export async function reportComment(
Expand All @@ -840,13 +839,6 @@ export async function reportPrivateMessage(
return api.createPrivateMessageReport(form);
}

export async function listCommentReports(
api: LemmyHttp,
): Promise<ListCommentReportsResponse> {
let form: ListCommentReports = {};
return api.listCommentReports(form);
}

export function getPosts(
api: LemmyHttp,
listingType?: ListingType,
Expand Down
37 changes: 0 additions & 37 deletions crates/api/src/comment_report/list.rs

This file was deleted.

4 changes: 1 addition & 3 deletions crates/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ use std::io::Cursor;
use totp_rs::{Secret, TOTP};

pub mod comment;
pub mod comment_report;
pub mod community;
pub mod local_user;
pub mod post;
pub mod post_report;
pub mod private_message;
pub mod private_message_report;
pub mod reports;
pub mod site;
pub mod sitemap;

Expand Down
Loading

0 comments on commit 1f0cd0a

Please sign in to comment.