-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathadmin-reports.service.test.js
More file actions
76 lines (66 loc) Β· 2.52 KB
/
Copy pathadmin-reports.service.test.js
File metadata and controls
76 lines (66 loc) Β· 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { describe, it, expect, vi } from "vitest";
vi.mock("@/lib/admin/audit", () => ({
AUDIT_ACTIONS: { REPORT_DISMISSED: "moderation.report_dismissed" },
logAuditEvent: vi.fn(),
}));
import {
DISMISSAL_REASONS,
dismissReport,
getDefaultNotificationPreference,
isFirstTimeReporter,
listReports,
} from "@/lib/actions/admin-reports";
describe("admin reports service", () => {
it("exposes all supported dismissal reasons", () => {
expect(DISMISSAL_REASONS.map(({ value }) => value)).toEqual([
"does-not-violate-policy",
"already-handled",
"insufficient-evidence",
"duplicate",
]);
});
it("identifies first-time reporters and applies smart defaults", () => {
expect(isFirstTimeReporter({ priorReportCount: 0 })).toBe(true);
expect(isFirstTimeReporter({ priorReportCount: 3 })).toBe(false);
expect(getDefaultNotificationPreference({ priorReportCount: 0 })).toBe(true);
expect(getDefaultNotificationPreference({ priorReportCount: 1 })).toBe(false);
});
it("decorates listed reports with their notification default", async () => {
const { reports } = await listReports();
expect(reports.find((report) => report.id === "R-5521").notifyReporterByDefault).toBe(true);
expect(reports.find((report) => report.id === "R-5490").notifyReporterByDefault).toBe(false);
});
it("dismisses a report without queuing a notification when disabled", async () => {
const { report, notification } = await dismissReport({
reportId: "R-5521",
reason: "insufficient-evidence",
notifyReporter: false,
});
expect(report.status).toBe("dismissed");
expect(report.dismissalReason).toBe("insufficient-evidence");
expect(report.notifyReporter).toBe(false);
expect(notification).toBeNull();
});
it("returns the courtesy notification stub when enabled", async () => {
const { report, notification } = await dismissReport({
reportId: "R-5490",
reason: "duplicate",
notifyReporter: true,
});
expect(report.notifyReporter).toBe(true);
expect(notification).toMatchObject({
status: "stubbed",
queued: false,
reportId: "R-5490",
template: "report-reviewed",
});
});
it("rejects missing or unsupported dismissal reasons", async () => {
await expect(dismissReport({ reportId: "R-5521" })).rejects.toThrow(
"Choose a valid dismissal reason"
);
await expect(
dismissReport({ reportId: "R-5521", reason: "not-a-reason" })
).rejects.toThrow("Choose a valid dismissal reason");
});
});