import tachijs , { controller , httpGet , EndResult } from '../../index' ; import request from 'supertest' ; describe ( 'EndResult' , ( ) => { it ( 'uses res.end' , async ( ) => { @ controller ( '/' ) class HomeController { @ httpGet ( '/' ) index ( ) { return new EndResult ( 'Hello' ) ; } } const app = tachijs ( { controllers : [ HomeController ] } ) ; const response = await request ( app ) . get ( '/' ) ; expect ( response ) . toMatchObject ( { status : 200 , text : 'Hello' } ) ; } ) ; it ( 'accepts encoding' , async ( ) => { @ controller ( '/' ) class HomeController { @ httpGet ( '/' ) index ( ) { return new EndResult ( 'Hello' , 'ascii' ) ; } } const app = tachijs ( { controllers : [ HomeController ] } ) ; const response = await request ( app ) . get ( '/' ) ; expect ( response ) . toMatchObject ( { status : 200 , text : 'Hello' } ) ; } ) ; it ( 'accepts status' , async ( ) => { @ controller ( '/' ) class HomeController { @ httpGet ( '/' ) index ( ) { return new EndResult ( 'Hello' , undefined , 201 ) ; } } const app = tachijs ( { controllers : [ HomeController ] } ) ; const response = await request ( app ) . get ( '/' ) ; expect ( response ) . toMatchObject ( { status : 201 , text : 'Hello' } ) ; } ) ; it ( 'accepts headers' , async ( ) => { @ controller ( '/' ) class HomeController { @ httpGet ( '/' ) index ( ) { return new EndResult ( 'Hello' , undefined , undefined , { test : 'test' } ) ; } } const app = tachijs ( { controllers : [ HomeController ] } ) ; const response = await request ( app ) . get ( '/' ) ; expect ( response ) . toMatchObject ( { status : 200 , text : 'Hello' , headers : { test : 'test' } } ) ; } ) ; } ) ;