test: retain sustained safety event claims

- exercise the shared notification claim boundary\n- preserve rolling sustained-run dedup coverage
This commit is contained in:
Marc-André Bombeck committed 2026-08-06 04:59:50 +02:00
1 parent 9ba37342d7
commit affd356677
1 file changed
+30 -27
@@ -12,8 +12,13 @@
*/
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
/** In-memory record event stream so the 24h dedupe behaves across calls. */
const ledger: Array<{ recordUserId: string; dedupKey: string }> = [];
/** In-memory event claims so the 24h dedupe behaves across calls. */
const ledger: Array<{
recordUserId: string;
eventType: string;
dedupKey: string;
createdAt: Date;
}> = [];
const measurementFindMany = vi.fn();
const dispatchMock = vi.fn();
@@ -25,31 +30,6 @@ vi.mock("@/lib/db", () => ({
user: {
findUnique: vi.fn().mockResolvedValue({ managedProfileAt: null }),
},
notificationEvent: {
findFirst: ({
where,
}: {
where: { recordUserId: string; dedupKey: string };
}) => {
const hit = ledger.find(
(r) =>
r.recordUserId === where.recordUserId &&
r.dedupKey === where.dedupKey,
);
return Promise.resolve(hit ? { id: "prior" } : null);
},
create: ({
data,
}: {
data: { recordUserId: string; dedupKey: string };
}) => {
ledger.push({
recordUserId: data.recordUserId,
dedupKey: data.dedupKey,
});
return Promise.resolve({});
},
},
},
}));
@@ -65,6 +45,29 @@ vi.mock("@/lib/notifications/dispatch-localised", () => ({
dispatchLocalisedNotification: (...a: unknown[]) => dispatchMock(...a),
}));
vi.mock("@/lib/notifications/reminder-dedup", () => ({
claimNotificationEvent: (
_prisma: unknown,
input: {
recordUserId: string;
eventType: string;
dedupKey: string;
since: Date;
},
) => {
const existing = ledger.find(
(event) =>
event.recordUserId === input.recordUserId &&
event.eventType === input.eventType &&
event.dedupKey === input.dedupKey &&
event.createdAt >= input.since,
);
if (existing) return Promise.resolve(false);
ledger.push({ ...input, createdAt: new Date() });
return Promise.resolve(true);
},
}));
import { runSafetyFloorCheck } from "../safety-floor-check";
/** A measured-at on a given UTC calendar day, mid-morning. */