Files
famapp/tests/unit/share-authorization.test.ts
ginnoir a312d4ce39
CI / checks (push) Successful in 12m55s
CI / build (push) Successful in 15m16s
fix: tighten sharing and shadcn composition
2026-06-13 05:20:01 -05:00

51 lines
1.4 KiB
TypeScript

import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { ensureEntityShareAuthorized } from "../../src/modules/_core/share-authorization";
import type { EntityTypeRegistration, ShareContext } from "../../src/modules/_core/module";
const ctx: ShareContext = {
householdId: "household-1",
userId: "user-1",
};
function registration(
canShareEntity?: EntityTypeRegistration["canShareEntity"],
): EntityTypeRegistration {
return {
type: "notes.note",
label: { singular: "Note", plural: "Notes" },
share: { canShare: true },
resolveUrl: (id) => `/notes/${id}`,
canShareEntity,
};
}
describe("ensureEntityShareAuthorized", () => {
it("rejects shareable entity types that do not provide entity authorization", async () => {
await assert.rejects(
() => ensureEntityShareAuthorized(registration(), "note-1", ctx),
/does not support share authorization/,
);
});
it("rejects entities denied by their module authorization callback", async () => {
await assert.rejects(
() =>
ensureEntityShareAuthorized(
registration(async () => false),
"note-1",
ctx,
),
/not allowed to share this entity/,
);
});
it("allows entities approved by their module authorization callback", async () => {
await ensureEntityShareAuthorized(
registration(async () => true),
"note-1",
ctx,
);
});
});