mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 15:42:24 +00:00
Bundles the deferred v1.4.47 Mediums + Lows with the v1.4.48-deferred items into a single release. Headline: server-side suppression of MEDICATION_REMINDER APNs for iOS clients that own their local reminders (closes GH #206), a push_attempts table backing /api/admin/notifications/diagnostic, and a sweep of v1.4.48 QA forward-findings. Performance (the user-visible win): - /api/analytics cold-fallback path splits the heavy single-statement aggregate into two parallel queries. The linearly composable columns (count / min / max / mean) keep the full-partition scan; the windowed 7 / 30 / 90-day avg / slope / r² columns take a 90-day outer cap so the planner does an index range scan on (user_id, type, measured_at) instead of a full-partition sequential scan. Output is bit-identical; cold slim slice drops from multi-second to sub-second on tenants with large measurement partitions. Server-side notifications: - GET + PATCH /api/auth/me/notification-prefs with deep-merge semantics. Initial category medication.clientManaged: boolean (default false). Cron medicationReminderJob skips dose-due APNs when the flag is true, emitting a medication_reminder.suppressed_client_managed wide-event annotation per skip. - push_attempts table backs the diagnostic endpoint. Every APNS / Web-Push / Telegram / NTFY sender writes a fire-and-forget row. Daily 03:35 Europe/Berlin cleanup prunes rows older than 90 days. - /api/admin/notifications/diagnostic — admin-only endpoint surfacing device APNs token presence (masked), channel config presence, and recent push attempts. Registered in OpenAPI. - Per-channel APNs "Send test" button now fires with eventType: "MEDICATION_REMINDER" so the dispatcher's time-sensitive + priority-10 branch runs. A successful self-test now exercises the exact path production reminders take; an unsuccessful one points the user at iOS Settings → Time Sensitive Notifications rather than appearing to be a server-side bug. Withings reliability: - OAuth callback consumes the nonce atomically (delete-first with P2025 catch for the replay branch). The previous read-then-delete pattern allowed a race between two concurrent callbacks. - ?reason=state redirect differentiated into csrf1 / replay / expired / cross_user so operators can tell mismatch types apart without DB shell access. - connect endpoint rate-limited to 10/60s/user; row-create failures redirect to a consistent error surface. Observability hardening: - redactSensitiveFields(body) denylist helper covers password / token / secret / apiKey / authorization / csrfState / nonce, recursive, case-insensitive. Caught: /api/devices invalid_format issues were echoing apnsToken values verbatim into the audit log. - sanitiseZodIssues(issues, { stripValuesFromMessage: true }) overload applied to 14 audit-log sites. Migrations: 0079 (notification_prefs), 0080 (push_attempts). Tests: 4815 → 5272 unit + integration. Workout-batch integration suite that had been red on main since v1.4.45 (three release commits shipped through it) now green again — updated to match v1.4.42 cross-source dedup semantics. Resolves PR #207.
78 lines
3.1 KiB
TypeScript
78 lines
3.1 KiB
TypeScript
/**
|
|
* v1.4.49 — `<MoodReminderCard>` status auto-clear parity.
|
|
*
|
|
* The v1.4.48 W-DISABLE-COACH refactor added a 3 s `setTimeout` to
|
|
* `<DisableCoachCard>` and claimed in the docstring that the pattern
|
|
* mirrored `<MoodReminderCard>`. It did not — the mood-reminder card
|
|
* had no auto-clear. v1.4.49 backfills the parity. This suite pins:
|
|
*
|
|
* 1. The card SSRs cleanly with no in-flight status banner.
|
|
* 2. The component module exposes the auto-clear plumbing
|
|
* (`scheduleClear` + `clearTimerRef`) so a future refactor can't
|
|
* silently regress the docstring claim.
|
|
*
|
|
* Project convention is SSR-only tests (no `@testing-library/react`);
|
|
* the actual timer-tick behaviour is verified through manual QA + the
|
|
* shared pattern with `<DisableCoachCard>` which is already audit-grade.
|
|
*/
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { readFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
|
|
import { I18nProvider } from "@/lib/i18n/context";
|
|
|
|
vi.mock("next/navigation", () => ({
|
|
useRouter: () => ({ push: vi.fn(), replace: vi.fn() }),
|
|
usePathname: () => "/settings/notifications",
|
|
useSearchParams: () => new URLSearchParams(""),
|
|
}));
|
|
|
|
import { MoodReminderCard } from "../mood-reminder-card";
|
|
|
|
function render(): string {
|
|
const client = new QueryClient({
|
|
defaultOptions: { queries: { retry: 0 } },
|
|
});
|
|
return renderToStaticMarkup(
|
|
<QueryClientProvider client={client}>
|
|
<I18nProvider initialLocale="en">
|
|
<MoodReminderCard isAuthenticated={true} />
|
|
</I18nProvider>
|
|
</QueryClientProvider>,
|
|
);
|
|
}
|
|
|
|
describe("<MoodReminderCard> — v1.4.49 auto-clear parity", () => {
|
|
it("SSRs the card scaffolding with no in-flight status banner", () => {
|
|
const html = render();
|
|
// The Switch primitive surfaces `data-state="unchecked"` for the
|
|
// default `moodReminderEnabled: false` profile shape.
|
|
expect(html).toContain('data-state="unchecked"');
|
|
// No status message visible by default — the `<p role="status">`
|
|
// line is gated on `msg !== null`.
|
|
expect(html).not.toContain('role="status"');
|
|
});
|
|
|
|
it("contains the auto-clear plumbing introduced for v1.4.48 docstring parity", () => {
|
|
// Structural assertion: the source file ships the `scheduleClear`
|
|
// helper + `clearTimerRef` (mirroring `<DisableCoachCard>` from
|
|
// v1.4.48 M2). Reading the file rather than a runtime mount keeps
|
|
// the test deterministic in the SSR-only test environment.
|
|
const src = readFileSync(
|
|
resolve(__dirname, "../mood-reminder-card.tsx"),
|
|
"utf8",
|
|
);
|
|
expect(src).toContain("clearTimerRef");
|
|
expect(src).toContain("scheduleClear");
|
|
// 3 s timeout — must match the `<DisableCoachCard>` value so the
|
|
// two Settings cards age at the same rate.
|
|
expect(src).toMatch(/setTimeout\([^,]+,\s*3000\)/);
|
|
// Cleanup-on-unmount branch — without this a navigate-away during
|
|
// the 3 s window would leave a stray timer pointing at unmounted
|
|
// state.
|
|
expect(src).toContain("clearTimeout(clearTimerRef.current)");
|
|
});
|
|
});
|