import { describe, expect, it } from "vitest"; import { gameAdmissionDenialReason, isGameNetworkAllowed, resolveEffectiveGroup } from "../src/index"; describe("group-based admission", () => { const everyone = { name: "everyone", accessEnabled: false }; it("uses the default group only when a user has no explicit assignment", () => { expect(resolveEffectiveGroup(null, everyone)).toEqual(everyone); expect(resolveEffectiveGroup({ name: "limited", accessEnabled: true }, everyone)).toEqual({ name: "limited", accessEnabled: true, }); }); it("does not combine default and explicitly assigned group access", () => { const enabledDefault = { name: "everyone", accessEnabled: true }; const limited = { name: "limited", accessEnabled: false }; expect(resolveEffectiveGroup(limited, enabledDefault)?.accessEnabled).toBe(false); }); it("denies confirmed anonymized game networks unless the effective group allows them", () => { for (const classification of ["vpn", "proxy", "tor"] as const) { expect(isGameNetworkAllowed(classification, false)).toBe(false); expect(isGameNetworkAllowed(classification, true)).toBe(true); } }); it("does not apply the group exception policy to clear, hosting, or unavailable intelligence", () => { for (const classification of ["clear", "hosting", "unknown"] as const) { expect(isGameNetworkAllowed(classification, false)).toBe(true); } }); it("prioritizes disabled group access, then schedule, then network policy", () => { expect(gameAdmissionDenialReason({ accessEnabled: false, anonymizedNetworksAllowed: false }, "vpn", false)) .toBe("group_access_disabled"); expect(gameAdmissionDenialReason({ accessEnabled: true, anonymizedNetworksAllowed: false }, "vpn", false)) .toBe("schedule_disallowed"); expect(gameAdmissionDenialReason({ accessEnabled: true, anonymizedNetworksAllowed: false }, "vpn", true)) .toBe("anonymized_network_disallowed"); expect(gameAdmissionDenialReason({ accessEnabled: true, anonymizedNetworksAllowed: true }, "vpn", true)) .toBeNull(); }); });