diff --git a/src/__tests__/tombstone-read-guard.test.ts b/src/__tests__/tombstone-read-guard.test.ts index 58895e9a0..ba32b1ca0 100644 --- a/src/__tests__/tombstone-read-guard.test.ts +++ b/src/__tests__/tombstone-read-guard.test.ts @@ -38,6 +38,9 @@ const SCOPES = [ "app/api/insights/", "app/api/analytics/", "app/api/dashboard/", + // Request-handler logic moved out of its route into a service keeps the + // route's scope. + "lib/dashboard/widgets/", ]; /** `model@file` → why this read includes deleted rows. */ diff --git a/src/app/api/dashboard/widgets/route.ts b/src/app/api/dashboard/widgets/route.ts index 3c394cebf..e4167a49a 100644 --- a/src/app/api/dashboard/widgets/route.ts +++ b/src/app/api/dashboard/widgets/route.ts @@ -6,17 +6,9 @@ * DELETE resets web-controlled choices and preserves the other preferences. */ import { apiHandler, requireAuth, requireRecordAuth } from "@/lib/api-handler"; -import { - apiSuccess, - buildPayloadDiagnostic, - safeJson, - returnAllZodIssues, - sanitiseZodIssues, -} from "@/lib/api-response"; +import { apiSuccess, safeJson, returnAllZodIssues } from "@/lib/api-response"; import { annotate } from "@/lib/logging/context"; -import { isModuleEnabled } from "@/lib/modules/gate"; -import { unavailableWidgetIds } from "@/lib/dashboard/widget-modules"; -import { prisma, toJson } from "@/lib/db"; +import { toJson } from "@/lib/db"; import { takeBaseToken, guardedUserUpdate, @@ -24,8 +16,6 @@ import { } from "@/lib/optimistic-lock"; import { resolveDashboardLayout, - serializeDashboardLayout, - DEFAULT_DASHBOARD_LAYOUT, DASHBOARD_WIDGET_CATALOGUE_IDS, COMPARISON_BASELINES, CHART_OVERLAY_KEYS, @@ -34,16 +24,19 @@ import { HERO_RING_IDS, MAX_HERO_RING_ORDER, HERO_PRIMARY_CONTENTS, - layoutNeedsPreserveRead, - mergePreservedLayoutFields, type DashboardLayout, type DashboardLayoutWithToken, } from "@/lib/dashboard-layout"; +import { buildDashboardLayout } from "@/lib/dashboard/widgets/read-layout"; +import { resolveUnavailableWidgetIds } from "@/lib/dashboard/widgets/unavailable-widgets"; +import { dropUnknownWidgetIds } from "@/lib/dashboard/widgets/unknown-ids"; +import { reportLayoutValidationFailure } from "@/lib/dashboard/widgets/validation-report"; +import { layoutToStore } from "@/lib/dashboard/widgets/merge-stored"; +import { resetDashboardLayout } from "@/lib/dashboard/widgets/reset-layout"; import { PRIORITY_ITEM_KINDS } from "@/lib/daily/priority-item"; import { z } from "zod/v4"; import { invalidateUserDashboardWidgets } from "@/lib/cache/invalidate"; import { cached, caches, type ServerCache } from "@/lib/cache/server-cache"; -import { redactForExcerpt } from "@/lib/observability/redact-payload"; import type { NextRequest } from "next/server"; // Single source of truth — every widget id the layout accepts. The @@ -179,21 +172,6 @@ const layoutSchema = z.object({ // field, and pulling it pre-Zod keeps the domain schema pure. }); -async function buildDashboardLayout( - userId: string, -): Promise { - const row = await prisma.user.findUnique({ - where: { id: userId }, - // v1.32.16 (issue #581) — `updatedAt` rides the cached layout so GET - // hands the client the optimistic-concurrency token alongside the - // layout it applies to. Cached together (and busted on every write) - // so the (layout, token) pair a client reads is always consistent. - select: { dashboardWidgetsJson: true, updatedAt: true }, - }); - const layout = resolveDashboardLayout(row?.dashboardWidgetsJson); - return { ...layout, updatedAt: row?.updatedAt?.toISOString() }; -} - export const GET = apiHandler(async () => { // Read: the RECORD's layout. Write: refused — see the PUT and DELETE below. // @@ -224,42 +202,8 @@ export const GET = apiHandler(async () => { annotate, ); - // Which toggles cannot do anything for this account. Resolved here, on - // the server, so the Settings screen never has to fetch dashboard data - // to find out whether a switch it is about to draw is dead. - // - // Deliberately OUTSIDE the cached layout above: the layout cell is keyed - // on the user and holds their arrangement, which does not change when a - // module is toggled. Folding a module-dependent answer into it would - // serve a stale one for the rest of the 5-minute TTL — the switch would - // linger for minutes after Recovery went off, which is the confusion this - // is removing. - // - // The HRV probes are index-only existence checks - // (`@@index([userId, type, measuredAt])`), not a summaries read; it runs - // only when Recovery is off, so the common account pays nothing. - // One flag, read the way this codebase reads one flag — not the whole - // module map. `hrv` is the only conditionally-dead widget and `recovery` - // is the only module that decides it. - const recoveryEnabled = await isModuleEnabled(user.id, "recovery"); - let hasSdnn = true; - let hasRmssd = true; - if (!recoveryEnabled) { - const [sdnnRow, rmssdRow] = await Promise.all( - (["HEART_RATE_VARIABILITY", "HRV_RMSSD"] as const).map((type) => - prisma.measurement.findFirst({ - where: { userId: user.id, type, deletedAt: null }, - select: { id: true }, - }), - ), - ); - hasSdnn = sdnnRow !== null; - hasRmssd = rmssdRow !== null; - } - const unavailable = unavailableWidgetIds( - { recovery: recoveryEnabled }, - { hasSdnn, hasRmssd }, - ); + // Outside the cached layout on purpose; see `resolveUnavailableWidgetIds`. + const unavailable = await resolveUnavailableWidgetIds(user.id); return apiSuccess( unavailable.length > 0 ? { ...layout, unavailableWidgetIds: unavailable } @@ -295,76 +239,13 @@ export const PUT = apiHandler(async (request: NextRequest) => { const base = taken.base; const body = taken.rest; - // v1.7.0 — accept-and-ignore widget ids OUTSIDE the 27-id catalogue - // on write. The 27 ids (16 web + 11 iOS-only) all validate + persist; - // only a genuinely-unknown id (a retired tile, or a typo) is filtered - // out here BEFORE Zod so it can't 422 the whole blob. The strict enum - // still validates the surviving ids, so a malformed entry (non-string - // id, missing `order`) still 422s. An id outside the catalogue - // silently vanishes — acceptable, and greppable via the annotation. - const knownWidgetIds = new Set(DASHBOARD_WIDGET_CATALOGUE_IDS); - if ( - body && - typeof body === "object" && - Array.isArray((body as { widgets?: unknown }).widgets) - ) { - const widgetsBody = body as { - widgets: Array<{ id?: unknown }>; - }; - const droppedIds = widgetsBody.widgets - .map((w) => w?.id) - .filter( - (id): id is string => typeof id === "string" && !knownWidgetIds.has(id), - ); - if (droppedIds.length > 0) { - widgetsBody.widgets = widgetsBody.widgets.filter( - (w) => !(typeof w?.id === "string" && !knownWidgetIds.has(w.id)), - ); - // v1.7.0 — the unknown-id filter runs over the FULL incoming - // `widgets` array BEFORE Zod's `.max(20)` applies, so `droppedIds` - // is bounded only by the request body limit. Cap the logged array - // (keep the full `dropped_count`) so a single large request can't - // push thousands of strings into one wide-event line. - annotate({ - action: { name: "dashboard.widgets.unknown-id-dropped" }, - meta: { - dropped_ids: droppedIds.slice(0, 20), - dropped_count: droppedIds.length, - }, - }); - } - } + // Ids outside the catalogue are dropped before Zod (a retired tile must + // not 422 the whole blob). + dropUnknownWidgetIds(body); const parsed = layoutSchema.safeParse(body); if (!parsed.success) { - // v1.4.42 — the legacy `issues[0].message` envelope dropped - // every issue past the first. iOS contract debugging hit one - // round-trip per wrong field; the new helper surfaces every - // issue under `details.issues`. We additionally emit an - // append-only audit-ledger row so the operator can grep - // `/api/admin/audit` for these without combing the iOS dev - // console. - const issues = sanitiseZodIssues(parsed.error.issues); - // v1.4.48 H-iOS-1 — surface the iOS-sent payload shape alongside - // the Zod rejection so a single wide-event line carries enough - // detail to diagnose serialiser drift in `HealthLog-iOS`. We log - // ONLY the top-level keys plus a hard 256-char JSON excerpt — never - // the full body — so PII / token-like fields cannot leak. The - // diagnostic shape is built by the shared `buildPayloadDiagnostic` - // helper (v1.4.49) so the widget + series routes can't drift; the - // body is routed through `redactForExcerpt` first so any - // future field matching the denylist (password / token / secret / - // apiKey / authorization / csrfState / nonce) lands as the literal - // `"[redacted]"` instead of its raw value. - const payloadDiagnostic = buildPayloadDiagnostic(redactForExcerpt(body)); - annotate({ - action: { name: "dashboard.widgets.validation-failed" }, - meta: { - issue_count: issues.length, - ...payloadDiagnostic, - zod_issues: issues, - }, - }); + reportLayoutValidationFailure(body, parsed.error); // No audit row: this write resolves the caller (`requireAuth`), so the // refusal can only ever be the caller's own, which is telemetry and // lives on the wide event above. Only a delegate's refused attempt is @@ -372,66 +253,15 @@ export const PUT = apiHandler(async (request: NextRequest) => { return returnAllZodIssues(parsed.error, 422); } - // Preserve every omitted client-owned field from the stored layout instead - // of clamping it to a default. The disposition map is exhaustive over - // `DashboardLayout`, so adding a field requires an explicit merge decision. - // One stored-layout read covers every fallback. The read is skipped only - // when the client supplied every preserved field and every supplied chart - // preference has rangePoints. - // - // The Zod shape leaves per-chart `comparisonBaseline` optional while - // `ChartOverlayPrefs` requires it. `coerceChartOverlayPrefsMap` inside the - // serializer fills that gap, so the assertion below is safe. - // v1.32.16 (issue #581) — the concurrency token was already split off the - // body pre-Zod (`takeBaseToken`), so `parsed.data` is pure layout and can - // never leak the token into the stored blob. - let toSerialize = parsed.data as Partial; - const incomingChartOverlayPrefs = toSerialize.chartOverlayPrefs; - const needsRangePointsPreserve = - incomingChartOverlayPrefs !== undefined && - CHART_OVERLAY_KEYS.some((chartKey) => { - const prefs = incomingChartOverlayPrefs[chartKey]; - return prefs !== undefined && prefs.rangePoints === undefined; - }); - const needsPreserveRead = - layoutNeedsPreserveRead(toSerialize) || needsRangePointsPreserve; - if (needsPreserveRead) { - const existing = await prisma.user.findUnique({ - where: { id: user.id }, - select: { dashboardWidgetsJson: true }, - }); - const existingLayout = resolveDashboardLayout( - existing?.dashboardWidgetsJson, - ); - toSerialize = mergePreservedLayoutFields(toSerialize, existingLayout); - - if (needsRangePointsPreserve && toSerialize.chartOverlayPrefs) { - let mergedChartOverlayPrefs = toSerialize.chartOverlayPrefs; - for (const chartKey of CHART_OVERLAY_KEYS) { - const incomingPrefs = toSerialize.chartOverlayPrefs[chartKey]; - const storedRangePoints = - existingLayout.chartOverlayPrefs?.[chartKey]?.rangePoints; - if ( - incomingPrefs !== undefined && - incomingPrefs.rangePoints === undefined && - storedRangePoints !== undefined - ) { - if (mergedChartOverlayPrefs === toSerialize.chartOverlayPrefs) { - mergedChartOverlayPrefs = { ...toSerialize.chartOverlayPrefs }; - } - mergedChartOverlayPrefs[chartKey] = { - ...incomingPrefs, - rangePoints: storedRangePoints, - }; - } - } - toSerialize = { - ...toSerialize, - chartOverlayPrefs: mergedChartOverlayPrefs, - }; - } - } - const normalized = serializeDashboardLayout(toSerialize as DashboardLayout); + // Omitted fields are carried forward from the stored layout. The Zod shape + // leaves per-chart `comparisonBaseline` optional while `ChartOverlayPrefs` + // requires it; `coerceChartOverlayPrefsMap` inside the serializer fills + // that gap, so the assertion is safe. The concurrency token was split off + // pre-Zod, so `parsed.data` can never leak it into the stored blob. + const normalized = await layoutToStore( + user.id, + parsed.data as Partial, + ); // Optimistic concurrency through the shared `guardedUserUpdate` helper. // When a client sends the `baseUpdatedAt` token it read with the layout, the @@ -472,33 +302,7 @@ export const DELETE = apiHandler(async () => { // dashboard to defaults is the loudest possible version of redecorating it. const { user } = await requireAuth(); - // Under a row lock rather than Serializable isolation: a reset racing a - // chart-overlay toggle on the same account waits for it instead of - // failing with a serialization error (a 500). - const { normalized, updatedAt } = await prisma.$transaction(async (tx) => { - await tx.$queryRaw`SELECT id FROM users WHERE id = ${user.id} FOR UPDATE`; - const existing = await tx.user.findUnique({ - where: { id: user.id }, - select: { dashboardWidgetsJson: true }, - }); - const existingLayout = resolveDashboardLayout( - existing?.dashboardWidgetsJson, - ); - const normalized = serializeDashboardLayout({ - ...existingLayout, - widgets: DEFAULT_DASHBOARD_LAYOUT.widgets, - enabledHeroItemKinds: DEFAULT_DASHBOARD_LAYOUT.enabledHeroItemKinds, - // A reset brings a hidden top card back. - todayCardVisible: DEFAULT_DASHBOARD_LAYOUT.todayCardVisible, - }); - - const updated = await tx.user.update({ - where: { id: user.id }, - data: { dashboardWidgetsJson: toJson(normalized) }, - select: { updatedAt: true }, - }); - return { normalized, updatedAt: updated.updatedAt.toISOString() }; - }); + const { normalized, updatedAt } = await resetDashboardLayout(user.id); annotate({ action: { name: "dashboard.widgets.reset" } }); diff --git a/src/lib/dashboard/widgets/merge-stored.ts b/src/lib/dashboard/widgets/merge-stored.ts new file mode 100644 index 000000000..2ed40aeff --- /dev/null +++ b/src/lib/dashboard/widgets/merge-stored.ts @@ -0,0 +1,72 @@ +/** + * The layout a dashboard-layout save stores: what the client sent, with + * every omitted client-owned field carried forward from the stored layout + * instead of clamped to a default. + * + * The disposition map is exhaustive over `DashboardLayout`, so adding a + * field requires an explicit merge decision. One stored-layout read covers + * every fallback. The read is skipped only when the client supplied every + * preserved field and every supplied chart preference has rangePoints. + */ +import { prisma } from "@/lib/db"; +import { + CHART_OVERLAY_KEYS, + layoutNeedsPreserveRead, + mergePreservedLayoutFields, + resolveDashboardLayout, + serializeDashboardLayout, + type DashboardLayout, +} from "@/lib/dashboard-layout"; + +export async function layoutToStore( + userId: string, + incoming: Partial, +): Promise { + let toSerialize = incoming; + const incomingChartOverlayPrefs = toSerialize.chartOverlayPrefs; + const needsRangePointsPreserve = + incomingChartOverlayPrefs !== undefined && + CHART_OVERLAY_KEYS.some((chartKey) => { + const prefs = incomingChartOverlayPrefs[chartKey]; + return prefs !== undefined && prefs.rangePoints === undefined; + }); + const needsPreserveRead = + layoutNeedsPreserveRead(toSerialize) || needsRangePointsPreserve; + if (needsPreserveRead) { + const existing = await prisma.user.findUnique({ + where: { id: userId }, + select: { dashboardWidgetsJson: true }, + }); + const existingLayout = resolveDashboardLayout( + existing?.dashboardWidgetsJson, + ); + toSerialize = mergePreservedLayoutFields(toSerialize, existingLayout); + + if (needsRangePointsPreserve && toSerialize.chartOverlayPrefs) { + let mergedChartOverlayPrefs = toSerialize.chartOverlayPrefs; + for (const chartKey of CHART_OVERLAY_KEYS) { + const incomingPrefs = toSerialize.chartOverlayPrefs[chartKey]; + const storedRangePoints = + existingLayout.chartOverlayPrefs?.[chartKey]?.rangePoints; + if ( + incomingPrefs !== undefined && + incomingPrefs.rangePoints === undefined && + storedRangePoints !== undefined + ) { + if (mergedChartOverlayPrefs === toSerialize.chartOverlayPrefs) { + mergedChartOverlayPrefs = { ...toSerialize.chartOverlayPrefs }; + } + mergedChartOverlayPrefs[chartKey] = { + ...incomingPrefs, + rangePoints: storedRangePoints, + }; + } + } + toSerialize = { + ...toSerialize, + chartOverlayPrefs: mergedChartOverlayPrefs, + }; + } + } + return serializeDashboardLayout(toSerialize as DashboardLayout); +} diff --git a/src/lib/dashboard/widgets/read-layout.ts b/src/lib/dashboard/widgets/read-layout.ts new file mode 100644 index 000000000..44b6185d3 --- /dev/null +++ b/src/lib/dashboard/widgets/read-layout.ts @@ -0,0 +1,25 @@ +/** + * The stored dashboard layout of one account, resolved for `GET + * /api/dashboard/widgets`: defaults merged in when the account has not + * customised it, with the optimistic-concurrency token beside it. + */ +import { prisma } from "@/lib/db"; +import { + resolveDashboardLayout, + type DashboardLayoutWithToken, +} from "@/lib/dashboard-layout"; + +export async function buildDashboardLayout( + userId: string, +): Promise { + const row = await prisma.user.findUnique({ + where: { id: userId }, + // Issue #581: `updatedAt` rides the cached layout so GET hands the + // client the optimistic-concurrency token alongside the layout it + // applies to. Cached together (and busted on every write) so the + // (layout, token) pair a client reads is always consistent. + select: { dashboardWidgetsJson: true, updatedAt: true }, + }); + const layout = resolveDashboardLayout(row?.dashboardWidgetsJson); + return { ...layout, updatedAt: row?.updatedAt?.toISOString() }; +} diff --git a/src/lib/dashboard/widgets/reset-layout.ts b/src/lib/dashboard/widgets/reset-layout.ts new file mode 100644 index 000000000..68097f8d9 --- /dev/null +++ b/src/lib/dashboard/widgets/reset-layout.ts @@ -0,0 +1,43 @@ +/** + * Reset the web-controlled dashboard choices of one account to their + * defaults, preserving its other layout preferences. + */ +import { prisma, toJson } from "@/lib/db"; +import { + DEFAULT_DASHBOARD_LAYOUT, + resolveDashboardLayout, + serializeDashboardLayout, + type DashboardLayout, +} from "@/lib/dashboard-layout"; + +export async function resetDashboardLayout( + userId: string, +): Promise<{ normalized: DashboardLayout; updatedAt: string }> { + // Under a row lock rather than Serializable isolation: a reset racing a + // chart-overlay toggle on the same account waits for it instead of + // failing with a serialization error (a 500). + return prisma.$transaction(async (tx) => { + await tx.$queryRaw`SELECT id FROM users WHERE id = ${userId} FOR UPDATE`; + const existing = await tx.user.findUnique({ + where: { id: userId }, + select: { dashboardWidgetsJson: true }, + }); + const existingLayout = resolveDashboardLayout( + existing?.dashboardWidgetsJson, + ); + const normalized = serializeDashboardLayout({ + ...existingLayout, + widgets: DEFAULT_DASHBOARD_LAYOUT.widgets, + enabledHeroItemKinds: DEFAULT_DASHBOARD_LAYOUT.enabledHeroItemKinds, + // A reset brings a hidden top card back. + todayCardVisible: DEFAULT_DASHBOARD_LAYOUT.todayCardVisible, + }); + + const updated = await tx.user.update({ + where: { id: userId }, + data: { dashboardWidgetsJson: toJson(normalized) }, + select: { updatedAt: true }, + }); + return { normalized, updatedAt: updated.updatedAt.toISOString() }; + }); +} diff --git a/src/lib/dashboard/widgets/unavailable-widgets.ts b/src/lib/dashboard/widgets/unavailable-widgets.ts new file mode 100644 index 000000000..ed68ee41d --- /dev/null +++ b/src/lib/dashboard/widgets/unavailable-widgets.ts @@ -0,0 +1,44 @@ +/** + * Which dashboard toggles cannot do anything for this account. Resolved on + * the server, so the Settings screen never has to fetch dashboard data to + * find out whether a switch it is about to draw is dead. + * + * Deliberately OUTSIDE the cached layout: the layout cell is keyed on the + * user and holds their arrangement, which does not change when a module is + * toggled. Folding a module-dependent answer into it would serve a stale one + * for the rest of the 5-minute TTL — the switch would linger for minutes + * after Recovery went off, which is the confusion this is removing. + */ +import { prisma } from "@/lib/db"; +import { unavailableWidgetIds } from "@/lib/dashboard/widget-modules"; +import { isModuleEnabled } from "@/lib/modules/gate"; + +export async function resolveUnavailableWidgetIds( + userId: string, +): Promise { + // The HRV probes are index-only existence checks + // (`@@index([userId, type, measuredAt])`), not a summaries read; it runs + // only when Recovery is off, so the common account pays nothing. + // One flag, read the way this codebase reads one flag — not the whole + // module map. `hrv` is the only conditionally-dead widget and `recovery` + // is the only module that decides it. + const recoveryEnabled = await isModuleEnabled(userId, "recovery"); + let hasSdnn = true; + let hasRmssd = true; + if (!recoveryEnabled) { + const [sdnnRow, rmssdRow] = await Promise.all( + (["HEART_RATE_VARIABILITY", "HRV_RMSSD"] as const).map((type) => + prisma.measurement.findFirst({ + where: { userId, type, deletedAt: null }, + select: { id: true }, + }), + ), + ); + hasSdnn = sdnnRow !== null; + hasRmssd = rmssdRow !== null; + } + return unavailableWidgetIds( + { recovery: recoveryEnabled }, + { hasSdnn, hasRmssd }, + ); +} diff --git a/src/lib/dashboard/widgets/unknown-ids.ts b/src/lib/dashboard/widgets/unknown-ids.ts new file mode 100644 index 000000000..ab454793a --- /dev/null +++ b/src/lib/dashboard/widgets/unknown-ids.ts @@ -0,0 +1,48 @@ +/** + * Accept-and-ignore widget ids OUTSIDE the catalogue on write. + * + * Every catalogue id (web and iOS-only) validates and persists; only a + * genuinely-unknown id (a retired tile, or a typo) is filtered out here + * BEFORE Zod so it can't 422 the whole blob. The strict enum still validates + * the surviving ids, so a malformed entry (non-string id, missing `order`) + * still 422s. An id outside the catalogue silently vanishes — acceptable, + * and greppable via the annotation. + */ +import { DASHBOARD_WIDGET_CATALOGUE_IDS } from "@/lib/dashboard-layout"; +import { annotate } from "@/lib/logging/context"; + +/** Drops unknown ids from `body.widgets` in place, and says so on the event. */ +export function dropUnknownWidgetIds(body: unknown): void { + const knownWidgetIds = new Set(DASHBOARD_WIDGET_CATALOGUE_IDS); + if ( + body && + typeof body === "object" && + Array.isArray((body as { widgets?: unknown }).widgets) + ) { + const widgetsBody = body as { + widgets: Array<{ id?: unknown }>; + }; + const droppedIds = widgetsBody.widgets + .map((w) => w?.id) + .filter( + (id): id is string => typeof id === "string" && !knownWidgetIds.has(id), + ); + if (droppedIds.length > 0) { + widgetsBody.widgets = widgetsBody.widgets.filter( + (w) => !(typeof w?.id === "string" && !knownWidgetIds.has(w.id)), + ); + // The unknown-id filter runs over the FULL incoming `widgets` array + // BEFORE Zod's `.max()` applies, so `droppedIds` is bounded only by + // the request body limit. Cap the logged array (keep the full + // `dropped_count`) so a single large request can't push thousands of + // strings into one wide-event line. + annotate({ + action: { name: "dashboard.widgets.unknown-id-dropped" }, + meta: { + dropped_ids: droppedIds.slice(0, 20), + dropped_count: droppedIds.length, + }, + }); + } + } +} diff --git a/src/lib/dashboard/widgets/validation-report.ts b/src/lib/dashboard/widgets/validation-report.ts new file mode 100644 index 000000000..88fe06ea9 --- /dev/null +++ b/src/lib/dashboard/widgets/validation-report.ts @@ -0,0 +1,35 @@ +/** + * The wide-event line a refused dashboard-layout save leaves behind. + * + * Every issue is surfaced (iOS contract debugging used to take one round + * trip per wrong field), next to the shape of the payload the client sent, + * so a single line carries enough detail to diagnose serialiser drift in the + * native client. Only the top-level keys plus a hard 256-char JSON excerpt + * are logged — never the full body — so PII / token-like fields cannot leak. + * The diagnostic shape is built by the shared `buildPayloadDiagnostic` + * helper so the widget and series routes can't drift; the body is routed + * through `redactForExcerpt` first so any field matching the denylist + * (password / token / secret / apiKey / authorization / csrfState / nonce) + * lands as the literal `"[redacted]"` instead of its raw value. + */ +import type { z } from "zod/v4"; + +import { buildPayloadDiagnostic, sanitiseZodIssues } from "@/lib/api-response"; +import { annotate } from "@/lib/logging/context"; +import { redactForExcerpt } from "@/lib/observability/redact-payload"; + +export function reportLayoutValidationFailure( + body: unknown, + error: z.ZodError, +): void { + const issues = sanitiseZodIssues(error.issues); + const payloadDiagnostic = buildPayloadDiagnostic(redactForExcerpt(body)); + annotate({ + action: { name: "dashboard.widgets.validation-failed" }, + meta: { + issue_count: issues.length, + ...payloadDiagnostic, + zod_issues: issues, + }, + }); +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.01-get-default.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.01-get-default.json.snap new file mode 100644 index 000000000..e782b90aa --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.01-get-default.json.snap @@ -0,0 +1,219 @@ +{ + "status": 200, + "body": { + "data": { + "version": 1, + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [ + "coach_checkin", + "dose_window", + "preventive_care", + "sync_issue", + "milestone", + "ecg_new_recording", + "tension_window", + "same_time_baseline", + "upcoming_visit" + ], + "hero": "score", + "todayCardVisible": true, + "widgets": [ + { + "id": "weight", + "visible": true, + "tileVisible": true, + "order": 0 + }, + { + "id": "bp", + "visible": true, + "tileVisible": true, + "order": 1 + }, + { + "id": "pulse", + "visible": true, + "tileVisible": true, + "order": 2 + }, + { + "id": "hrv", + "visible": false, + "tileVisible": true, + "order": 3 + }, + { + "id": "oxygenSaturation", + "visible": false, + "tileVisible": true, + "order": 4 + }, + { + "id": "respiratoryRate", + "visible": false, + "tileVisible": true, + "order": 5 + }, + { + "id": "wristTemperature", + "visible": false, + "tileVisible": true, + "order": 6 + }, + { + "id": "bodyFat", + "visible": true, + "tileVisible": true, + "order": 7 + }, + { + "id": "muscleMass", + "visible": false, + "tileVisible": true, + "order": 8 + }, + { + "id": "totalBodyWater", + "visible": false, + "tileVisible": true, + "order": 9 + }, + { + "id": "boneMass", + "visible": false, + "tileVisible": true, + "order": 10 + }, + { + "id": "mood", + "visible": true, + "tileVisible": true, + "order": 11 + }, + { + "id": "bpInTarget", + "visible": true, + "tileVisible": true, + "order": 12 + }, + { + "id": "medications", + "visible": true, + "tileVisible": true, + "order": 13 + }, + { + "id": "sleep", + "visible": false, + "tileVisible": true, + "order": 14 + }, + { + "id": "steps", + "visible": false, + "tileVisible": true, + "order": 15 + }, + { + "id": "glucose", + "visible": false, + "tileVisible": true, + "order": 16 + }, + { + "id": "achievements", + "visible": true, + "tileVisible": false, + "order": 17 + }, + { + "id": "vo2Max", + "visible": false, + "tileVisible": true, + "order": 18 + }, + { + "id": "recentWorkouts", + "visible": true, + "tileVisible": true, + "order": 19 + }, + { + "id": "cardioRecovery", + "visible": false, + "tileVisible": false, + "order": 20 + }, + { + "id": "sixMinuteWalk", + "visible": false, + "tileVisible": false, + "order": 21 + }, + { + "id": "stairAscentSpeed", + "visible": false, + "tileVisible": false, + "order": 22 + }, + { + "id": "stairDescentSpeed", + "visible": false, + "tileVisible": false, + "order": 23 + }, + { + "id": "breathingDisturbances", + "visible": false, + "tileVisible": false, + "order": 24 + }, + { + "id": "falls", + "visible": false, + "tileVisible": false, + "order": 25 + }, + { + "id": "walkingSteadiness", + "visible": false, + "tileVisible": false, + "order": 26 + }, + { + "id": "vorsorge", + "visible": true, + "tileVisible": false, + "order": 27 + }, + { + "id": "waterIntake", + "visible": false, + "tileVisible": true, + "order": 28 + } + ], + "updatedAt": "" + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": null, + "meta": { + "cache.dashboardWidgets.outcome": "miss", + "cache.dashboardWidgets.key_hash": "" + }, + "warnings": null, + "error": null + } + ], + "stored": null +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.02-get-cached.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.02-get-cached.json.snap new file mode 100644 index 000000000..fd505c472 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.02-get-cached.json.snap @@ -0,0 +1,219 @@ +{ + "status": 200, + "body": { + "data": { + "version": 1, + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [ + "coach_checkin", + "dose_window", + "preventive_care", + "sync_issue", + "milestone", + "ecg_new_recording", + "tension_window", + "same_time_baseline", + "upcoming_visit" + ], + "hero": "score", + "todayCardVisible": true, + "widgets": [ + { + "id": "weight", + "visible": true, + "tileVisible": true, + "order": 0 + }, + { + "id": "bp", + "visible": true, + "tileVisible": true, + "order": 1 + }, + { + "id": "pulse", + "visible": true, + "tileVisible": true, + "order": 2 + }, + { + "id": "hrv", + "visible": false, + "tileVisible": true, + "order": 3 + }, + { + "id": "oxygenSaturation", + "visible": false, + "tileVisible": true, + "order": 4 + }, + { + "id": "respiratoryRate", + "visible": false, + "tileVisible": true, + "order": 5 + }, + { + "id": "wristTemperature", + "visible": false, + "tileVisible": true, + "order": 6 + }, + { + "id": "bodyFat", + "visible": true, + "tileVisible": true, + "order": 7 + }, + { + "id": "muscleMass", + "visible": false, + "tileVisible": true, + "order": 8 + }, + { + "id": "totalBodyWater", + "visible": false, + "tileVisible": true, + "order": 9 + }, + { + "id": "boneMass", + "visible": false, + "tileVisible": true, + "order": 10 + }, + { + "id": "mood", + "visible": true, + "tileVisible": true, + "order": 11 + }, + { + "id": "bpInTarget", + "visible": true, + "tileVisible": true, + "order": 12 + }, + { + "id": "medications", + "visible": true, + "tileVisible": true, + "order": 13 + }, + { + "id": "sleep", + "visible": false, + "tileVisible": true, + "order": 14 + }, + { + "id": "steps", + "visible": false, + "tileVisible": true, + "order": 15 + }, + { + "id": "glucose", + "visible": false, + "tileVisible": true, + "order": 16 + }, + { + "id": "achievements", + "visible": true, + "tileVisible": false, + "order": 17 + }, + { + "id": "vo2Max", + "visible": false, + "tileVisible": true, + "order": 18 + }, + { + "id": "recentWorkouts", + "visible": true, + "tileVisible": true, + "order": 19 + }, + { + "id": "cardioRecovery", + "visible": false, + "tileVisible": false, + "order": 20 + }, + { + "id": "sixMinuteWalk", + "visible": false, + "tileVisible": false, + "order": 21 + }, + { + "id": "stairAscentSpeed", + "visible": false, + "tileVisible": false, + "order": 22 + }, + { + "id": "stairDescentSpeed", + "visible": false, + "tileVisible": false, + "order": 23 + }, + { + "id": "breathingDisturbances", + "visible": false, + "tileVisible": false, + "order": 24 + }, + { + "id": "falls", + "visible": false, + "tileVisible": false, + "order": 25 + }, + { + "id": "walkingSteadiness", + "visible": false, + "tileVisible": false, + "order": 26 + }, + { + "id": "vorsorge", + "visible": true, + "tileVisible": false, + "order": 27 + }, + { + "id": "waterIntake", + "visible": false, + "tileVisible": true, + "order": 28 + } + ], + "updatedAt": "" + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": null, + "meta": { + "cache.dashboardWidgets.outcome": "hit", + "cache.dashboardWidgets.key_hash": "" + }, + "warnings": null, + "error": null + } + ], + "stored": null +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.03-put-full-unknown-ids.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.03-put-full-unknown-ids.json.snap new file mode 100644 index 000000000..6ff77eac3 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.03-put-full-unknown-ids.json.snap @@ -0,0 +1,419 @@ +{ + "status": 200, + "body": { + "data": { + "version": 1, + "widgets": [ + { + "id": "weight", + "visible": true, + "tileVisible": true, + "order": 0 + }, + { + "id": "bp", + "visible": true, + "tileVisible": true, + "order": 1 + }, + { + "id": "pulse", + "visible": true, + "tileVisible": true, + "order": 2 + }, + { + "id": "hrv", + "visible": false, + "tileVisible": true, + "order": 3 + }, + { + "id": "oxygenSaturation", + "visible": false, + "tileVisible": true, + "order": 4 + }, + { + "id": "respiratoryRate", + "visible": false, + "tileVisible": true, + "order": 5 + }, + { + "id": "wristTemperature", + "visible": false, + "tileVisible": true, + "order": 6 + }, + { + "id": "bodyFat", + "visible": true, + "tileVisible": true, + "order": 7 + }, + { + "id": "muscleMass", + "visible": false, + "tileVisible": true, + "order": 8 + }, + { + "id": "totalBodyWater", + "visible": false, + "tileVisible": true, + "order": 9 + }, + { + "id": "boneMass", + "visible": false, + "tileVisible": true, + "order": 10 + }, + { + "id": "mood", + "visible": true, + "tileVisible": true, + "order": 11 + }, + { + "id": "bpInTarget", + "visible": true, + "tileVisible": true, + "order": 12 + }, + { + "id": "medications", + "visible": true, + "tileVisible": true, + "order": 13 + }, + { + "id": "sleep", + "visible": false, + "tileVisible": true, + "order": 14 + }, + { + "id": "steps", + "visible": false, + "tileVisible": true, + "order": 15 + }, + { + "id": "glucose", + "visible": false, + "tileVisible": true, + "order": 16 + }, + { + "id": "achievements", + "visible": true, + "tileVisible": false, + "order": 17 + }, + { + "id": "vo2Max", + "visible": false, + "tileVisible": true, + "order": 18 + }, + { + "id": "recentWorkouts", + "visible": true, + "tileVisible": true, + "order": 19 + }, + { + "id": "cardioRecovery", + "visible": false, + "tileVisible": false, + "order": 20 + }, + { + "id": "sixMinuteWalk", + "visible": false, + "tileVisible": false, + "order": 21 + }, + { + "id": "stairAscentSpeed", + "visible": false, + "tileVisible": false, + "order": 22 + }, + { + "id": "stairDescentSpeed", + "visible": false, + "tileVisible": false, + "order": 23 + }, + { + "id": "breathingDisturbances", + "visible": false, + "tileVisible": false, + "order": 24 + }, + { + "id": "falls", + "visible": false, + "tileVisible": false, + "order": 25 + }, + { + "id": "walkingSteadiness", + "visible": false, + "tileVisible": false, + "order": 26 + }, + { + "id": "vorsorge", + "visible": true, + "tileVisible": false, + "order": 27 + }, + { + "id": "waterIntake", + "visible": false, + "tileVisible": true, + "order": 28 + } + ], + "comparisonBaseline": "lastMonth", + "chartOverlayPrefs": { + "weight": { + "showTrendIndicator": true, + "showTrendArrow": false, + "showTargetRange": true, + "comparisonBaseline": "none", + "rangePoints": 30 + } + }, + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [], + "updatedAt": "" + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "dashboard.widgets.update" + }, + "meta": { + "dropped_ids": [ + "retired-tile", + "typo-tile" + ], + "dropped_count": 2, + "visible_count": 10 + }, + "warnings": null, + "error": null + } + ], + "stored": { + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "chartOverlayPrefs": { + "weight": { + "rangePoints": 30, + "showTrendArrow": false, + "showTargetRange": true, + "comparisonBaseline": "none", + "showTrendIndicator": true + } + }, + "comparisonBaseline": "lastMonth", + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.04-put-partial-preserve.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.04-put-partial-preserve.json.snap new file mode 100644 index 000000000..47f2fd7d4 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.04-put-partial-preserve.json.snap @@ -0,0 +1,428 @@ +{ + "status": 200, + "body": { + "data": { + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "comparisonBaseline": "lastMonth", + "chartOverlayPrefs": { + "weight": { + "showTrendIndicator": false, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "rangePoints": 30 + }, + "bp": { + "showTrendIndicator": true, + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none" + } + }, + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [], + "hero": "reminders", + "updatedAt": "" + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "dashboard.widgets.update" + }, + "meta": { + "visible_count": 10 + }, + "warnings": null, + "error": null + } + ], + "stored": { + "hero": "reminders", + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "chartOverlayPrefs": { + "bp": { + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none", + "showTrendIndicator": true + }, + "weight": { + "rangePoints": 30, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "showTrendIndicator": false + } + }, + "comparisonBaseline": "lastMonth", + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.05-put-invalid.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.05-put-invalid.json.snap new file mode 100644 index 000000000..881c7eea9 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.05-put-invalid.json.snap @@ -0,0 +1,271 @@ +{ + "status": 422, + "body": { + "data": null, + "error": "Validation failed", + "details": { + "issues": [ + { + "path": "version", + "code": "invalid_value", + "message": "Invalid input: expected 1" + }, + { + "path": "widgets.0.visible", + "code": "invalid_type", + "message": "Invalid input: expected boolean, received string" + }, + { + "path": "comparisonBaseline", + "code": "invalid_value", + "message": "Invalid option: expected one of \"none\"|\"lastMonth\"|\"lastYear\"" + } + ] + }, + "meta": { + "errorCode": "http.invalid", + "requestId": "" + } + }, + "events": [ + { + "status": 422, + "action": { + "name": "dashboard.widgets.validation-failed" + }, + "meta": { + "issue_count": 3, + "received_keys": [ + "version", + "widgets", + "comparisonBaseline", + "password" + ], + "received_shape_excerpt": "{\"version\":2,\"widgets\":[{\"id\":\"weight\",\"visible\":\"yes\",\"order\":1}],\"comparisonBaseline\":\"lastDecade\",\"password\":\"[redacted]\"}", + "zod_issues": [ + { + "path": "version", + "code": "invalid_value", + "message": "Invalid input: expected 1" + }, + { + "path": "widgets.0.visible", + "code": "invalid_type", + "message": "Invalid input: expected boolean, received string" + }, + { + "path": "comparisonBaseline", + "code": "invalid_value", + "message": "Invalid option: expected one of \"none\"|\"lastMonth\"|\"lastYear\"" + } + ] + }, + "warnings": null, + "error": null + } + ], + "stored": { + "hero": "reminders", + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "chartOverlayPrefs": { + "bp": { + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none", + "showTrendIndicator": true + }, + "weight": { + "rangePoints": 30, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "showTrendIndicator": false + } + }, + "comparisonBaseline": "lastMonth", + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.06-put-empty-body.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.06-put-empty-body.json.snap new file mode 100644 index 000000000..61d27e8c3 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.06-put-empty-body.json.snap @@ -0,0 +1,224 @@ +{ + "status": 400, + "body": { + "data": null, + "error": "Invalid JSON body", + "meta": { + "errorCode": "http.bad_request", + "requestId": "" + } + }, + "events": [ + { + "status": 400, + "action": null, + "meta": null, + "warnings": null, + "error": null + } + ], + "stored": { + "hero": "reminders", + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "chartOverlayPrefs": { + "bp": { + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none", + "showTrendIndicator": true + }, + "weight": { + "rangePoints": 30, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "showTrendIndicator": false + } + }, + "comparisonBaseline": "lastMonth", + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.07-put-invalid-base.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.07-put-invalid-base.json.snap new file mode 100644 index 000000000..ddfdb8515 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.07-put-invalid-base.json.snap @@ -0,0 +1,224 @@ +{ + "status": 422, + "body": { + "data": null, + "error": "Invalid base token", + "meta": { + "errorCode": "invalid_base_updated_at", + "requestId": "" + } + }, + "events": [ + { + "status": 422, + "action": null, + "meta": null, + "warnings": null, + "error": null + } + ], + "stored": { + "hero": "reminders", + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "chartOverlayPrefs": { + "bp": { + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none", + "showTrendIndicator": true + }, + "weight": { + "rangePoints": 30, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "showTrendIndicator": false + } + }, + "comparisonBaseline": "lastMonth", + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.08-put-stale-base.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.08-put-stale-base.json.snap new file mode 100644 index 000000000..1b7721ae9 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.08-put-stale-base.json.snap @@ -0,0 +1,228 @@ +{ + "status": 409, + "body": { + "data": null, + "error": "Dashboard layout changed since it was loaded", + "meta": { + "errorCode": "dashboard_layout_conflict", + "requestId": "" + } + }, + "events": [ + { + "status": 409, + "action": { + "name": "dashboard.widgets.conflict" + }, + "meta": { + "base_updated_at": "2026-01-01T00:00:00.000Z" + }, + "warnings": null, + "error": null + } + ], + "stored": { + "hero": "reminders", + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "chartOverlayPrefs": { + "bp": { + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none", + "showTrendIndicator": true + }, + "weight": { + "rangePoints": 30, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "showTrendIndicator": false + } + }, + "comparisonBaseline": "lastMonth", + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.09-put-current-base.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.09-put-current-base.json.snap new file mode 100644 index 000000000..7d089361e --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.09-put-current-base.json.snap @@ -0,0 +1,430 @@ +{ + "status": 200, + "body": { + "data": { + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "comparisonBaseline": "lastMonth", + "chartOverlayPrefs": { + "bp": { + "showTrendIndicator": true, + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none" + }, + "weight": { + "showTrendIndicator": false, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "rangePoints": 30 + } + }, + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [], + "hero": "reminders", + "todayCardVisible": false, + "updatedAt": "" + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "dashboard.widgets.update" + }, + "meta": { + "visible_count": 10 + }, + "warnings": null, + "error": null + } + ], + "stored": { + "hero": "reminders", + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "todayCardVisible": false, + "chartOverlayPrefs": { + "bp": { + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none", + "showTrendIndicator": true + }, + "weight": { + "rangePoints": 30, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "showTrendIndicator": false + } + }, + "comparisonBaseline": "lastMonth", + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.10a-get-recovery-off-no-hrv.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.10a-get-recovery-off-no-hrv.json.snap new file mode 100644 index 000000000..d9f349889 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.10a-get-recovery-off-no-hrv.json.snap @@ -0,0 +1,432 @@ +{ + "status": 200, + "body": { + "data": { + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "comparisonBaseline": "lastMonth", + "chartOverlayPrefs": { + "bp": { + "showTrendIndicator": true, + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none" + }, + "weight": { + "showTrendIndicator": false, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "rangePoints": 30 + } + }, + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [], + "hero": "reminders", + "todayCardVisible": false, + "updatedAt": "", + "unavailableWidgetIds": [ + "hrv" + ] + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": null, + "meta": { + "cache.dashboardWidgets.outcome": "miss", + "cache.dashboardWidgets.key_hash": "" + }, + "warnings": null, + "error": null + } + ], + "stored": { + "hero": "reminders", + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "todayCardVisible": false, + "chartOverlayPrefs": { + "bp": { + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none", + "showTrendIndicator": true + }, + "weight": { + "rangePoints": 30, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "showTrendIndicator": false + } + }, + "comparisonBaseline": "lastMonth", + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.10b-get-recovery-off-rmssd.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.10b-get-recovery-off-rmssd.json.snap new file mode 100644 index 000000000..71c833f1e --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.10b-get-recovery-off-rmssd.json.snap @@ -0,0 +1,429 @@ +{ + "status": 200, + "body": { + "data": { + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "comparisonBaseline": "lastMonth", + "chartOverlayPrefs": { + "bp": { + "showTrendIndicator": true, + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none" + }, + "weight": { + "showTrendIndicator": false, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "rangePoints": 30 + } + }, + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [], + "hero": "reminders", + "todayCardVisible": false, + "updatedAt": "" + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": null, + "meta": { + "cache.dashboardWidgets.outcome": "hit", + "cache.dashboardWidgets.key_hash": "" + }, + "warnings": null, + "error": null + } + ], + "stored": { + "hero": "reminders", + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "todayCardVisible": false, + "chartOverlayPrefs": { + "bp": { + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none", + "showTrendIndicator": true + }, + "weight": { + "rangePoints": 30, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "showTrendIndicator": false + } + }, + "comparisonBaseline": "lastMonth", + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.11a-delegate-get.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.11a-delegate-get.json.snap new file mode 100644 index 000000000..71c833f1e --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.11a-delegate-get.json.snap @@ -0,0 +1,429 @@ +{ + "status": 200, + "body": { + "data": { + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "comparisonBaseline": "lastMonth", + "chartOverlayPrefs": { + "bp": { + "showTrendIndicator": true, + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none" + }, + "weight": { + "showTrendIndicator": false, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "rangePoints": 30 + } + }, + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [], + "hero": "reminders", + "todayCardVisible": false, + "updatedAt": "" + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": null, + "meta": { + "cache.dashboardWidgets.outcome": "hit", + "cache.dashboardWidgets.key_hash": "" + }, + "warnings": null, + "error": null + } + ], + "stored": { + "hero": "reminders", + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "todayCardVisible": false, + "chartOverlayPrefs": { + "bp": { + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none", + "showTrendIndicator": true + }, + "weight": { + "rangePoints": 30, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "showTrendIndicator": false + } + }, + "comparisonBaseline": "lastMonth", + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.11b-delegate-put.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.11b-delegate-put.json.snap new file mode 100644 index 000000000..b241397e8 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.11b-delegate-put.json.snap @@ -0,0 +1,230 @@ +{ + "status": 403, + "body": { + "data": null, + "error": "This endpoint cannot be used while acting on another account", + "meta": { + "errorCode": "sharing.not_permitted", + "requestId": "" + } + }, + "events": [ + { + "status": 403, + "action": null, + "meta": { + "sharing_refusal": "undeclared_mode" + }, + "warnings": null, + "error": { + "type": "SharingNotPermittedError", + "message": "This endpoint cannot be used while acting on another account" + } + } + ], + "stored": { + "hero": "reminders", + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "todayCardVisible": false, + "chartOverlayPrefs": { + "bp": { + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none", + "showTrendIndicator": true + }, + "weight": { + "rangePoints": 30, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "showTrendIndicator": false + } + }, + "comparisonBaseline": "lastMonth", + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.11c-delegate-delete.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.11c-delegate-delete.json.snap new file mode 100644 index 000000000..b241397e8 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.11c-delegate-delete.json.snap @@ -0,0 +1,230 @@ +{ + "status": 403, + "body": { + "data": null, + "error": "This endpoint cannot be used while acting on another account", + "meta": { + "errorCode": "sharing.not_permitted", + "requestId": "" + } + }, + "events": [ + { + "status": 403, + "action": null, + "meta": { + "sharing_refusal": "undeclared_mode" + }, + "warnings": null, + "error": { + "type": "SharingNotPermittedError", + "message": "This endpoint cannot be used while acting on another account" + } + } + ], + "stored": { + "hero": "reminders", + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "todayCardVisible": false, + "chartOverlayPrefs": { + "bp": { + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none", + "showTrendIndicator": true + }, + "weight": { + "rangePoints": 30, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "showTrendIndicator": false + } + }, + "comparisonBaseline": "lastMonth", + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.12-delete-reset.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.12-delete-reset.json.snap new file mode 100644 index 000000000..74d9a52b9 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.12-delete-reset.json.snap @@ -0,0 +1,436 @@ +{ + "status": 200, + "body": { + "data": { + "version": 1, + "widgets": [ + { + "id": "weight", + "visible": true, + "tileVisible": true, + "order": 0 + }, + { + "id": "bp", + "visible": true, + "tileVisible": true, + "order": 1 + }, + { + "id": "pulse", + "visible": true, + "tileVisible": true, + "order": 2 + }, + { + "id": "hrv", + "visible": false, + "tileVisible": true, + "order": 3 + }, + { + "id": "oxygenSaturation", + "visible": false, + "tileVisible": true, + "order": 4 + }, + { + "id": "respiratoryRate", + "visible": false, + "tileVisible": true, + "order": 5 + }, + { + "id": "wristTemperature", + "visible": false, + "tileVisible": true, + "order": 6 + }, + { + "id": "bodyFat", + "visible": true, + "tileVisible": true, + "order": 7 + }, + { + "id": "muscleMass", + "visible": false, + "tileVisible": true, + "order": 8 + }, + { + "id": "totalBodyWater", + "visible": false, + "tileVisible": true, + "order": 9 + }, + { + "id": "boneMass", + "visible": false, + "tileVisible": true, + "order": 10 + }, + { + "id": "mood", + "visible": true, + "tileVisible": true, + "order": 11 + }, + { + "id": "bpInTarget", + "visible": true, + "tileVisible": true, + "order": 12 + }, + { + "id": "medications", + "visible": true, + "tileVisible": true, + "order": 13 + }, + { + "id": "sleep", + "visible": false, + "tileVisible": true, + "order": 14 + }, + { + "id": "steps", + "visible": false, + "tileVisible": true, + "order": 15 + }, + { + "id": "glucose", + "visible": false, + "tileVisible": true, + "order": 16 + }, + { + "id": "achievements", + "visible": true, + "tileVisible": false, + "order": 17 + }, + { + "id": "vo2Max", + "visible": false, + "tileVisible": true, + "order": 18 + }, + { + "id": "recentWorkouts", + "visible": true, + "tileVisible": true, + "order": 19 + }, + { + "id": "cardioRecovery", + "visible": false, + "tileVisible": false, + "order": 20 + }, + { + "id": "sixMinuteWalk", + "visible": false, + "tileVisible": false, + "order": 21 + }, + { + "id": "stairAscentSpeed", + "visible": false, + "tileVisible": false, + "order": 22 + }, + { + "id": "stairDescentSpeed", + "visible": false, + "tileVisible": false, + "order": 23 + }, + { + "id": "breathingDisturbances", + "visible": false, + "tileVisible": false, + "order": 24 + }, + { + "id": "falls", + "visible": false, + "tileVisible": false, + "order": 25 + }, + { + "id": "walkingSteadiness", + "visible": false, + "tileVisible": false, + "order": 26 + }, + { + "id": "vorsorge", + "visible": true, + "tileVisible": false, + "order": 27 + }, + { + "id": "waterIntake", + "visible": false, + "tileVisible": true, + "order": 28 + } + ], + "comparisonBaseline": "lastMonth", + "chartOverlayPrefs": { + "bp": { + "showTrendIndicator": true, + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none" + }, + "weight": { + "showTrendIndicator": false, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "rangePoints": 30 + } + }, + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [ + "coach_checkin", + "dose_window", + "preventive_care", + "sync_issue", + "milestone", + "ecg_new_recording", + "tension_window", + "same_time_baseline", + "upcoming_visit" + ], + "hero": "reminders", + "todayCardVisible": true, + "updatedAt": "" + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "dashboard.widgets.reset" + }, + "meta": null, + "warnings": null, + "error": null + } + ], + "stored": { + "hero": "reminders", + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "chartOverlayPrefs": { + "bp": { + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none", + "showTrendIndicator": true + }, + "weight": { + "rangePoints": 30, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "showTrendIndicator": false + } + }, + "comparisonBaseline": "lastMonth", + "selectedScoreRings": [ + "MED_COMPLIANCE" + ] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.13-get-after-reset.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.13-get-after-reset.json.snap new file mode 100644 index 000000000..e2b329bf3 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.13-get-after-reset.json.snap @@ -0,0 +1,437 @@ +{ + "status": 200, + "body": { + "data": { + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "comparisonBaseline": "lastMonth", + "chartOverlayPrefs": { + "bp": { + "showTrendIndicator": true, + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none" + }, + "weight": { + "showTrendIndicator": false, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "rangePoints": 30 + } + }, + "selectedScoreRings": [ + "MED_COMPLIANCE" + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "enabledHeroItemKinds": [ + "coach_checkin", + "dose_window", + "preventive_care", + "sync_issue", + "milestone", + "ecg_new_recording", + "tension_window", + "same_time_baseline", + "upcoming_visit" + ], + "hero": "reminders", + "todayCardVisible": true, + "updatedAt": "" + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": null, + "meta": { + "cache.dashboardWidgets.outcome": "miss", + "cache.dashboardWidgets.key_hash": "" + }, + "warnings": null, + "error": null + } + ], + "stored": { + "hero": "reminders", + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "chartOverlayPrefs": { + "bp": { + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none", + "showTrendIndicator": true + }, + "weight": { + "rangePoints": 30, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "showTrendIndicator": false + } + }, + "comparisonBaseline": "lastMonth", + "selectedScoreRings": [ + "MED_COMPLIANCE" + ] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/dashboard-widgets.14-anonymous-get.json.snap b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.14-anonymous-get.json.snap new file mode 100644 index 000000000..83ae725b0 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/dashboard-widgets.14-anonymous-get.json.snap @@ -0,0 +1,226 @@ +{ + "status": 401, + "body": { + "data": null, + "error": "Not authenticated", + "meta": { + "errorCode": "auth.missing", + "requestId": "" + } + }, + "events": [ + { + "status": 401, + "action": null, + "meta": null, + "warnings": null, + "error": { + "type": "HttpError", + "message": "Not authenticated" + } + } + ], + "stored": { + "hero": "reminders", + "version": 1, + "widgets": [ + { + "id": "weight", + "order": 0, + "visible": true, + "tileVisible": true + }, + { + "id": "bp", + "order": 1, + "visible": true, + "tileVisible": true + }, + { + "id": "pulse", + "order": 2, + "visible": true, + "tileVisible": true + }, + { + "id": "hrv", + "order": 3, + "visible": false, + "tileVisible": true + }, + { + "id": "oxygenSaturation", + "order": 4, + "visible": false, + "tileVisible": true + }, + { + "id": "respiratoryRate", + "order": 5, + "visible": false, + "tileVisible": true + }, + { + "id": "wristTemperature", + "order": 6, + "visible": false, + "tileVisible": true + }, + { + "id": "bodyFat", + "order": 7, + "visible": true, + "tileVisible": true + }, + { + "id": "muscleMass", + "order": 8, + "visible": false, + "tileVisible": true + }, + { + "id": "totalBodyWater", + "order": 9, + "visible": false, + "tileVisible": true + }, + { + "id": "boneMass", + "order": 10, + "visible": false, + "tileVisible": true + }, + { + "id": "mood", + "order": 11, + "visible": true, + "tileVisible": true + }, + { + "id": "bpInTarget", + "order": 12, + "visible": true, + "tileVisible": true + }, + { + "id": "medications", + "order": 13, + "visible": true, + "tileVisible": true + }, + { + "id": "sleep", + "order": 14, + "visible": false, + "tileVisible": true + }, + { + "id": "steps", + "order": 15, + "visible": false, + "tileVisible": true + }, + { + "id": "glucose", + "order": 16, + "visible": false, + "tileVisible": true + }, + { + "id": "achievements", + "order": 17, + "visible": true, + "tileVisible": false + }, + { + "id": "vo2Max", + "order": 18, + "visible": false, + "tileVisible": true + }, + { + "id": "recentWorkouts", + "order": 19, + "visible": true, + "tileVisible": true + }, + { + "id": "cardioRecovery", + "order": 20, + "visible": false, + "tileVisible": false + }, + { + "id": "sixMinuteWalk", + "order": 21, + "visible": false, + "tileVisible": false + }, + { + "id": "stairAscentSpeed", + "order": 22, + "visible": false, + "tileVisible": false + }, + { + "id": "stairDescentSpeed", + "order": 23, + "visible": false, + "tileVisible": false + }, + { + "id": "breathingDisturbances", + "order": 24, + "visible": false, + "tileVisible": false + }, + { + "id": "falls", + "order": 25, + "visible": false, + "tileVisible": false + }, + { + "id": "walkingSteadiness", + "order": 26, + "visible": false, + "tileVisible": false + }, + { + "id": "vorsorge", + "order": 27, + "visible": true, + "tileVisible": false + }, + { + "id": "waterIntake", + "order": 28, + "visible": false, + "tileVisible": true + } + ], + "heroRingOrder": [ + "HEALTH_SCORE", + "MED_COMPLIANCE" + ], + "chartOverlayPrefs": { + "bp": { + "showTrendArrow": true, + "showTargetRange": true, + "comparisonBaseline": "none", + "showTrendIndicator": true + }, + "weight": { + "rangePoints": 30, + "showTrendArrow": true, + "showTargetRange": false, + "comparisonBaseline": "none", + "showTrendIndicator": false + } + }, + "comparisonBaseline": "lastMonth", + "selectedScoreRings": [ + "MED_COMPLIANCE" + ] + } +} diff --git a/tests/integration/routes/parity/dashboard-widgets.parity.test.ts b/tests/integration/routes/parity/dashboard-widgets.parity.test.ts new file mode 100644 index 000000000..0faca0745 --- /dev/null +++ b/tests/integration/routes/parity/dashboard-widgets.parity.test.ts @@ -0,0 +1,313 @@ +/** + * Parity for `GET / PUT / DELETE /api/dashboard/widgets` while the layout + * logic moves out of the route into `src/lib/dashboard/widgets/`. + * + * One owner walks through the cases the route tells apart, in order, each + * request seeing what the earlier ones stored: the first read (the default + * layout, filled into the cache), the same read from the cache, a full save + * that carries ids outside the catalogue, a partial save that leans on the + * stored layout (including a per-chart range the client left out), the + * refusals (schema, an empty body, junk and stale base tokens), a save on + * the current token, reads with the recovery module off before and after an + * HRV series exists, a delegate reading the owner's layout and being refused + * the write and the reset, the owner's reset, and an anonymous call. After + * each request the snapshot holds the response, the wide event and the + * stored layout blob. + * + * The clock is pinned (`Date` only) and moved one second per step, so the + * concurrency token advances between writes the way it does in production. + */ +import { afterAll, beforeAll, describe, expect, it, vi } from "vitest"; + +import { DELETE, GET, PUT } from "@/app/api/dashboard/widgets/route"; +import { DEFAULT_DASHBOARD_LAYOUT } from "@/lib/dashboard-layout"; + +import { + anonymous, + callRoute, + type HttpMethod, + type RouteAuth, +} from "../../../kit/call-route"; +import { + makeGrant, + makeMeasurement, + makeSession, + makeUser, + type SessionFixture, +} from "../../../kit/factories"; +import { + eventFacts, + expectParity, + stable, + wideEventRecorder, +} from "../../../kit/parity"; +import { headerJar } from "../../mock-next-headers"; +import { + getPrismaClient, + switchSessionTo, + truncateAllTables, +} from "../../setup"; + +vi.mock("@/lib/logging/transports", async (importOriginal) => { + const actual = + await importOriginal(); + const { wideEventRecorder: recorder } = await import("../../../kit/parity"); + return { + ...actual, + emitIfSampled: (event: (typeof recorder.events)[number]) => { + recorder.events.push(event); + }, + }; +}); + +const prisma = getPrismaClient(); +const NOW = new Date("2026-10-15T12:00:00.000Z"); +const ROUTE = "/api/dashboard/widgets"; +const HANDLERS = { GET, PUT, DELETE } as const; + +let ownerId: string; +let owner: SessionFixture; +let delegate: SessionFixture; +let tick = 0; + +/** The cache key is a hash of the account id, which differs on every run. */ +const VOLATILE = ["cache.dashboardWidgets.key_hash"]; + +/** A widget as the wire carries it: any id, so unknown ones can be sent. */ +interface WireWidget { + id: string; + visible: boolean; + tileVisible: boolean; + order: number; +} + +function fullLayout(extra: Record = {}) { + return { + version: 1, + widgets: DEFAULT_DASHBOARD_LAYOUT.widgets.map((w): WireWidget => ({ + id: w.id, + visible: w.visible, + tileVisible: w.tileVisible ?? w.visible, + order: w.order, + })), + comparisonBaseline: "none", + chartOverlayPrefs: {}, + selectedScoreRings: ["MED_COMPLIANCE"], + heroRingOrder: ["HEALTH_SCORE", "MED_COMPLIANCE"], + enabledHeroItemKinds: [], + hero: "score", + todayCardVisible: true, + ...extra, + }; +} + +async function stored() { + const row = await prisma.user.findUniqueOrThrow({ + where: { id: ownerId }, + select: { dashboardWidgetsJson: true }, + }); + return row.dashboardWidgetsJson; +} + +async function step( + name: string, + method: HttpMethod, + options: { + auth?: RouteAuth; + body?: unknown; + headers?: Record; + contract?: { skip: string }; + } = {}, +): Promise<{ data: unknown }> { + tick += 1; + vi.setSystemTime(new Date(NOW.getTime() + tick * 1000)); + wideEventRecorder.take(); + const handler = HANDLERS[method as keyof typeof HANDLERS]; + const res = await callRoute(handler, { + method, + route: ROUTE, + body: options.body, + headers: options.headers, + contract: options.contract, + auth: options.auth ?? owner, + }); + const events = wideEventRecorder.take(); + expect(events.length).toBeGreaterThan(0); + await expectParity( + `dashboard-widgets.${name}`, + stable( + { + status: res.status, + body: res.body, + events: events.map(eventFacts), + stored: await stored(), + }, + { since: NOW, volatileKeys: VOLATILE }, + ), + ); + return { data: res.data }; +} + +function tokenOf(data: unknown): string { + const token = (data as { updatedAt?: unknown } | null)?.updatedAt; + if (typeof token !== "string") throw new Error("no updatedAt in response"); + return token; +} + +beforeAll(async () => { + vi.useFakeTimers({ toFake: ["Date"], now: NOW }); + await truncateAllTables(prisma); + const ownerRow = await makeUser({ timezone: "UTC" }); + ownerId = ownerRow.id; + owner = await makeSession(ownerRow); + const delegateRow = await makeUser({ timezone: "UTC" }); + delegate = await makeSession(delegateRow); + await makeGrant(ownerRow, delegateRow, { access: "WRITE" }); +}); + +afterAll(() => { + vi.useRealTimers(); +}); + +describe("/api/dashboard/widgets parity", () => { + let lastToken = ""; + + it("01 the first read, filled into the cache", async () => { + const { data } = await step("01-get-default", "GET"); + lastToken = tokenOf(data); + }); + + it("02 the same read from the cache", async () => { + await step("02-get-cached", "GET"); + }); + + it("03 a full save carrying ids outside the catalogue", async () => { + const body = fullLayout({ comparisonBaseline: "lastMonth" }); + body.widgets.push( + { id: "retired-tile", visible: true, tileVisible: true, order: 90 }, + { id: "typo-tile", visible: false, tileVisible: false, order: 91 }, + ); + body.chartOverlayPrefs = { + weight: { + showTrendIndicator: true, + showTrendArrow: false, + showTargetRange: true, + rangePoints: 30, + }, + }; + const { data } = await step("03-put-full-unknown-ids", "PUT", { body }); + lastToken = tokenOf(data); + }); + + it("04 a partial save that keeps the stored fields and range", async () => { + const { data } = await step("04-put-partial-preserve", "PUT", { + body: { + version: 1, + chartOverlayPrefs: { + weight: { + showTrendIndicator: false, + showTrendArrow: true, + showTargetRange: false, + }, + bp: { + showTrendIndicator: true, + showTrendArrow: true, + showTargetRange: true, + }, + }, + hero: "reminders", + }, + }); + lastToken = tokenOf(data); + }); + + it("05 a body the schema refuses", async () => { + await step("05-put-invalid", "PUT", { + body: { + version: 2, + widgets: [{ id: "weight", visible: "yes", order: 1 }], + comparisonBaseline: "lastDecade", + password: "hunter2", + }, + }); + }); + + it("06 a request without a body", async () => { + await step("06-put-empty-body", "PUT", { + body: undefined, + headers: { "content-type": "application/json" }, + // The registry declares no 400 for this operation; the parity walk + // pins the answer the route gives, not the contract. + contract: { skip: "400 for an unreadable body is not registered" }, + }); + }); + + it("07 a junk base token", async () => { + await step("07-put-invalid-base", "PUT", { + body: { version: 1, baseUpdatedAt: 42, todayCardVisible: false }, + }); + }); + + it("08 a stale base token", async () => { + await step("08-put-stale-base", "PUT", { + body: { + version: 1, + baseUpdatedAt: "2026-01-01T00:00:00.000Z", + todayCardVisible: false, + }, + }); + }); + + it("09 a save on the current token", async () => { + const { data } = await step("09-put-current-base", "PUT", { + body: { version: 1, baseUpdatedAt: lastToken, todayCardVisible: false }, + }); + lastToken = tokenOf(data); + }); + + it("10 reads with recovery off, without HRV and with one series", async () => { + await prisma.user.update({ + where: { id: ownerId }, + data: { modulePreferencesJson: { recovery: false } }, + }); + await step("10a-get-recovery-off-no-hrv", "GET"); + await makeMeasurement( + { id: ownerId }, + { + type: "HRV_RMSSD", + value: 41, + unit: "ms", + measuredAt: new Date("2026-10-14T06:00:00.000Z"), + }, + ); + await step("10b-get-recovery-off-rmssd", "GET"); + }); + + it("11 a delegate reads the owner's layout and may not change it", async () => { + await switchSessionTo(delegate.sessionId, ownerId); + try { + await step("11a-delegate-get", "GET", { auth: delegate }); + await step("11b-delegate-put", "PUT", { + auth: delegate, + body: { version: 1, comparisonBaseline: "lastYear" }, + }); + await step("11c-delegate-delete", "DELETE", { auth: delegate }); + } finally { + await switchSessionTo(delegate.sessionId, null); + headerJar.delete("x-healthlog-record-epoch"); + headerJar.delete("x-healthlog-record-scope"); + } + }); + + it("12 the owner resets the layout", async () => { + await step("12-delete-reset", "DELETE"); + }); + + it("13 the read after the reset", async () => { + await step("13-get-after-reset", "GET"); + }); + + it("14 an anonymous call", async () => { + await step("14-anonymous-get", "GET", { auth: anonymous }); + }); +});