fix(notifications): drop the four switches nothing sends

The notification matrix listed "Unusual measurement", "Low adherence",
"Withings sync failed" and "Personal record" with a switch per channel,
three of them on by default, yet nothing dispatches any of them: a reading
far outside its range or a week of missed doses produced no message.

eventTypesForRole now leaves them out for every role, next to the
admin-only filter, and the preferences read no longer serves rows stored
for them. Their labels in all locales and their tap targets are deleted.
The types stay in EVENT_TYPES, so the preference write and the stored rows
keep parsing; no migration.

The label and tap-target tests walked EVENT_TYPES and so pinned the four
in place; they now walk the event types that are sent.
This commit is contained in:
Marc-André Bombeck committed 2026-11-11 19:53:01 +01:00
1 parent aae029d94e
commit 8057bb20bc
20 files changed
+207 -140

No files matched your search

@@ -131,3 +131,49 @@ describe("event defaults: the matrix shows what delivery does", () => {
);
});
});
describe("events nothing sends", () => {
it("are listed for nobody, and their stored rows are not served", async () => {
const userId = await seedAccount(false);
const prisma = getPrismaClient();
const channel = await prisma.notificationChannel.findFirstOrThrow({
where: { userId },
});
// Rows written while the four switches were still offered.
await prisma.notificationPreference.createMany({
data: [
{ channelId: channel.id, eventType: "PERSONAL_RECORD", enabled: true },
{
channelId: channel.id,
eventType: "MEASUREMENT_ANOMALY",
enabled: false,
},
{
channelId: channel.id,
eventType: "MEDICATION_REMINDER",
enabled: false,
},
],
});
const { GET } = await import("@/app/api/notifications/preferences/route");
const res = await GET();
expect(res.status).toBe(200);
const body = (await res.json()) as {
data: {
eventTypes: string[];
preferences: { eventType: string; enabled: boolean }[];
};
};
const { UNSENT_EVENT_TYPES } = await import("@/lib/notifications/types");
for (const unsent of UNSENT_EVENT_TYPES) {
expect(body.data.eventTypes).not.toContain(unsent);
}
expect(body.data.preferences).toEqual([
expect.objectContaining({
eventType: "MEDICATION_REMINDER",
enabled: false,
}),
]);
});
});