test(sharing): hold the revoker pair at the database

A revoked grant with no revoker, or a revoker with no revocation, are
both rows that cannot answer the question the table exists to answer.
The migration already enforces the pair; this asserts it against real
Postgres rather than trusting that the domain module is the only writer.
This commit is contained in:
Marc-André Bombeck committed 2026-08-02 10:03:04 +02:00
1 parent 07e8ca9ef5
commit 48f29cc802
1 file changed
+28
@@ -303,6 +303,34 @@ describe("account grant lifecycle", () => {
).toBeNull();
});
it("refuses a revocation the record cannot attribute", async () => {
// The database holds the halves together, because a revoked row with no
// revoker and a revoker with no revocation are both records that cannot
// answer the question the table exists to answer. The domain module always
// writes the pair; this is the floor under it.
const { grant } = await acceptedGrant();
const prisma = getPrismaClient();
await expect(
prisma.accountGrant.update({
where: { id: grant.id },
data: { revokedAt: new Date() },
}),
).rejects.toThrow();
await expect(
prisma.accountGrant.update({
where: { id: grant.id },
data: { revokedBy: "GRANTOR" },
}),
).rejects.toThrow();
const row = await prisma.accountGrant.findUniqueOrThrow({
where: { id: grant.id },
});
expect(row.revokedAt).toBeNull();
expect(row.revokedBy).toBeNull();
});
it("refuses a second live grant for the same pair", async () => {
const owner = await makeUser("owner");
const delegate = await makeUser("delegate");