38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { PortalActorAttributionError, requireExactlyOneActor, requirePortalUserActor } from "./customer-portal-actor.js";
|
|
|
|
describe("customer portal actor attribution", () => {
|
|
it("normalizes one internal actor", () => {
|
|
expect(requireExactlyOneActor({ createdByUserId: " user_1 " })).toEqual({
|
|
actorKind: "user",
|
|
actorId: "user_1",
|
|
createdByUserId: "user_1",
|
|
createdByPortalUserId: null,
|
|
});
|
|
});
|
|
|
|
it("normalizes one portal actor without a TenantUser fallback", () => {
|
|
expect(requirePortalUserActor({ createdByPortalUserId: " portal_user_1 " })).toEqual({
|
|
actorKind: "portal_user",
|
|
actorId: "portal_user_1",
|
|
createdByUserId: null,
|
|
createdByPortalUserId: "portal_user_1",
|
|
});
|
|
});
|
|
|
|
it.each([
|
|
{},
|
|
{ createdByUserId: "", createdByPortalUserId: " " },
|
|
{ createdByUserId: "user_1", createdByPortalUserId: "portal_user_1" },
|
|
])("rejects missing or ambiguous actors: %o", (input) => {
|
|
expect(() => requireExactlyOneActor(input)).toThrow(PortalActorAttributionError);
|
|
});
|
|
|
|
it("rejects an internal actor at the portal mutation boundary", () => {
|
|
expect(() => requirePortalUserActor({ createdByUserId: "synthetic-user" })).toThrowError(
|
|
expect.objectContaining({ code: "portal_actor_exactly_one_required" }),
|
|
);
|
|
});
|
|
});
|