import { request , Dino , Controller , ApiController , HttpGet , HttpPost } from './index' ; import { initializeTests } from './init' ; @ Controller ( '/test' ) class TestController extends ApiController { @ HttpGet ( '/:id' ) get ( id ) { return { data : id } ; } @ HttpGet ( '/:user/images/:img' ) getImg ( img , user ) { return { img : img , user : user } ; } @ HttpPost ( '/post' ) post ( body ) { return body ; } @ HttpPost ( '/add/:id' ) add ( body , id ) { return { body : body , id : id } ; } @ HttpGet ( '/optional/:id?' ) optional ( id ) { if ( id === undefined ) return { data : 'undefined' } ; return { data : id } ; } } describe ( 'segments.e2e.spec' , ( ) => { const baseRoute = '/api/test' ; function register ( dino ) { dino . registerController ( TestController ) ; dino . bind ( ) ; } it ( '/:id.returns_data' , done => { const x = initializeTests ( ) ; const app = x . app ; const dino = x . dino ; register ( dino ) ; request ( app ) . get ( `${ baseRoute }/22` ) . expect ( 'Content-Type' , /json/ ) . expect ( 200 , { data : '22' } , done ) ; } ) ; it ( '/:user/images/:img.returns_data' , done => { const x = initializeTests ( ) ; const app = x . app ; const dino = x . dino ; register ( dino ) ; request ( app ) . get ( `${ baseRoute }/john/images/45` ) . expect ( 'Content-Type' , /json/ ) . expect ( 200 , { img : '45' , user : 'john' } , done ) ; } ) ; it ( '/post.returns_data' , done => { const x = initializeTests ( ) ; const app = x . app ; const dino = x . dino ; register ( dino ) ; request ( app ) . post ( `${ baseRoute }/post` ) . send ( { name : 'john' } ) . expect ( 'Content-Type' , /json/ ) . expect ( 200 , { name : 'john' } , done ) ; } ) ; it ( '/add/:id.returns_data' , done => { const x = initializeTests ( ) ; const app = x . app ; const dino = x . dino ; register ( dino ) ; request ( app ) . post ( `${ baseRoute }/add/45` ) . send ( { name : 'john' } ) . expect ( 'Content-Type' , /json/ ) . expect ( 200 , { body : { name : 'john' } , id : '45' } , done ) ; } ) ; it ( '/optional/:id?.returns_data' , done => { const x = initializeTests ( ) ; const app = x . app ; const dino = x . dino ; register ( dino ) ; request ( app ) . get ( `${ baseRoute }/optional/22` ) . expect ( 'Content-Type' , /json/ ) . expect ( 200 , { data : '22' } , done ) ; } ) ; it ( '/optional/:id?.returns_undefined' , done => { const x = initializeTests ( ) ; const app = x . app ; const dino = x . dino ; register ( dino ) ; request ( app ) . get ( `${ baseRoute }/optional` ) . expect ( 'Content-Type' , /json/ ) . expect ( 200 , { data : 'undefined' } , done ) ; } ) ; } ) ;