import 'mocha' ; import HttpStatus from '@xpring-eng/http-status' ; import * as request from 'supertest' ; import App from '../../../../src/app' ; import config , { adminApiVersions } from '../../../../src/config' ; import { appSetup , appCleanup } from '../../../helpers/helpers' ; let app ; describe ( 'E2E - adminApiRouter - Version Headers' , function ( ) : void { before ( async function ( ) { app = await appSetup ( ) ; } ) ; it ( 'Returns a 400 - Bad Request when we omit a PayID-API-Version header' , function ( done ) : void { const payId = 'alice$xpring.money' ; const expectedErrorResponse = { statusCode : 400 , error : 'Bad Request' , message : "A PayID-API-Version header is required in the request, of the form 'PayID-API-Version: YYYY-MM-DD'." , } ; request ( app . adminApiExpress ) . get ( `/users/${ payId }` ) . expect ( 'PayID-API-Server-Version' , config . app . adminApiVersion ) . expect ( 'Content-Type' , /json/u ) . expect ( HttpStatus . BadRequest , expectedErrorResponse , done ) ; } ) ; it ( 'Returns a 400 - Bad Request when we provide a malformed PayID-API-Version header' , function ( done ) : void { const payId = 'alice$xpring.money' ; const payIdApiVersion = 'a-b-c' ; const expectedErrorResponse = { statusCode : 400 , error : 'Bad Request' , message : "A PayID-API-Version header must be in the form 'PayID-API-Version: YYYY-MM-DD'." , } ; request ( app . adminApiExpress ) . get ( `/users/${ payId }` ) . set ( 'PayID-API-Version' , payIdApiVersion ) . expect ( 'PayID-API-Server-Version' , config . app . adminApiVersion ) . expect ( 'Content-Type' , /json/u ) . expect ( HttpStatus . BadRequest , expectedErrorResponse , done ) ; } ) ; it ( 'Returns a 400 - Bad Request when we provide an unsupported PayID-API-Version header (less than first Version cut)' , function ( done ) : void { const payId = 'alice$xpring.money' ; const payIdApiVersion = '2020-05-27' ; const expectedErrorResponse = { statusCode : 400 , error : 'Bad Request' , message : `The PayID-API-Version ${ payIdApiVersion } is not supported, please try upgrading your request to at least 'PayID-API-Version: ${ adminApiVersions [ 0 ] }'` , } ; request ( app . adminApiExpress ) . get ( `/users/${ payId }` ) . set ( 'PayID-API-Version' , payIdApiVersion ) . expect ( 'PayID-API-Server-Version' , config . app . adminApiVersion ) . expect ( 'Content-Type' , /json/u ) . expect ( HttpStatus . BadRequest , expectedErrorResponse , done ) ; } ) ; it ( 'Returns a 200 - OK when we provide a valid PayID-Version header' , function ( done ) : void { const payId = 'alice$xpring.money' ; request ( app . adminApiExpress ) . get ( `/users/${ payId }` ) . set ( 'PayID-API-Version' , config . app . adminApiVersion ) . expect ( 'PayID-API-Server-Version' , config . app . adminApiVersion ) . expect ( 'Content-Type' , /json/u ) . expect ( HttpStatus . OK , done ) ; } ) ; after ( function ( ) { appCleanup ( app ) ; } ) ; } ) ;