@@ -15,23 +15,23 @@ describe('Validation examples', () => {
1515 } ) ;
1616
1717 it ( '/testGet returns 200' , async ( ) => {
18- const { text } = await supertest ( 'localhost:3000 ' )
18+ const { text } = await supertest ( 'localhost:3210 ' )
1919 . get ( '/testGet?keyNumber=2' )
2020 . expect ( 200 ) ;
2121
2222 text . should . eql ( JSON . stringify ( { } ) ) ;
2323 } ) ;
2424
2525 it ( '/testGet returns 400' , async ( ) => {
26- const { text } = await supertest ( 'localhost:3000 ' )
26+ const { text } = await supertest ( 'localhost:3210 ' )
2727 . get ( '/testGet?keyNumber=somestring' )
2828 . expect ( 400 ) ;
2929
3030 text . should . equal ( JSON . stringify ( { keyNumber : '"keyNumber" must be a number' } ) ) ;
3131 } ) ;
3232
3333 it ( '/testPost returns 200' , async ( ) => {
34- const { text } = await supertest ( 'localhost:3000 ' )
34+ const { text } = await supertest ( 'localhost:3210 ' )
3535 . post ( '/testPost' )
3636 . send ( { keyNumber : 2 } )
3737 . expect ( 200 ) ;
@@ -40,11 +40,35 @@ describe('Validation examples', () => {
4040 } ) ;
4141
4242 it ( '/testPost returns 400' , async ( ) => {
43- const { text } = await supertest ( 'localhost:3000 ' )
43+ const { text } = await supertest ( 'localhost:3210 ' )
4444 . post ( '/testPost' )
4545 . send ( { keyNumber : 'somestring' } )
4646 . expect ( 400 ) ;
4747
4848 text . should . equal ( JSON . stringify ( { keyNumber : '"keyNumber" must be a number' } ) ) ;
4949 } ) ;
50+
51+ it ( '/testParams/:id/:name returns 200 with coerced params' , async ( ) => {
52+ const { body } = await supertest ( 'localhost:3210' )
53+ . get ( '/testParams/123/john' )
54+ . expect ( 200 ) ;
55+
56+ body . should . eql ( { id : 123 , name : 'john' } ) ;
57+ } ) ;
58+
59+ it ( '/testParams/:id returns 200 with optional param missing' , async ( ) => {
60+ const { body } = await supertest ( 'localhost:3210' )
61+ . get ( '/testParams/456' )
62+ . expect ( 200 ) ;
63+
64+ body . should . eql ( { id : 456 } ) ;
65+ } ) ;
66+
67+ it ( '/testParams/:id returns 400 when id is not a number' , async ( ) => {
68+ const { text } = await supertest ( 'localhost:3210' )
69+ . get ( '/testParams/notanumber' )
70+ . expect ( 400 ) ;
71+
72+ text . should . equal ( JSON . stringify ( { id : '"id" must be a number' } ) ) ;
73+ } ) ;
5074} ) ;
0 commit comments