mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 20:42:43 +00:00
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.
This commit is contained in:
1 parent
82c138fb8e
commit
afe8634453
1 file changed
+10
-5
@@ -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<Response>)(
|
||||
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<Response>)(
|
||||
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 () => {
|
||||
|
||||
Reference in new issue
Block a user