Files
2026-07-13 13:39:12 +08:00

34 lines
1.1 KiB
TypeScript

import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { validateScoreChange, getAnomalies } from "../../../src/lib/gamification/antiCheat";
describe("Anti-Cheat", () => {
describe("validateScoreChange", () => {
it("allows normal score changes", async () => {
const result = await validateScoreChange("test-user", "request", 1);
assert.equal(result.allowed, true);
});
it("rejects excessive XP", async () => {
const result = await validateScoreChange("test-user", "request", 999999);
assert.equal(result.allowed, false);
assert.ok(result.reason);
});
});
describe("getAnomalies", () => {
it("returns array", async () => {
const anomalies = await getAnomalies();
assert.ok(Array.isArray(anomalies));
});
it("returns entries with numeric zScore (not hardcoded 0)", async () => {
const anomalies = await getAnomalies();
for (const a of anomalies) {
assert.equal(typeof a.zScore, "number");
assert.ok(!Number.isNaN(a.zScore));
}
});
});
});