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 () => {