|
| 1 | +var expect = require('chai').expect; |
| 2 | +var OAuth = require('../oauth-1.0a'); |
| 3 | + |
| 4 | +describe('OAuth.parseUrl', function() { |
| 5 | + |
| 6 | + it('should parse protocol', function () { |
| 7 | + expect(OAuth.parseUrl('http://example.com/').protocol).to.equal('http'); |
| 8 | + expect(OAuth.parseUrl('https://example.com/').protocol).to.equal('https'); |
| 9 | + }); |
| 10 | + |
| 11 | + it('should parse auth component', function () { |
| 12 | + expect(OAuth.parseUrl('http://example.com/').auth).to.equal(''); |
| 13 | + expect(OAuth.parseUrl('http://foo:[email protected]/').auth).to.equal('foo:bar@'); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should parse hostname component', function () { |
| 17 | + expect(OAuth.parseUrl('http://example.com/').hostname).to.equal('example.com'); |
| 18 | + expect(OAuth.parseUrl('http://example.com:8080/').hostname).to.equal('example.com'); |
| 19 | + expect(OAuth.parseUrl('http://foo:[email protected]/').hostname).to.equal('example.com'); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should parse port component', function () { |
| 23 | + expect(OAuth.parseUrl('http://example.com/').port).to.equal(''); |
| 24 | + expect(OAuth.parseUrl('http://example.com:80/').port).to.equal(':80'); |
| 25 | + expect(OAuth.parseUrl('http://foo:[email protected]:80/').port).to.equal(':80'); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should parse pathname component', function () { |
| 29 | + expect(OAuth.parseUrl('http://example.com').pathname).to.equal(''); |
| 30 | + expect(OAuth.parseUrl('http://example.com/').pathname).to.equal('/'); |
| 31 | + expect(OAuth.parseUrl('http://example.com/foo/bar').pathname).to.equal('/foo/bar'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should parse search component', function () { |
| 35 | + expect(OAuth.parseUrl('http://example.com').search).to.equal(''); |
| 36 | + expect(OAuth.parseUrl('http://example.com/?foo').search).to.equal('?foo'); |
| 37 | + expect(OAuth.parseUrl('http://example.com/?foo#bar').search).to.equal('?foo'); |
| 38 | + expect(OAuth.parseUrl('http://example.com/?foo?bar').search).to.equal('?foo?bar'); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should parse hash component', function () { |
| 42 | + expect(OAuth.parseUrl('http://example.com').hash).to.equal(''); |
| 43 | + expect(OAuth.parseUrl('http://example.com/?foo').hash).to.equal(''); |
| 44 | + expect(OAuth.parseUrl('http://example.com/?foo#bar').hash).to.equal('#bar'); |
| 45 | + }); |
| 46 | +}); |
0 commit comments