import { assert } from 'chai' ; import 'mocha' ; import { urlToPayId } from '../../src/services/urls' ; describe ( 'Parsing - URLs - urlToPayId()' , function ( ) : void { it ( 'throws an error on inputs that are not HTTP/HTTPS' , function ( ) : void { const url = 'ftp://example.com/alice' ; const expectedErrorMessage = 'Invalid PayID URL protocol. PayID URLs must be HTTP/HTTPS.' ; const badConversion = ( ) : string => urlToPayId ( url ) ; assert . throws ( badConversion , expectedErrorMessage ) ; } ) ; it ( 'Handles an HTTPS PayID URL' , function ( ) : void { const url = 'https://example.com/alice' ; const expectedPayId = 'alice$example.com' ; const actualPayId = urlToPayId ( url ) ; assert . strictEqual ( actualPayId , expectedPayId ) ; } ) ; it ( 'Handles an HTTP PayID URL' , function ( ) : void { const url = 'http://example.com/alice' ; const expectedPayId = 'alice$example.com' ; const actualPayId = urlToPayId ( url ) ; assert . strictEqual ( actualPayId , expectedPayId ) ; } ) ; it ( 'throws an error on inputs that are not ASCII' , function ( ) : void { const url = 'https://hansbergren.example.संगठन' ; const expectedErrorMessage = 'Invalid PayID characters. PayIDs must be ASCII.' ; const badConversion = ( ) : string => urlToPayId ( url ) ; assert . throws ( badConversion , expectedErrorMessage ) ; } ) ; it ( 'throws an error on an invalid URL' , function ( ) : void { const url = 'https://example.com/badPath/alice' ; const expectedErrorMessage = 'Too many paths. The only paths allowed in a PayID are to specify the user.' ; const badConversion = ( ) : string => urlToPayId ( url ) ; assert . throws ( badConversion , expectedErrorMessage ) ; } ) ; it ( 'handles a PayID URL with a subdomain' , function ( ) : void { const url = 'https://payid.example.com/alice' ; const expectedPayId = 'alice$payid.example.com' ; const actualPayId = urlToPayId ( url ) ; assert . strictEqual ( actualPayId , expectedPayId ) ; } ) ; it ( 'handles a PayID URL with capital letters' , function ( ) : void { const url = 'https://example.com/ALICE' ; const expectedPayId = 'alice$example.com' ; const actualPayId = urlToPayId ( url ) ; assert . strictEqual ( actualPayId , expectedPayId ) ; } ) ; } ) ;