File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/**
22 * @vitest -environment node
33 */
4+ import appPackage from '@/package.json'
45import { NextRequest } from 'next/server'
56import { afterEach , describe , expect , it } from 'vitest'
67import { GET } from '@/app/api/health/route'
@@ -29,6 +30,12 @@ describe('GET /api/health', () => {
2930 } )
3031 } )
3132
33+ it ( 'accepts query parameters from health-checking clients' , async ( ) => {
34+ const response = await GET ( new NextRequest ( 'http://localhost/api/health?_=123' ) )
35+
36+ expect ( response . status ) . toBe ( 200 )
37+ } )
38+
3239 it ( 'falls back to the package version when runtime metadata is not provided' , async ( ) => {
3340 process . env . APP_VERSION = ''
3441 process . env . NEXT_PUBLIC_APP_VERSION = ''
@@ -42,7 +49,7 @@ describe('GET /api/health', () => {
4249 await expect ( response . json ( ) ) . resolves . toEqual ( {
4350 status : 'ok' ,
4451 timestamp : expect . any ( String ) ,
45- version : '0.1.0' ,
52+ version : appPackage . version ,
4653 commit : null ,
4754 } )
4855 } )
Original file line number Diff line number Diff line change @@ -20,7 +20,6 @@ function getAppCommit(): string | null {
2020export async function GET ( request : NextRequest ) : Promise < Response > {
2121 const parsed = await parseRequest ( healthContract , request , { } )
2222 if ( ! parsed . success ) return parsed . response
23-
2423 return NextResponse . json (
2524 {
2625 status : 'ok' ,
Original file line number Diff line number Diff line change 11import { z } from 'zod'
2- import { noInputSchema } from '@/lib/api/contracts/primitives'
32import { defineRouteContract } from '@/lib/api/contracts/types'
43
4+ const healthQuerySchema = z . object ( { } ) . passthrough ( )
55export const healthResponseSchema = z . object ( {
66 status : z . literal ( 'ok' ) ,
77 timestamp : z . string ( ) ,
@@ -14,7 +14,7 @@ export type HealthResponse = z.output<typeof healthResponseSchema>
1414export const healthContract = defineRouteContract ( {
1515 method : 'GET' ,
1616 path : '/api/health' ,
17- query : noInputSchema ,
17+ query : healthQuerySchema ,
1818 response : {
1919 mode : 'json' ,
2020 schema : healthResponseSchema ,
You can’t perform that action at this time.
0 commit comments