import { assert } from 'chai' ; import { formatPaymentInfo } from '../../src/services/basePayId' ; import { AddressDetailsType } from '../../src/types/protocol' ; const version1dot1 = '1.1' ; describe ( 'Base PayID - formatPaymentInfo()' , function ( ) : void { it ( 'Returns CryptoAddressDetails & FiatAddressDetails for addressDetailsTypes when formatting array with multiple AddressInformation' , function ( ) { const payId = 'alice$example.com' ; const addressInfo = [ { paymentNetwork : 'XRP' , environment : 'TESTNET' , details : { address : 'rDk7FQvkQxQQNGTtfM2Fr66s7Nm3k87vdS' , } , } , { paymentNetwork : 'ACH' , environment : null , details : { accountNumber : '000123456789' , routingNumber : '123456789' , } , } , ] ; const expectedPaymentInfo = { payId : 'alice$example.com' , version : '1.1' , addresses : [ { paymentNetwork : 'XRP' , environment : 'TESTNET' , addressDetailsType : AddressDetailsType . CryptoAddress , addressDetails : { address : 'rDk7FQvkQxQQNGTtfM2Fr66s7Nm3k87vdS' , } , } , { paymentNetwork : 'ACH' , addressDetailsType : AddressDetailsType . FiatAddress , addressDetails : { accountNumber : '000123456789' , routingNumber : '123456789' , } , } , ] , verifiedAddresses : [ ] , } ; const paymentInfo = formatPaymentInfo ( addressInfo , [ ] , '' , version1dot1 , payId ) ; assert . deepStrictEqual ( paymentInfo , expectedPaymentInfo ) ; } ) ; it ( 'Does not return a environment field when it is not included in the address information' , function ( ) : void { const payId = 'alice$example.com' ; const version = '1.1' ; const addressInfo = [ { paymentNetwork : 'ACH' , environment : null , details : { accountNumber : '000123456789' , routingNumber : '123456789' , } , } , ] ; const expectedPaymentInfo = { addresses : [ { paymentNetwork : 'ACH' , addressDetailsType : AddressDetailsType . FiatAddress , addressDetails : { accountNumber : '000123456789' , routingNumber : '123456789' , } , } , ] , verifiedAddresses : [ ] , payId , version , } ; const paymentInfo = formatPaymentInfo ( addressInfo , [ ] , '' , version1dot1 , payId ) ; assert . deepStrictEqual ( paymentInfo , expectedPaymentInfo ) ; } ) ; it ( 'Returns a memo field when using a memo function that returns a truthy string' , function ( ) : void { const payId = 'alice$example.com' ; const addressInfo = [ { paymentNetwork : 'XRP' , environment : 'TESTNET' , details : { address : 'rDk7FQvkQxQQNGTtfM2Fr66s7Nm3k87vdS' , } , } , ] ; const expectedPaymentInfo = { addresses : [ { paymentNetwork : 'XRP' , environment : 'TESTNET' , addressDetailsType : AddressDetailsType . CryptoAddress , addressDetails : { address : 'rDk7FQvkQxQQNGTtfM2Fr66s7Nm3k87vdS' , } , } , ] , verifiedAddresses : [ ] , payId : 'alice$example.com' , memo : 'memo' , version : '1.1' , } ; const memoFn = ( ) : string => 'memo' ; const paymentInfo = formatPaymentInfo ( addressInfo , [ ] , '' , version1dot1 , payId , memoFn ) ; assert . deepStrictEqual ( paymentInfo , expectedPaymentInfo ) ; } ) ; } ) ;