62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
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 UTC–2026-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);
|
||
});
|
||
});
|