1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-27 10:48:22 +00:00

Added tests form url parser

This commit is contained in:
Vladimir Volek 2019-02-28 16:13:09 +01:00
parent 0278c3bb19
commit ff400d9ca9
2 changed files with 16 additions and 1 deletions

View File

@ -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&param2=hah')).toEqual({ address: 'www.trezor.io/TT', param1: 'aha', param2: 'hah' });
});
});

View File

@ -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<string> = 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,
};