import 'mocha' ; import HttpStatus from '@xpring-eng/http-status' ; import { assert } from 'chai' ; import * as request from 'supertest' ; import App from '../../../../src/app' ; import { appSetup , appCleanup } from '../../../helpers/helpers' ; import { XRPL_TESTNET_ADDRESS , XRPL_TESTNET_ACCEPT_HEADER , XRPL_MAINNET_ACCEPT_HEADER , SIGNATURE , } from './payloads' ; let app ; const USER = '/johnwick' ; const PAYID = `${ USER . slice ( 1 ) }$127.0.0.1` ; const VERSION = '1.1' ; const XRPL_EXPECTED_TESTNET_RESPONSE = { addresses : [ ] , verifiedAddresses : [ { signatures : [ SIGNATURE ] , payload : JSON . stringify ( { payId : PAYID , payIdAddress : XRPL_TESTNET_ADDRESS , } ) , } , ] , payId : PAYID , version : VERSION , } ; describe ( 'E2E - publicAPIRouter - Verifiable PayId Content Negotiation' , function ( ) : void { before ( async function ( ) { app = await appSetup ( ) ; } ) ; it ( 'Returns the first address for multiple types with no q' , function ( done ) : void { const acceptHeader = `${ XRPL_TESTNET_ACCEPT_HEADER }, ${ XRPL_MAINNET_ACCEPT_HEADER }` ; request ( app . publicApiExpress ) . get ( USER ) . set ( 'PayID-Version' , VERSION ) . set ( 'Accept' , acceptHeader ) . expect ( ( res ) => { assert . strictEqual ( res . get ( 'Content-Type' ) . split ( '; ' ) [ 0 ] , XRPL_TESTNET_ACCEPT_HEADER ) ; } ) . expect ( HttpStatus . OK , XRPL_EXPECTED_TESTNET_RESPONSE , done ) ; } ) ; it ( 'Returns the preferred available address where the higher q is at the beginning' , function ( done ) : void { const acceptHeader = `${ XRPL_TESTNET_ACCEPT_HEADER }; q=1.1, ${ XRPL_MAINNET_ACCEPT_HEADER }; q=0.5` ; request ( app . publicApiExpress ) . get ( USER ) . set ( 'PayID-Version' , VERSION ) . set ( 'Accept' , acceptHeader ) . expect ( ( res ) => { assert . strictEqual ( res . get ( 'Content-Type' ) . split ( '; ' ) [ 0 ] , XRPL_TESTNET_ACCEPT_HEADER ) ; } ) . expect ( HttpStatus . OK , XRPL_EXPECTED_TESTNET_RESPONSE , done ) ; } ) ; it ( 'Returns the preferred available address where the higher q is at the end' , function ( done ) : void { const acceptHeader = `${ XRPL_MAINNET_ACCEPT_HEADER }; q=0.5, ${ XRPL_TESTNET_ACCEPT_HEADER }; q=1.1` ; request ( app . publicApiExpress ) . get ( USER ) . set ( 'PayID-Version' , VERSION ) . set ( 'Accept' , acceptHeader ) . expect ( ( res ) => { assert . strictEqual ( res . get ( 'Content-Type' ) . split ( '; ' ) [ 0 ] , XRPL_TESTNET_ACCEPT_HEADER ) ; } ) . expect ( HttpStatus . OK , XRPL_EXPECTED_TESTNET_RESPONSE , done ) ; } ) ; it ( 'Returns a valid address when the most preferred type does not exist' , function ( done ) : void { const nonExistentAcceptType = 'application/fakenetwork-fakenet+json' ; const acceptHeader = `${ nonExistentAcceptType }; q=1.1, ${ XRPL_MAINNET_ACCEPT_HEADER }; q=0.5, ${ XRPL_TESTNET_ACCEPT_HEADER }; q=0.9` ; request ( app . publicApiExpress ) . get ( USER ) . set ( 'PayID-Version' , VERSION ) . set ( 'Accept' , acceptHeader ) . expect ( ( res ) => { assert . strictEqual ( res . get ( 'Content-Type' ) . split ( '; ' ) [ 0 ] , XRPL_TESTNET_ACCEPT_HEADER ) ; } ) . expect ( HttpStatus . OK , XRPL_EXPECTED_TESTNET_RESPONSE , done ) ; } ) ; after ( function ( ) { appCleanup ( app ) ; } ) ; } ) ;