test(02-11): verify final claim uses database time

- Keep a stale application clock from authorizing an expired Guardian\n
This commit is contained in:
Marc-André Bombeck committed 2026-08-06 13:47:42 +02:00
1 parent 4b79f83cf7
commit e8ce0e277a
1 file changed
+40
@@ -228,6 +228,46 @@ describe("notification attribution (real Postgres)", () => {
expect(await getPrismaClient().pushAttempt.count()).toBe(0);
});
it("uses database time for expiry at the final egress claim", async () => {
const recordUser = await createUser("database-clock-record", true);
const recipientUser = await createUser("database-clock-recipient");
const actualNow = Date.now();
await createGuardianGrant({
recordUserId: recordUser.id,
recipientUserId: recipientUser.id,
expiresAt: new Date(actualNow - 1_000),
});
vi.useFakeTimers();
vi.setSystemTime(new Date(actualNow - 60_000));
try {
const delivery = await resolveNotificationDeliveryIdentity({
eventType: "MEDICATION_REMINDER",
userId: recordUser.id,
recordUserId: recordUser.id,
recipientUserId: recipientUser.id,
title: "record reminder",
message: "record message",
});
expect(delivery).toMatchObject({ managed: true });
await expect(
claimManagedGuardianEgressAuthorization(
delivery!,
"NTFY",
"MEDICATION_REMINDER",
),
).resolves.toBeNull();
} finally {
vi.useRealTimers();
}
expect(
await getPrismaClient().notificationEgressAuthorization.count(),
).toBe(0);
expect(await getPrismaClient().pushAttempt.count()).toBe(0);
});
it("allows exactly one concurrent claim for a notification event", async () => {
const recordUser = await createUser("claim-record", true);
const client = getPrismaClient();