mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-13 14:32:03 +00:00
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:
1 parent
aae029d94e
commit
8057bb20bc
20 files changed
+207
-140
No files matched your search
@@ -84,20 +84,25 @@ export const GET = apiHandler(async () => {
|
||||
globallyEnabled: globalToggles[ch.type] ?? true,
|
||||
}));
|
||||
|
||||
// Admin-only events (backup health) are listed for admins only, and an
|
||||
// event nothing sends is listed for nobody: a switch for either would
|
||||
// switch nothing. A stored row for an unlisted event stays in the table and
|
||||
// is not served.
|
||||
const eventTypes: string[] = eventTypesForRole(user.role);
|
||||
const preferences = channels.flatMap((ch) =>
|
||||
ch.preferences.map((p) => ({
|
||||
channelId: p.channelId,
|
||||
eventType: p.eventType,
|
||||
enabled: p.enabled,
|
||||
})),
|
||||
ch.preferences
|
||||
.filter((p) => eventTypes.includes(p.eventType))
|
||||
.map((p) => ({
|
||||
channelId: p.channelId,
|
||||
eventType: p.eventType,
|
||||
enabled: p.enabled,
|
||||
})),
|
||||
);
|
||||
|
||||
return apiSuccess({
|
||||
channels: channelData,
|
||||
preferences,
|
||||
// Admin-only events (backup health) are listed for admins only: nobody
|
||||
// else is ever sent one, so a switch for it would switch nothing.
|
||||
eventTypes: eventTypesForRole(user.role),
|
||||
eventTypes,
|
||||
// What an event does on a channel with no stored row, resolved for this
|
||||
// account by the same function the dispatcher asks. A client renders a
|
||||
// switch without a row from this map, never from its own copy of the
|
||||
|
||||
@@ -143,8 +143,8 @@ describe("NotificationsPage", () => {
|
||||
},
|
||||
],
|
||||
preferences: [],
|
||||
eventTypes: ["MOOD_REMINDER", "PERSONAL_RECORD"],
|
||||
eventDefaults: { MOOD_REMINDER: true, PERSONAL_RECORD: false },
|
||||
eventTypes: ["MOOD_REMINDER", "DAILY_BRIEFING"],
|
||||
eventDefaults: { MOOD_REMINDER: true, DAILY_BRIEFING: false },
|
||||
};
|
||||
const html = render();
|
||||
const state = (label: string) =>
|
||||
@@ -152,10 +152,10 @@ describe("NotificationsPage", () => {
|
||||
`aria-label="${label} - Telegram"[^>]*data-state="(checked|unchecked)"|data-state="(checked|unchecked)"[^>]*aria-label="${label} - Telegram"`,
|
||||
).exec(html);
|
||||
const mood = state("Mood reminder");
|
||||
const record = state("Personal record");
|
||||
const briefing = state("Daily briefing");
|
||||
expect(mood, "mood switch rendered").not.toBeNull();
|
||||
expect(mood?.[1] ?? mood?.[2]).toBe("checked");
|
||||
expect(record?.[1] ?? record?.[2]).toBe("unchecked");
|
||||
expect(briefing?.[1] ?? briefing?.[2]).toBe("unchecked");
|
||||
});
|
||||
|
||||
it("a stored row still wins over the default", () => {
|
||||
|
||||
Reference in new issue
Block a user