From ff400d9ca98ef19ede5938eb4d9bca0332aeb99d Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Thu, 28 Feb 2019 16:13:09 +0100 Subject: [PATCH] Added tests form url parser --- src/utils/__tests__/cryptoUriParser.js | 11 +++++++++++ src/utils/cryptoUriParser.js | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/utils/__tests__/cryptoUriParser.js diff --git a/src/utils/__tests__/cryptoUriParser.js b/src/utils/__tests__/cryptoUriParser.js new file mode 100644 index 00000000..4ba4aa80 --- /dev/null +++ b/src/utils/__tests__/cryptoUriParser.js @@ -0,0 +1,11 @@ +import * as utils from '../cryptoUriParser'; + +describe('crypto uri parser', () => { + it('parseUri', () => { + expect(utils.parseUri('http://www.trezor.io')).toEqual({ address: '//www.trezor.io' }); // TODO: Error in function + expect(utils.parseUri('www.trezor.io')).toEqual({ address: 'www.trezor.io' }); + expect(utils.parseUri('www.trezor.io/TT')).toEqual({ address: 'www.trezor.io/TT' }); + expect(utils.parseUri('www.trezor.io/TT?param1=aha')).toEqual({ address: 'www.trezor.io/TT', param1: 'aha' }); + expect(utils.parseUri('www.trezor.io/TT?param1=aha¶m2=hah')).toEqual({ address: 'www.trezor.io/TT', param1: 'aha', param2: 'hah' }); + }); +}); diff --git a/src/utils/cryptoUriParser.js b/src/utils/cryptoUriParser.js index defb6a4f..0e0a77fd 100644 --- a/src/utils/cryptoUriParser.js +++ b/src/utils/cryptoUriParser.js @@ -10,7 +10,7 @@ export type parsedURI = { }; // Parse a string read from a bitcoin QR code into an object -export const parseUri = (uri: string): ?parsedURI => { +const parseUri = (uri: string): ?parsedURI => { const str = stripPrefix(uri); const query: Array = str.split('?'); const values: Object = (query.length > 1) ? parseQuery(query[1]) : {}; @@ -37,3 +37,7 @@ const parseQuery = (str: string): {} => str.split('&') } return vals; }, {}); + +export { + parseUri, +}; \ No newline at end of file