@@ -5,6 +5,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
55import request from 'supertest' ;
66import { createHandler } from './createHandler' ;
77import { Body , Delete , Get , Header , HttpCode , Post , Put , Query , Req , Res , Response , SetHeader } from './decorators' ;
8+ import { ValidationPipe } from './pipes' ;
89import { ParseBooleanPipe } from './pipes/parseBoolean.pipe' ;
910import { ParseNumberPipe } from './pipes/parseNumber.pipe' ;
1011
@@ -56,7 +57,7 @@ class TestHandler {
5657 @HttpCode ( 201 )
5758 @Post ( )
5859 @SetHeader ( 'X-Method' , 'create' )
59- public create ( @Header ( 'Content-Type' ) contentType : string , @Body ( ) body : CreateDto ) {
60+ public create ( @Header ( 'Content-Type' ) contentType : string , @Body ( ValidationPipe ) body : CreateDto ) {
6061 return { contentType, receivedBody : body , test : this . testField , instanceOf : body instanceof CreateDto } ;
6162 }
6263
@@ -77,7 +78,7 @@ class TestHandler {
7778 const { 'content-type' : contentType } = headers ;
7879 const { id } = query ;
7980
80- res . status ( 200 ) . json ( { contentType, id, receivedBody : body , test : this . testField } ) ;
81+ return res . status ( 200 ) . json ( { contentType, id, receivedBody : body , test : this . testField } ) ;
8182 }
8283}
8384
@@ -112,7 +113,7 @@ describe('E2E', () => {
112113 } )
113114 ) ) ;
114115
115- it ( 'read' , ( ) =>
116+ it ( 'read without "step" ' , ( ) =>
116117 request ( server )
117118 . get ( '/?id=my-id&redirect=true' )
118119 . set ( 'Content-Type' , 'application/json' )
@@ -222,4 +223,16 @@ describe('E2E', () => {
222223 }
223224 } )
224225 ) ) ;
226+
227+ it ( 'should throw express style 404 for an undefined http verb' , ( ) =>
228+ request ( server )
229+ . patch ( '/' )
230+ . set ( 'Content-Type' , 'application/json' )
231+ . expect ( 404 )
232+ . then ( res =>
233+ expect ( res . body ) . toMatchObject ( {
234+ statusCode : 404 ,
235+ error : 'Not Found'
236+ } )
237+ ) ) ;
225238} ) ;
0 commit comments