[short url] Cleanup

This commit is contained in:
Jonathan Budzenski 2016-03-21 10:09:35 -05:00
parent 690a140a1b
commit 49d297fd55
2 changed files with 28 additions and 27 deletions

View file

@ -5,7 +5,7 @@ import ngMock from 'ng_mock';
import chrome from 'ui/chrome';
import LibUrlShortenerProvider from 'ui/share/lib/url_shortener';
describe('Url shortener', function () {
describe('Url shortener', () => {
let $rootScope;
let $location;
let $http;
@ -21,14 +21,14 @@ describe('Url shortener', function () {
urlShortener = Private(LibUrlShortenerProvider);
}));
describe('Shorten without base path', function () {
describe('Shorten without base path', () => {
it('should shorten urls with a port', function (done) {
$httpBackend.when('POST', '/shorten').respond(function (type, route, data) {
expect(JSON.parse(data).url).to.be('/app/kibana#123');
return [200, shareId];
});
urlShortener.shortenUrl('http://localhost:5601/app/kibana#123').then(function (url) {
expect(url).to.be('http://localhost:5601/goto/id123');
expect(url).to.be(`http://localhost:5601/goto/${shareId}`);
done();
});
$httpBackend.flush();
@ -40,84 +40,84 @@ describe('Url shortener', function () {
return [200, shareId];
});
urlShortener.shortenUrl('http://localhost/app/kibana#123').then(function (url) {
expect(url).to.be('http://localhost/goto/id123');
expect(url).to.be(`http://localhost/goto/${shareId}`);
done();
});
$httpBackend.flush();
});
});
describe('Shorten with base path', function () {
describe('Shorten with base path', () => {
const basePath = '/foo';
let getBasePath;
beforeEach(ngMock.inject(function (Private) {
beforeEach(ngMock.inject((Private) => {
getBasePath = sinon.stub(chrome, 'getBasePath', () => basePath);
urlShortener = Private(LibUrlShortenerProvider);
}));
it('should shorten urls with a port', function (done) {
$httpBackend.when('POST', `${basePath}/shorten`).respond(function (type, route, data) {
it('should shorten urls with a port', (done) => {
$httpBackend.when('POST', `${basePath}/shorten`).respond((type, route, data) => {
expect(JSON.parse(data).url).to.be('/app/kibana#123');
return [200, shareId];
});
urlShortener.shortenUrl(`http://localhost:5601${basePath}/app/kibana#123`).then(function (url) {
expect(url).to.be(`http://localhost:5601${basePath}/goto/id123`);
urlShortener.shortenUrl(`http://localhost:5601${basePath}/app/kibana#123`).then((url) => {
expect(url).to.be(`http://localhost:5601${basePath}/goto/${shareId}`);
done();
});
$httpBackend.flush();
});
it('should shorten urls without a port', function (done) {
$httpBackend.when('POST', `${basePath}/shorten`).respond(function (type, route, data) {
it('should shorten urls without a port', (done) => {
$httpBackend.when('POST', `${basePath}/shorten`).respond((type, route, data) => {
expect(JSON.parse(data).url).to.be('/app/kibana#123');
return [200, shareId];
});
urlShortener.shortenUrl(`http://localhost${basePath}/app/kibana#123`).then(function (url) {
expect(url).to.be(`http://localhost${basePath}/goto/id123`);
urlShortener.shortenUrl(`http://localhost${basePath}/app/kibana#123`).then((url) => {
expect(url).to.be(`http://localhost${basePath}/goto/${shareId}`);
done();
});
$httpBackend.flush();
});
it('should shorten urls with a query string', function (done) {
$httpBackend.when('POST', `${basePath}/shorten`).respond(function (type, route, data) {
it('should shorten urls with a query string', (done) => {
$httpBackend.when('POST', `${basePath}/shorten`).respond((type, route, data) => {
expect(JSON.parse(data).url).to.be('/app/kibana?foo#123');
return [200, shareId];
});
urlShortener.shortenUrl(`http://localhost${basePath}/app/kibana?foo#123`).then(function (url) {
expect(url).to.be(`http://localhost${basePath}/goto/id123`);
urlShortener.shortenUrl(`http://localhost${basePath}/app/kibana?foo#123`).then((url) => {
expect(url).to.be(`http://localhost${basePath}/goto/${shareId}`);
done();
});
$httpBackend.flush();
});
it('should shorten urls without a hash', function (done) {
$httpBackend.when('POST', `${basePath}/shorten`).respond(function (type, route, data) {
it('should shorten urls without a hash', (done) => {
$httpBackend.when('POST', `${basePath}/shorten`).respond((type, route, data) => {
expect(JSON.parse(data).url).to.be('/app/kibana');
return [200, shareId];
});
urlShortener.shortenUrl(`http://localhost${basePath}/app/kibana`).then(function (url) {
expect(url).to.be(`http://localhost${basePath}/goto/id123`);
urlShortener.shortenUrl(`http://localhost${basePath}/app/kibana`).then((url) => {
expect(url).to.be(`http://localhost${basePath}/goto/${shareId}`);
done();
});
$httpBackend.flush();
});
it('should shorten urls with a query string in the hash', function (done) {
it('should shorten urls with a query string in the hash', (done) => {
const relativeUrl = "/app/kibana#/discover?_g=(refreshInterval:(display:Off,pause:!f,value:0),time:(from:now-15m,mode:quick,to:now))&_a=(columns:!(_source),index:%27logstash-*%27,interval:auto,query:(query_string:(analyze_wildcard:!t,query:%27*%27)),sort:!(%27@timestamp%27,desc))"; //eslint-disable-line max-len, quotes
$httpBackend.when('POST', `${basePath}/shorten`).respond(function (type, route, data) {
$httpBackend.when('POST', `${basePath}/shorten`).respond((type, route, data) => {
expect(JSON.parse(data).url).to.be(relativeUrl);
return [200, shareId];
});
urlShortener.shortenUrl(`http://localhost${basePath}${relativeUrl}`).then(function (url) {
expect(url).to.be(`http://localhost${basePath}/goto/id123`);
urlShortener.shortenUrl(`http://localhost${basePath}${relativeUrl}`).then((url) => {
expect(url).to.be(`http://localhost${basePath}/goto/${shareId}`);
done();
});
$httpBackend.flush();
});
afterEach(function () {
afterEach(() => {
getBasePath.restore();
});
});

View file

@ -1,5 +1,6 @@
import chrome from 'ui/chrome';
import url from 'url';
export default function createUrlShortener(Notifier, $http, $location) {
const notify = new Notifier({
location: 'Url Shortener'