Created
October 31, 2017 20:16
-
-
Save tanepiper/39103e9f1208ca5c8808d3894ef6cd95 to your computer and use it in GitHub Desktop.
Library test for node-bitly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const expect = require('chai').expect; | |
| require('sepia'); | |
| require('../test/bootstrap'); | |
| const { generateUrl, sortUrlsAndHash } = require('./lib'); | |
| describe('generateUrl', () => { | |
| it('should return a default url', () => { | |
| const result = generateUrl('iamatoken', 'foo'); | |
| expect(result.href).to.equal( | |
| 'https://api-ssl.bitly.com/v3/foo?access_token=iamatoken&domain=bit.ly&format=json' | |
| ); | |
| }); | |
| it('should return a custom url', () => { | |
| const result = generateUrl('iamatoken', 'foo', null, { | |
| apiUrl: 'api-ssl.myhost.com', | |
| apiVersion: 'v4' | |
| }); | |
| expect(result.href).to.equal( | |
| 'https://api-ssl.myhost.com/v4/foo?access_token=iamatoken&domain=bit.ly&format=json' | |
| ); | |
| }); | |
| }); | |
| describe('sortUrlsAndHash', () => { | |
| it('takes urls and hashes and appends them correctly', () => { | |
| const { shortUrl, hash } = sortUrlsAndHash(['http://example.com', '1KjIwXl']); | |
| expect(shortUrl.length).to.equal(1); | |
| expect(hash.length).to.equal(1); | |
| }); | |
| it('should never return falsy values', () => { | |
| const { shortUrl, hash } = sortUrlsAndHash([false, null, undefined]); | |
| expect(shortUrl.length).to.equal(0); | |
| expect(hash.length).to.equal(0); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment