Files
buzz-sheet/lib/comments/moderation.test.ts
T
gunshiz 20c52fac04
CI / Verify (push) Successful in 1m41s
CI / Build immutable images and deploy (push) Successful in 2m30s
feat(comments) : filter abusive language and prevent spam
2026-10-08 04:45:45 +07:00

21 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from "vitest";
import { checkCommentContent, normalizeCommentText } from "./moderation";
describe("comment content moderation", () => {
it.each(["fuck you", "F U C K", "f.u.c.k", "f\u200buck", "fuck", "sh1t", "b!tch", "ไอ้เหี้ย", "เย็ดแม่", "ควย"])("rejects abusive language: %s", (text) => {
expect(() => checkCommentContent(text)).toThrow("comment-abusive-language");
});
it.each(["", "This weapon has classic passive stats", "Scunthorpe", "The boss has an assassin phase", "ทีมนี้ใช้กล้วยได้ไหม", "ขอบคุณสำหรับไกด์ครับ", "https://example.com/guide", "https://a.test https://b.test https://c.test", "ha ha ha", "Crit rate 100%!"])("allows ordinary discussion: %s", (text) => {
expect(() => checkCommentContent(text)).not.toThrow();
});
it.each(["https://a.test https://b.test https://c.test https://d.test", "www.a.test www.b.test www.c.test www.d.test", "a".repeat(20), "🔥".repeat(20), "buy now ".repeat(8), "spam ".repeat(8)])("rejects spam: %s", (text) => {
expect(() => checkCommentContent(text)).toThrow("comment-spam");
});
it("normalizes casing, whitespace, invisible characters and compatibility forms for duplicates", () => {
expect(normalizeCommentText(" Hello\u200b\n WORLD ")).toBe("hello world");
});
it("rejects text containing only invisible characters", () => {
expect(() => checkCommentContent("\u200b\u200d")).toThrow("empty-comment");
});
});