mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-13 22:32:04 +00:00
test: cast analytics GET handler in sleep-stages integration test
The W2 commit shipped with `as never` casts on the request + params arguments, which let the runtime test pass but failed strict tsc because `apiHandler<() => Promise<Response>>` narrows the wrapper's signature down to its inner handler's. Cast through `unknown` so the wrapper-side `request.url` read works and tsc is satisfied. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
2ce1a85622
commit
49c1a41c08
1 file changed
+12
-6
@@ -124,9 +124,12 @@ describe("GET /api/analytics — sleep-stage aggregation", () => {
|
||||
}
|
||||
|
||||
const { GET } = await import("@/app/api/analytics/route");
|
||||
const response = await GET(
|
||||
new Request("http://localhost/api/analytics") as never,
|
||||
{ params: Promise.resolve({}) } as never,
|
||||
// The wrapped handler reads `request.url` for logging metadata;
|
||||
// the inner handler ignores its arguments. Cast through `unknown`
|
||||
// because `apiHandler`'s narrowed type signature is the inner
|
||||
// handler's `()`, not the wrapper's `(NextRequest)`.
|
||||
const response = await (GET as unknown as (req: Request) => Promise<Response>)(
|
||||
new Request("http://localhost/api/analytics"),
|
||||
);
|
||||
expect(response.status).toBe(200);
|
||||
const envelope = (await response.json()) as AnalyticsEnvelope;
|
||||
@@ -166,9 +169,12 @@ describe("GET /api/analytics — sleep-stage aggregation", () => {
|
||||
});
|
||||
|
||||
const { GET } = await import("@/app/api/analytics/route");
|
||||
const response = await GET(
|
||||
new Request("http://localhost/api/analytics") as never,
|
||||
{ params: Promise.resolve({}) } as never,
|
||||
// The wrapped handler reads `request.url` for logging metadata;
|
||||
// the inner handler ignores its arguments. Cast through `unknown`
|
||||
// because `apiHandler`'s narrowed type signature is the inner
|
||||
// handler's `()`, not the wrapper's `(NextRequest)`.
|
||||
const response = await (GET as unknown as (req: Request) => Promise<Response>)(
|
||||
new Request("http://localhost/api/analytics"),
|
||||
);
|
||||
expect(response.status).toBe(200);
|
||||
const envelope = (await response.json()) as AnalyticsEnvelope;
|
||||
|
||||
Reference in new issue
Block a user