From 10dd2fc9adab870051c8ef605ba03d13d52a56de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 14 May 2026 11:36:27 +0200 Subject: [PATCH] =?UTF-8?q?test(coach-prefs):=20fix=20NextRequest=20URL=20?= =?UTF-8?q?mock=20=E2=80=94=20v1.4.22=20carryover?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The two failing cases in tests/integration/coach-prefs.test.ts were invoking the route's GET handler with zero arguments — `(GET as () => Promise)()`. The apiHandler wrapper at src/lib/api-handler.ts:46-47 reads args[0].url to build the Wide Event `http.path`, so the call threw `TypeError: Cannot read properties of undefined (reading 'url')` before the route body ever ran. Other integration tests already pass a real Request to GET (see analytics-health-score, chart-overlay-prefs); aligning this test to the same pattern restores parity with production where Next.js always invokes route handlers with a Request. The api-handler wrapper itself was left untouched — defending against a caller passing undefined would mask the same bug in any future test. --- tests/integration/coach-prefs.test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/integration/coach-prefs.test.ts b/tests/integration/coach-prefs.test.ts index fc671a495..59226d1ef 100644 --- a/tests/integration/coach-prefs.test.ts +++ b/tests/integration/coach-prefs.test.ts @@ -70,7 +70,9 @@ describe("GET /api/auth/me/coach-prefs", () => { await seedSession("coach-prefs-defaults"); const { GET } = await import("@/app/api/auth/me/coach-prefs/route"); - const res = await (GET as () => Promise)(); + const res = await (GET as (r: Request) => Promise)( + new Request("http://localhost/api/auth/me/coach-prefs"), + ); expect(res.status).toBe(200); const env = (await res.json()) as { data: typeof DEFAULT_COACH_PREFS }; expect(env.data).toEqual(DEFAULT_COACH_PREFS); @@ -108,7 +110,9 @@ describe("PUT /api/auth/me/coach-prefs", () => { expect(row?.coachPrefsJson).toEqual(body); // GET reads the saved values back. - const getRes = await (GET as () => Promise)(); + 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);