@@ -40,6 +40,15 @@ function makeRequest(body: Record<string, unknown>) {
4040 } ) ;
4141}
4242
43+ function makeRawRequest ( body : string ) {
44+ const url = "http://localhost/api/applications/test-app-id/status" ;
45+ return new NextRequest ( url , {
46+ method : "PUT" ,
47+ headers : { "Content-Type" : "application/json" } ,
48+ body,
49+ } ) ;
50+ }
51+
4352const routeParams = { params : Promise . resolve ( { id : "test-app-id" } ) } ;
4453
4554/** Build a chain-able Supabase query mock that resolves to `result`. */
@@ -99,6 +108,20 @@ describe("PUT /api/applications/[id]/status", () => {
99108 expect ( res . status ) . toBe ( 400 ) ;
100109 } ) ;
101110
111+ it ( "returns 400 for malformed JSON without querying Supabase" , async ( ) => {
112+ mockGetAuthContext . mockResolvedValue ( {
113+ user : { id : "poster-user-id" , authMethod : "session" } ,
114+ supabase : supabaseClient ,
115+ } as MockAuthContext ) ;
116+
117+ const res = await PUT ( makeRawRequest ( "{" ) , routeParams ) ;
118+ const json = await res . json ( ) ;
119+
120+ expect ( res . status ) . toBe ( 400 ) ;
121+ expect ( json . error ) . toBe ( "Invalid JSON body" ) ;
122+ expect ( mockFrom ) . not . toHaveBeenCalled ( ) ;
123+ } ) ;
124+
102125 it ( "returns 404 when application not found" , async ( ) => {
103126 mockGetAuthContext . mockResolvedValue ( {
104127 user : { id : "poster-user-id" , authMethod : "session" } ,
0 commit comments