import { assert } from 'chai' ; import 'mocha' ; import { parseAcceptHeader } from '../../src/services/headers' ; import { ParsedAcceptHeader } from '../../src/types/headers' ; import { ParseError } from '../../src/utils/errors' ; describe ( 'Parsing - Headers - parseAcceptHeader()' , function ( ) : void { it ( 'Parses a string with a valid media type' , function ( ) { const validAcceptMediaType = 'application/xrpl-testnet+json' ; const expectedParsedAcceptHeader = { mediaType : validAcceptMediaType , paymentNetwork : 'XRPL' , environment : 'TESTNET' , } ; const parsedAcceptHeader = parseAcceptHeader ( validAcceptMediaType ) ; assert . deepStrictEqual ( parsedAcceptHeader , expectedParsedAcceptHeader ) ; } ) ; it ( 'Parses a string with a valid media type without an environment' , function ( ) { const validAcceptMediaType = 'application/ach+json' ; const expectedParsedAcceptHeader = { mediaType : validAcceptMediaType , paymentNetwork : 'ACH' , } ; const parsedAcceptHeader = parseAcceptHeader ( validAcceptMediaType ) ; assert . deepStrictEqual ( parsedAcceptHeader , expectedParsedAcceptHeader ) ; } ) ; it ( 'Throws an error when parsing a string with an invalid media type' , function ( ) { const invalidAcceptMediaType = 'invalid-type' ; const invalidMediaTypeParse = ( ) : ParsedAcceptHeader => parseAcceptHeader ( invalidAcceptMediaType ) ; assert . throws ( invalidMediaTypeParse , ParseError , `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'
      ` ) ; } ) ; } ) ;