|
1 | 1 | import 'babel-polyfill'; |
2 | 2 | import expect from 'expect.js'; |
3 | | -import { prueUrl } from '../src/util'; |
| 3 | +import { prueUrl, parseUrl, parseRequest } from '../src/util'; |
4 | 4 |
|
5 | 5 | describe('test util methods', () => { |
6 | 6 | it('get prue url', async () => { |
7 | 7 | expect(prueUrl('http://www.baidu.com?')).to.eql('http://www.baidu.com'); |
8 | 8 | expect(prueUrl('http://www.baidu.com?ab=23')).to.eql('http://www.baidu.com'); |
9 | 9 | }); |
| 10 | + it('parse basic url', async () => { |
| 11 | + expect(parseUrl('http://www.baidu.com?')).to.eql({ |
| 12 | + url: 'http://www.baidu.com', |
| 13 | + params: {}, |
| 14 | + }); |
| 15 | + expect(parseUrl('http://www.baidu.com?ab=23')).to.eql({ |
| 16 | + url: 'http://www.baidu.com', |
| 17 | + params: { |
| 18 | + ab: '23', |
| 19 | + }, |
| 20 | + }); |
| 21 | + expect(parseUrl('http://www.baidu.com?ab=23&name=123')).to.eql({ |
| 22 | + url: 'http://www.baidu.com', |
| 23 | + params: { |
| 24 | + ab: '23', |
| 25 | + name: '123', |
| 26 | + }, |
| 27 | + }); |
| 28 | + }); |
| 29 | + it('parse error url', async () => { |
| 30 | + expect(parseUrl('http://www.baidu.com?a')).to.eql({ |
| 31 | + url: 'http://www.baidu.com', |
| 32 | + params: {}, |
| 33 | + }); |
| 34 | + expect(parseUrl('http://www.baidu.com?a??=1')).to.eql({ |
| 35 | + url: 'http://www.baidu.com', |
| 36 | + params: {}, |
| 37 | + }); |
| 38 | + expect(parseUrl('http://www.baidu.com?a=1?b=1')).to.eql({ |
| 39 | + url: 'http://www.baidu.com', |
| 40 | + params: { |
| 41 | + a: '1', |
| 42 | + }, |
| 43 | + }); |
| 44 | + }); |
| 45 | + it('parse encoded url', async () => { |
| 46 | + expect(parseUrl('http://www.baidu.com?callback=http%20%201')).to.eql({ |
| 47 | + url: 'http://www.baidu.com', |
| 48 | + params: { |
| 49 | + callback: 'http 1' |
| 50 | + }, |
| 51 | + }); |
| 52 | + }); |
| 53 | + it('parse request', async () => { |
| 54 | + expect(parseRequest('http://www.baidu.com?callback=http%20%201', { |
| 55 | + headers: { |
| 56 | + 'Content-Type': 'application/json', |
| 57 | + } |
| 58 | + })).to.eql({ |
| 59 | + method: 'GET', |
| 60 | + url: 'http://www.baidu.com', |
| 61 | + headers: { |
| 62 | + 'Content-Type': 'application/json', |
| 63 | + }, |
| 64 | + params: { |
| 65 | + callback: 'http 1' |
| 66 | + }, |
| 67 | + }); |
| 68 | + }); |
10 | 69 | }); |
0 commit comments