import tachijs , { controller , httpGet , SendFileResult } from '../../index' ; import request from 'supertest' ; import path from 'path' ; describe ( 'SendFileResult' , ( ) => { it ( 'uses res.sendFile' , async ( ) => { @ controller ( '/' ) class HomeController { @ httpGet ( '/' ) index ( ) { return new SendFileResult ( path . join ( __dirname , '../dummy/files/readme.md' ) ) ; } } const app = tachijs ( { controllers : [ HomeController ] } ) ; const response = await request ( app ) . get ( '/' ) ; expect ( response ) . toMatchObject ( { status : 200 , text : '# Test document\n' } ) ; } ) ; it ( 'accepts options' , async ( ) => { @ controller ( '/' ) class HomeController { @ httpGet ( '/' ) index ( ) { return new SendFileResult ( 'readme.md' , { root : path . join ( __dirname , '../dummy/files' ) } ) ; } } const app = tachijs ( { controllers : [ HomeController ] } ) ; const response = await request ( app ) . get ( '/' ) ; expect ( response ) . toMatchObject ( { status : 200 , text : '# Test document\n' } ) ; } ) ; it ( 'accepts callback' , async ( ) => { @ controller ( '/' ) class HomeController { @ httpGet ( '/' ) index ( ) { return new SendFileResult ( path . join ( __dirname , '../dummy/files/wrong.md' ) , undefined , ( error , req , res ) => { res . send ( error ! . message ) ; } ) ; } } const app = tachijs ( { controllers : [ HomeController ] } ) ; const response = await request ( app ) . get ( '/' ) ; expect ( response ) . toMatchObject ( { status : 200 , text : 'Not Found' } ) ; } ) ; it ( 'accepts status' , async ( ) => { @ controller ( '/' ) class HomeController { @ httpGet ( '/' ) index ( ) { return new SendFileResult ( path . join ( __dirname , '../dummy/files/readme.md' ) , undefined , undefined , 201 ) ; } } const app = tachijs ( { controllers : [ HomeController ] } ) ; const response = await request ( app ) . get ( '/' ) ; expect ( response ) . toMatchObject ( { status : 201 , text : '# Test document\n' } ) ; } ) ; it ( 'accepts headers' , async ( ) => { @ controller ( '/' ) class HomeController { @ httpGet ( '/' ) index ( ) { return new SendFileResult ( path . join ( __dirname , '../dummy/files/readme.md' ) , undefined , undefined , undefined , { test : 'test' } ) ; } } const app = tachijs ( { controllers : [ HomeController ] } ) ; const response = await request ( app ) . get ( '/' ) ; expect ( response ) . toMatchObject ( { status : 200 , text : '# Test document\n' , headers : { test : 'test' } } ) ; } ) ; } ) ;