@@ -142,4 +142,37 @@ await test('createApp', async (t) => {
142142 const data = await response . json ( )
143143 assert . deepEqual ( data , [ { id : '1' , title : 'foo' } ] )
144144 } )
145+
146+ await t . test ( 'POST /posts with array body returns 400' , async ( ) => {
147+ const response = await fetch ( `http://localhost:${ port } /posts` , {
148+ method : 'POST' ,
149+ headers : { 'Content-Type' : 'application/json' } ,
150+ body : JSON . stringify ( [ { title : 'foo' } ] ) ,
151+ } )
152+ assert . equal ( response . status , 400 )
153+ const data = await response . json ( )
154+ assert . deepEqual ( data , { error : 'Body must be a JSON object' } )
155+ } )
156+
157+ await t . test ( 'PATCH /posts/1 with string body returns 400' , async ( ) => {
158+ const response = await fetch ( `http://localhost:${ port } /posts/1` , {
159+ method : 'PATCH' ,
160+ headers : { 'Content-Type' : 'application/json' } ,
161+ body : JSON . stringify ( 'hello' ) ,
162+ } )
163+ assert . equal ( response . status , 400 )
164+ const data = await response . json ( )
165+ assert . deepEqual ( data , { error : 'Body must be a JSON object' } )
166+ } )
167+
168+ await t . test ( 'PUT /posts/1 with null body returns 400' , async ( ) => {
169+ const response = await fetch ( `http://localhost:${ port } /posts/1` , {
170+ method : 'PUT' ,
171+ headers : { 'Content-Type' : 'application/json' } ,
172+ body : JSON . stringify ( null ) ,
173+ } )
174+ assert . equal ( response . status , 400 )
175+ const data = await response . json ( )
176+ assert . deepEqual ( data , { error : 'Body must be a JSON object' } )
177+ } )
145178} )
0 commit comments