import { assert } from 'chai' ; import { getPreferredAddressHeaderPair } from '../../src/services/basePayId' ; import { AddressInformation } from '../../src/types/database' ; import { ParsedAcceptHeader } from '../../src/types/headers' ; describe ( 'Base PayID - getPreferredAddressInfo()' , function ( ) : void { let addressInfo ; let verifiedAddressInfo ; beforeEach ( function ( ) { addressInfo = [ { paymentNetwork : 'XRPL' , environment : 'TESTNET' , details : { address : 'rDk7FQvkQxQQNGTtfM2Fr66s7Nm3k87vdS' , } , } , { paymentNetwork : 'ACH' , environment : null , details : { accountNumber : '000123456789' , routingNumber : '123456789' , } , } , ] ; verifiedAddressInfo = [ { paymentNetwork : 'XRPL' , environment : 'TESTNET' , details : { address : 'rDk7FQvkQxQQNGTtfM2Fr66s7Nm3k87vdS' , } , } , { paymentNetwork : 'ETH' , environment : 'KOVAN' , details : { address : '0x43F14dFF256E8e44b839AE00BE8E0e02fA7D18Db' , } , } , ] ; } ) ; it ( 'Returns all addresses & payid media type if payment network is PAYID' , function ( ) { const acceptMediaTypes = [ { mediaType : 'application/payid+json' , paymentNetwork : 'PAYID' , } , ] ; const expectedAddressInfo = [ { mediaType : 'application/payid+json' , paymentNetwork : 'PAYID' , } , addressInfo , verifiedAddressInfo , ] ; const preferredAddressInfo = getPreferredAddressHeaderPair ( addressInfo , verifiedAddressInfo , acceptMediaTypes ) ; assert . deepStrictEqual ( preferredAddressInfo , expectedAddressInfo ) ; } ) ; it ( 'Returns the first order preferred address when found' , function ( ) { const acceptMediaTypes = [ { mediaType : 'application/xrpl-testnet+json' , environment : 'TESTNET' , paymentNetwork : 'XRPL' , } , ] ; const expectedAddressInfo = [ { mediaType : 'application/xrpl-testnet+json' , environment : 'TESTNET' , paymentNetwork : 'XRPL' , } , [ addressInfo [ 0 ] ] , [ verifiedAddressInfo [ 0 ] ] , ] ; const preferredAddressInfo = getPreferredAddressHeaderPair ( addressInfo , verifiedAddressInfo , acceptMediaTypes ) ; assert . deepStrictEqual ( preferredAddressInfo , expectedAddressInfo ) ; } ) ; it ( 'Returns the second order preferred address (unverified) when the first is not found' , function ( ) { const acceptMediaTypes = [ { mediaType : 'application/xrpl-mainnet+json' , environment : 'MAINNET' , paymentNetwork : 'XRPL' , } , { mediaType : 'application/ach+json' , paymentNetwork : 'ACH' , } , ] ; const expectedAddressInfo = [ { mediaType : 'application/ach+json' , paymentNetwork : 'ACH' , } , [ addressInfo [ 1 ] ] , [ ] , ] ; const preferredAddressInfo = getPreferredAddressHeaderPair ( addressInfo , verifiedAddressInfo , acceptMediaTypes ) ; assert . deepStrictEqual ( preferredAddressInfo , expectedAddressInfo ) ; } ) ; it ( 'Returns the second order preferred address (verified) when the first is not found' , function ( ) { const acceptMediaTypes = [ { mediaType : 'application/xrpl-mainnet+json' , environment : 'MAINNET' , paymentNetwork : 'XRPL' , } , { mediaType : 'application/eth-kovan+json' , environment : 'KOVAN' , paymentNetwork : 'ETH' , } , ] ; const expectedAddressInfo = [ { mediaType : 'application/eth-kovan+json' , environment : 'KOVAN' , paymentNetwork : 'ETH' , } , [ ] , [ verifiedAddressInfo [ 1 ] ] , ] ; const preferredAddressInfo = getPreferredAddressHeaderPair ( addressInfo , verifiedAddressInfo , acceptMediaTypes ) ; assert . deepStrictEqual ( preferredAddressInfo , expectedAddressInfo ) ; } ) ; it ( 'Returns undefined if no preferred address found' , function ( ) { const acceptMediaTypes = [ { mediaType : 'application/xrpl-mainnet+json' , environment : 'MAINNET' , paymentNetwork : 'XRPL' , } , ] ; const preferredAddressInfo = getPreferredAddressHeaderPair ( addressInfo , verifiedAddressInfo , acceptMediaTypes ) ; assert . deepStrictEqual ( preferredAddressInfo , [ undefined , [ ] , [ ] ] ) ; } ) ; } ) ;