Skip to content

Instantly share code, notes, and snippets.

@tanepiper
Created October 31, 2017 20:16
Show Gist options
  • Select an option

  • Save tanepiper/39103e9f1208ca5c8808d3894ef6cd95 to your computer and use it in GitHub Desktop.

Select an option

Save tanepiper/39103e9f1208ca5c8808d3894ef6cd95 to your computer and use it in GitHub Desktop.
Library test for node-bitly
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