Files
minecraft-account-manager/apps/web/src/lib/game-admission-policy.test.ts
T
dmg c131465ff5
CI / validate (push) Successful in 6m15s
Release / release (push) Successful in 7m49s
feat(admission): add scheduled group access
2026-08-02 14:04:48 -04:00

62 lines
2.1 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 { DEFAULT_ADMISSION_MESSAGES } from "./admission-settings";
import { evaluateRegisteredPlayerAdmission } from "./game-admission-policy";
const group = {
name: "Friday friends",
accessEnabled: true,
anonymizedNetworksAllowed: false,
};
const fridayWindow = { startMinuteOfWeek: 6960, endMinuteOfWeek: 7200 };
describe("registered player admission policy", () => {
it("lets disabled Minecraft access override an active schedule", () => {
const decision = evaluateRegisteredPlayerAdmission({
group: { ...group, accessEnabled: false },
windows: [fridayWindow],
classification: "clear",
now: new Date("2026-08-07T21:00:00Z"),
player: "AlexMC",
messages: DEFAULT_ADMISSION_MESSAGES,
});
expect(decision.reason).toBe("group_access_disabled");
});
it("denies an enabled group outside its schedule with the next UTC window", () => {
const decision = evaluateRegisteredPlayerAdmission({
group,
windows: [fridayWindow],
classification: "vpn",
now: new Date("2026-08-08T01:00:00Z"),
player: "AlexMC",
messages: {
...DEFAULT_ADMISSION_MESSAGES,
scheduledAccessDeniedMessage: "{player} in {group}: {next_start}{next_end}.",
},
});
expect(decision.reason).toBe("schedule_disallowed");
expect(decision.message).toBe("AlexMC in Friday friends: 2026-08-14 20:00 UTC2026-08-15 00:00 UTC.");
});
it("applies network policy only after group access and schedule pass", () => {
const denied = evaluateRegisteredPlayerAdmission({
group,
windows: [fridayWindow],
classification: "vpn",
now: new Date("2026-08-07T21:00:00Z"),
player: "AlexMC",
messages: DEFAULT_ADMISSION_MESSAGES,
});
expect(denied.reason).toBe("anonymized_network_disallowed");
expect(evaluateRegisteredPlayerAdmission({
group: { ...group, anonymizedNetworksAllowed: true },
windows: [fridayWindow],
classification: "vpn",
now: new Date("2026-08-07T21:00:00Z"),
player: "AlexMC",
messages: DEFAULT_ADMISSION_MESSAGES,
}).allowed).toBe(true);
});
});