import * as httpRequest from 'supertest' ; const API_HTTP_ADDRESS = 'http://localhost:3000' ; export interface ProtoRoute { baseRoute : string ; queryParams ? : { [ param ] : string ; } ; } param protoRoute export function constructRoute ( protoRoute ) { const queryArray = protoRoute . queryParams ? Object . entries ( protoRoute . queryParams ) : [ ] ; if ( ! queryArray . length ) { return protoRoute . baseRoute ; } const stringifiedQueryParams = queryArray . map ( ( [ param , value ] ) => `${ param }=${ value }` ) . join ( '&' ) ; return `${ protoRoute . baseRoute }?${ stringifiedQueryParams }` ; } param input export async function httpGetAsync ( input ) { return httpRequest ( input . app || input . baseURL || API_HTTP_ADDRESS ) . get ( input . route ) ; } param input export async function httpPostAsync ( input ) { const request = httpRequest ( input . app || input . baseURL || API_HTTP_ADDRESS ) . post ( input . route ) . send ( input . body ) ; if ( input . headers ) { for ( const [ field , value ] of Object . entries ( input . headers ) ) { request . set ( field , value ) ; } } return request ; }