Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/modules/telephony/routes/telephonyAccess.server.test.ts
T

44 lines
1.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { CatalogError } from "@hivegrid/foundation";
import {
TELEPHONY_PERMISSIONS,
canReadAllTelephonyCalls,
requireTelephonyCallVisibility,
requireTelephonyPermission,
telephonyHasPermission,
type TelephonyRouteContext,
} from "./telephonyAccess.server";
function context(permissions: readonly string[], userId = "user-1"): TelephonyRouteContext {
return { tenantId: "tenant-1", userId, tenantUserId: `membership-${userId}`, permissions, hasModule: true };
}
describe("telephony access", () => {
it("lets manage cover every telephony capability", () => {
const ctx = context([TELEPHONY_PERMISSIONS.manage]);
expect(telephonyHasPermission(ctx, TELEPHONY_PERMISSIONS.readOwn)).toBe(true);
expect(telephonyHasPermission(ctx, TELEPHONY_PERMISSIONS.readAll)).toBe(true);
expect(telephonyHasPermission(ctx, TELEPHONY_PERMISSIONS.call)).toBe(true);
});
it("lets read_all cover read_own without granting call or manage", () => {
const ctx = context([TELEPHONY_PERMISSIONS.readAll]);
expect(telephonyHasPermission(ctx, TELEPHONY_PERMISSIONS.readOwn)).toBe(true);
expect(canReadAllTelephonyCalls(ctx)).toBe(true);
expect(telephonyHasPermission(ctx, TELEPHONY_PERMISSIONS.call)).toBe(false);
expect(telephonyHasPermission(ctx, TELEPHONY_PERMISSIONS.manage)).toBe(false);
});
it("allows an own-call reader to see only their bound calls", () => {
const ctx = context([TELEPHONY_PERMISSIONS.readOwn]);
expect(requireTelephonyCallVisibility(ctx, "membership-user-1")).toBe(ctx);
expect(() => requireTelephonyCallVisibility(ctx, "membership-user-2")).toThrow(CatalogError);
expect(() => requireTelephonyCallVisibility(ctx, null)).toThrow(CatalogError);
});
it("returns the not-found catalog error for a missing capability", () => {
expect(() => requireTelephonyPermission(context([]), TELEPHONY_PERMISSIONS.call)).toThrow(CatalogError);
});
});