mirror of https://github.com/LemmyNet/lemmy.git
add federation test cases for reports
parent
9a7b1e7d2c
commit
c05ff2af92
|
@ -16,7 +16,7 @@
|
|||
"eslint": "^7.30.0",
|
||||
"eslint-plugin-jane": "^9.0.3",
|
||||
"jest": "^27.0.6",
|
||||
"lemmy-js-client": "0.12.0",
|
||||
"lemmy-js-client": "0.13.1-rc.1",
|
||||
"node-fetch": "^2.6.1",
|
||||
"prettier": "^2.3.2",
|
||||
"ts-jest": "^27.0.3",
|
||||
|
|
|
@ -19,6 +19,9 @@ import {
|
|||
unfollowRemotes,
|
||||
createCommunity,
|
||||
registerUser,
|
||||
reportComment,
|
||||
listCommentReports,
|
||||
randomString,
|
||||
API,
|
||||
} from './shared';
|
||||
import { CommentView } from 'lemmy-js-client';
|
||||
|
@ -382,3 +385,23 @@ test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde
|
|||
|
||||
await unfollowRemotes(alpha);
|
||||
});
|
||||
|
||||
|
||||
test('Report a comment', async () => {
|
||||
let betaCommunity = (await resolveBetaCommunity(beta)).community;
|
||||
console.log(betaCommunity);
|
||||
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;
|
||||
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(betaReport).toBeDefined();
|
||||
expect(betaReport.resolved).toBe(false);
|
||||
expect(betaReport.original_comment_text).toBe(alphaReport.original_comment_text);
|
||||
expect(betaReport.reason).toBe(alphaReport.reason);
|
||||
});
|
|
@ -24,6 +24,9 @@ import {
|
|||
searchPostLocal,
|
||||
followCommunity,
|
||||
banPersonFromCommunity,
|
||||
reportPost,
|
||||
listPostReports,
|
||||
randomString,
|
||||
} from './shared';
|
||||
import { PostView, CommunityView } from 'lemmy-js-client';
|
||||
|
||||
|
@ -352,3 +355,22 @@ test('Enforce community ban for federated user', async () => {
|
|||
let betaPost = searchBeta.posts[0];
|
||||
expect(betaPost).toBeDefined();
|
||||
});
|
||||
|
||||
test('Report a post', async () => {
|
||||
let betaCommunity = (await resolveBetaCommunity(beta)).community;
|
||||
console.log(betaCommunity);
|
||||
let postRes = await createPost(beta, betaCommunity.community.id);
|
||||
expect(postRes.post_view.post).toBeDefined();
|
||||
|
||||
let alphaPost = (await resolvePost(alpha, postRes.post_view.post)).post;
|
||||
let alphaReport = (await reportPost(alpha, alphaPost.post.id, randomString(10)))
|
||||
.post_report_view.post_report;
|
||||
|
||||
let betaReport = (await listPostReports(beta)).post_reports[0].post_report;
|
||||
expect(betaReport).toBeDefined();
|
||||
expect(betaReport.resolved).toBe(false);
|
||||
expect(betaReport.original_post_name).toBe(alphaReport.original_post_name);
|
||||
expect(betaReport.original_post_url).toBe(alphaReport.original_post_url);
|
||||
expect(betaReport.original_post_body).toBe(alphaReport.original_post_body);
|
||||
expect(betaReport.reason).toBe(alphaReport.reason);
|
||||
});
|
|
@ -49,6 +49,15 @@ import {
|
|||
CreatePrivateMessage,
|
||||
ResolveObjectResponse,
|
||||
ResolveObject,
|
||||
CreatePostReport,
|
||||
PostReport,
|
||||
ListPostReports,
|
||||
PostReportResponse,
|
||||
ListPostReportsResponse,
|
||||
CreateCommentReport,
|
||||
CommentReportResponse,
|
||||
ListCommentReports,
|
||||
ListCommentReportsResponse,
|
||||
} from 'lemmy-js-client';
|
||||
|
||||
export interface API {
|
||||
|
@ -586,6 +595,46 @@ export async function followBeta(api: API): Promise<CommunityResponse> {
|
|||
}
|
||||
}
|
||||
|
||||
export async function reportPost(
|
||||
api: API,
|
||||
post_id: number,
|
||||
reason: string,
|
||||
): Promise<PostReportResponse> {
|
||||
let form: CreatePostReport = {
|
||||
post_id,
|
||||
reason,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.createPostReport(form);
|
||||
}
|
||||
|
||||
export async function listPostReports(api: API): Promise<ListPostReportsResponse> {
|
||||
let form: ListPostReports = {
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.listPostReports(form);
|
||||
}
|
||||
|
||||
export async function reportComment(
|
||||
api: API,
|
||||
comment_id: number,
|
||||
reason: string,
|
||||
): Promise<CommentReportResponse> {
|
||||
let form: CreateCommentReport = {
|
||||
comment_id,
|
||||
reason,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.createCommentReport(form);
|
||||
}
|
||||
|
||||
export async function listCommentReports(api: API): Promise<ListCommentReportsResponse> {
|
||||
let form: ListCommentReports = {
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.listCommentReports(form);
|
||||
}
|
||||
|
||||
export function delay(millis: number = 500) {
|
||||
return new Promise(resolve => setTimeout(resolve, millis));
|
||||
}
|
||||
|
@ -598,7 +647,7 @@ export function wrapper(form: any): string {
|
|||
return JSON.stringify(form);
|
||||
}
|
||||
|
||||
function randomString(length: number): string {
|
||||
export function randomString(length: number): string {
|
||||
var result = '';
|
||||
var characters = 'abcdefghijklmnopqrstuvwxyz0123456789_';
|
||||
var charactersLength = characters.length;
|
||||
|
|
|
@ -3076,10 +3076,10 @@ language-tags@^1.0.5:
|
|||
dependencies:
|
||||
language-subtag-registry "~0.3.2"
|
||||
|
||||
lemmy-js-client@0.12.0:
|
||||
version "0.12.0"
|
||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.12.0.tgz#2337aca9d8b38d92908d7f7a9479f0066a9eaeae"
|
||||
integrity sha512-PSebUBkojM7OUlfSXKQhL4IcYKaKF+Xj2G0+pybaCvP9sJvviy32qHUi9BQeIhRHXgw8ILRH0Y+xZGKu0a3wvQ==
|
||||
lemmy-js-client@0.13.1-rc.1:
|
||||
version "0.13.1-rc.1"
|
||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.13.1-rc.1.tgz#e1af4749a5493954a17f87b7b20dcccb8c585f22"
|
||||
integrity sha512-fncCq6Zu8s6GpeCrkmJS8/rqXcyrJ8p8EyWfXiiuZlWkgzOIi+qZjTRnO63wI6DomYwVOjwk7sry4RbOJSdK5Q==
|
||||
|
||||
leven@^3.1.0:
|
||||
version "3.1.0"
|
||||
|
|
|
@ -114,7 +114,7 @@ impl ActivityHandler for Report {
|
|||
original_post_name: post.name,
|
||||
original_post_url: post.url,
|
||||
reason: self.summary,
|
||||
original_post_body: None,
|
||||
original_post_body: post.body,
|
||||
};
|
||||
|
||||
let report = blocking(context.pool(), move |conn| {
|
||||
|
|
Loading…
Reference in New Issue