From afe86344537cee242aebacf7ded3c8584a9aa5f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 14 May 2026 19:11:51 +0200 Subject: [PATCH] fix(test): align coach-prefs round-trip with W5 defaultWindow default W5 added `defaultWindow` to the coach-prefs schema with `"allTime"` as its default, so the PUT handler now returns the canonical defaulted shape even when the caller omits the field. Update the integration round-trip to expect the defaulted form on both the response envelope and the persisted row. --- tests/integration/coach-prefs.test.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/integration/coach-prefs.test.ts b/tests/integration/coach-prefs.test.ts index 59226d1ef..5da6b5531 100644 --- a/tests/integration/coach-prefs.test.ts +++ b/tests/integration/coach-prefs.test.ts @@ -85,12 +85,17 @@ describe("PUT /api/auth/me/coach-prefs", () => { const prisma = getPrismaClient(); const { PUT, GET } = await import("@/app/api/auth/me/coach-prefs/route"); + // The request body omits `defaultWindow`; the schema (v1.4.25 W5) + // defaults it to "allTime", so the canonical PUT response and the + // persisted row both carry the defaulted field even when the + // caller didn't pass it. const body = { tone: "concise" as const, verbosity: "brief" as const, excludeMetrics: ["mood" as const, "compliance" as const], showEvidenceByDefault: true, }; + const expected = { ...body, defaultWindow: "allTime" as const }; const putRes = await (PUT as (r: Request) => Promise)( new Request("http://localhost/api/auth/me/coach-prefs", { method: "PUT", @@ -99,23 +104,23 @@ describe("PUT /api/auth/me/coach-prefs", () => { }), ); expect(putRes.status).toBe(200); - const putEnv = (await putRes.json()) as { data: typeof body }; - expect(putEnv.data).toEqual(body); + const putEnv = (await putRes.json()) as { data: typeof expected }; + expect(putEnv.data).toEqual(expected); // DB row reflects the canonical defaulted form. const row = await prisma.user.findUnique({ where: { id: user.id }, select: { coachPrefsJson: true }, }); - expect(row?.coachPrefsJson).toEqual(body); + expect(row?.coachPrefsJson).toEqual(expected); // GET reads the saved values back. const getRes = await (GET as (r: Request) => Promise)( new Request("http://localhost/api/auth/me/coach-prefs"), ); expect(getRes.status).toBe(200); - const getEnv = (await getRes.json()) as { data: typeof body }; - expect(getEnv.data).toEqual(body); + const getEnv = (await getRes.json()) as { data: typeof expected }; + expect(getEnv.data).toEqual(expected); }); it("rejects unknown tone values with 422", async () => {