import { assert } from 'chai' ; import 'mocha' ; import { parseAcceptHeaders } from '../../src/services/headers' ; import { ParsedAcceptHeader } from '../../src/types/headers' ; import { ParseError } from '../../src/utils/errors' ; describe ( 'Parsing - Headers - parseAcceptHeaders()' , function ( ) : void { it ( 'Parses a list with a valid media type strings' , function ( ) { const validAcceptMediaType1 = 'application/xrpl-testnet+json' ; const validAcceptMediaType2 = 'application/xrpl-mainnet+json' ; const expectedParsedAcceptHeader1 = { mediaType : validAcceptMediaType1 , paymentNetwork : 'XRPL' , environment : 'TESTNET' , } ; const expectedParsedAcceptHeader2 = { mediaType : validAcceptMediaType2 , paymentNetwork : 'XRPL' , environment : 'MAINNET' , } ; const parsedAcceptHeaders = parseAcceptHeaders ( [ validAcceptMediaType1 , validAcceptMediaType2 , ] ) ; assert . deepStrictEqual ( parsedAcceptHeaders [ 0 ] , expectedParsedAcceptHeader1 ) ; assert . deepStrictEqual ( parsedAcceptHeaders [ 1 ] , expectedParsedAcceptHeader2 ) ; } ) ; it ( 'Throws an error on an empty list of media types' , function ( ) { const expectedError = `Missing Accept Header. Must have an Accept header of the form "application/{payment_network}(-{environment})+json".
      Examples:
      - 'Accept: application/xrpl-mainnet+json'
      - 'Accept: application/btc-testnet+json'
      - 'Accept: application/ach+json'
      - 'Accept: application/payid+json'
      ` ; const invalidMediaTypeParse = ( ) : ParsedAcceptHeader => parseAcceptHeaders ( [ ] ) [ 0 ] ; assert . throws ( invalidMediaTypeParse , ParseError , expectedError ) ; } ) ; it ( 'Throws an error if the list contains an invalid media type' , function ( ) { const invalidAcceptMediaType = 'invalid-type' ; const validAcceptMediaType = 'application/xrpl-testnet+json' ; const expectedError = `Invalid Accept Header. Must have an Accept header of the form "application/{payment_network}(-{environment})+json".
      Examples:
      - 'Accept: application/xrpl-mainnet+json'
      - 'Accept: application/btc-testnet+json'
      - 'Accept: application/ach+json'
      - 'Accept: application/payid+json'
      ` ; const invalidMediaTypeParse = ( ) : ParsedAcceptHeader => parseAcceptHeaders ( [ invalidAcceptMediaType , validAcceptMediaType ] ) [ 0 ] ; assert . throws ( invalidMediaTypeParse , ParseError , expectedError ) ; } ) ; } ) ;