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' ; let app ; describe ( 'E2E - publicAPIRouter - Base PayID' , function ( ) : void { before ( async function ( ) { app = await appSetup ( ) ; } ) ; it ( 'Returns the correct MAINNET address for a known PayID' , function ( done ) : void { const payId = '/alice' ; const acceptHeader = 'application/xrpl-mainnet+json' ; const expectedResponse = { addresses : [ { paymentNetwork : 'XRPL' , environment : 'MAINNET' , addressDetailsType : 'CryptoAddressDetails' , addressDetails : { address : 'rw2ciyaNshpHe7bCHo4bRWq6pqqynnWKQg' , tag : '67298042' , } , } , ] , verifiedAddresses : [ ] , payId : 'alice$127.0.0.1' , version : '1.1' , } ; request ( app . publicApiExpress ) . get ( payId ) . set ( 'PayID-Version' , '1.1' ) . set ( 'Accept' , acceptHeader ) . expect ( ( res ) => { assert . strictEqual ( res . get ( 'Content-Type' ) . split ( '; ' ) [ 0 ] , acceptHeader ) ; } ) . expect ( HttpStatus . OK , expectedResponse , done ) ; } ) ; it ( 'Returns the correct TESTNET address for a known PayID' , function ( done ) : void { const payId = '/alice' ; const acceptHeader = 'application/xrpl-testnet+json' ; const expectedResponse = { addresses : [ { paymentNetwork : 'XRPL' , environment : 'TESTNET' , addressDetailsType : 'CryptoAddressDetails' , addressDetails : { address : 'rDk7FQvkQxQQNGTtfM2Fr66s7Nm3k87vdS' , } , } , ] , verifiedAddresses : [ ] , payId : 'alice$127.0.0.1' , version : '1.1' , } ; request ( app . publicApiExpress ) . get ( payId ) . set ( 'PayID-Version' , '1.1' ) . set ( 'Accept' , acceptHeader ) . expect ( ( res ) => { assert . strictEqual ( res . get ( 'Content-Type' ) . split ( '; ' ) [ 0 ] , acceptHeader ) ; } ) . expect ( HttpStatus . OK , expectedResponse , done ) ; } ) ; it ( 'Returns the correct address for a known PayID and a non-XRPL header' , function ( done ) : void { const payId = '/alice' ; const acceptHeader = 'application/btc-testnet+json' ; const expectedResponse = { addresses : [ { paymentNetwork : 'BTC' , environment : 'TESTNET' , addressDetailsType : 'CryptoAddressDetails' , addressDetails : { address : 'mxNEbRXokcdJtT6sbukr1CTGVx8Tkxk3DB' , } , } , ] , verifiedAddresses : [ ] , payId : 'alice$127.0.0.1' , version : '1.1' , } ; request ( app . publicApiExpress ) . get ( payId ) . set ( 'PayID-Version' , '1.1' ) . set ( 'Accept' , acceptHeader ) . expect ( ( res ) => { assert . strictEqual ( res . get ( 'Content-Type' ) . split ( '; ' ) [ 0 ] , acceptHeader ) ; } ) . expect ( HttpStatus . OK , expectedResponse , done ) ; } ) ; it ( 'Returns the correct address for a known PayID and an ACH header (no environment)' , function ( done ) : void { const payId = '/alice' ; const acceptHeader = 'application/ach+json' ; const expectedResponse = { addresses : [ { paymentNetwork : 'ACH' , addressDetailsType : 'FiatAddressDetails' , addressDetails : { accountNumber : '000123456789' , routingNumber : '123456789' , } , } , ] , verifiedAddresses : [ ] , payId : 'alice$127.0.0.1' , version : '1.1' , } ; request ( app . publicApiExpress ) . get ( payId ) . set ( 'PayID-Version' , '1.1' ) . set ( 'Accept' , acceptHeader ) . expect ( ( res ) => { assert . strictEqual ( res . get ( 'Content-Type' ) . split ( '; ' ) [ 0 ] , acceptHeader ) ; } ) . expect ( HttpStatus . OK , expectedResponse , done ) ; } ) ; it ( 'Returns a 404 with the correct error response object for an unknown PayID' , function ( done ) : void { const payId = '/johndoe' ; const acceptHeader = 'application/xrpl-testnet+json' ; const expectedErrorResponse = { statusCode : 404 , error : 'Not Found' , message : 'PayID johndoe$127.0.0.1 could not be found.' , } ; request ( app . publicApiExpress ) . get ( payId ) . set ( 'PayID-Version' , '1.1' ) . set ( 'Accept' , acceptHeader ) . expect ( 'Content-Type' , /application\/json/u ) . expect ( HttpStatus . NotFound , expectedErrorResponse , done ) ; } ) ; it ( 'Returns a 404 for a PayID without the relevant associated address' , function ( done ) : void { const payId = '/alice' ; const acceptHeader = 'application/xrpl-devnet+json' ; const expectedErrorResponse = { statusCode : 404 , error : 'Not Found' , message : 'Payment information for alice$127.0.0.1 could not be found.' , } ; request ( app . publicApiExpress ) . get ( payId ) . set ( 'PayID-Version' , '1.1' ) . set ( 'Accept' , acceptHeader ) . expect ( 'Content-Type' , /application\/json/u ) . expect ( HttpStatus . NotFound , expectedErrorResponse , done ) ; } ) ; it ( 'Returns a 404 for a PayID request with payid+json, when that PayID has been deleted' , function ( done ) : void { const payId = '/johndoe' ; const acceptHeader = 'application/payid+json' ; const expectedErrorResponse = { statusCode : 404 , error : 'Not Found' , message : 'PayID johndoe$127.0.0.1 could not be found.' , } ; request ( app . publicApiExpress ) . get ( payId ) . set ( 'PayID-Version' , '1.1' ) . set ( 'Accept' , acceptHeader ) . expect ( HttpStatus . NotFound , expectedErrorResponse , done ) ; } ) ; after ( function ( ) { appCleanup ( app ) ; } ) ; } ) ;