返回 DeepSeek-Reasonix
antispam.test.ts
根目录 / workers / forum / src / antispam.test.ts
1 import { describe, expect, it } from "vitest";
2 import type { Member } from "./env";
3 import { assertCanFlag, assertCanInteract } from "./antispam";
4
5 function member(overrides: Partial<Member> = {}): Member {
6 return {
7 email: "alice@example.test",
8 handle: "alice",
9 emailVerified: true,
10 trust: 0,
11 role: "member",
12 silencedUntil: null,
13 ...overrides,
14 };
15 }
16
17 describe("community interaction gates", () => {
18 it("rejects reactions and reports from unverified identities", () => {
19 expect(() => assertCanInteract(member({ emailVerified: false }))).toThrowError(/Confirm your email/);
20 expect(() => assertCanFlag(member({ emailVerified: false }), "bob@example.test")).toThrowError(/Confirm your email/);
21 });
22
23 it("rejects self-reporting", () => {
24 expect(() => assertCanFlag(member(), "alice@example.test")).toThrowError(/own post/);
25 });
26 });
27
27 lines TYPESCRIPT