From a612a0ed956f1b8bfa4f11fe3b20edc76ca483d0 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Mon, 21 Mar 2016 10:30:12 -0500 Subject: [PATCH] [short url] Add server tests --- src/server/http/__tests__/index.js | 90 ++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 22 deletions(-) diff --git a/src/server/http/__tests__/index.js b/src/server/http/__tests__/index.js index 3d2ac386b13f..f9f72f89e2bc 100644 --- a/src/server/http/__tests__/index.js +++ b/src/server/http/__tests__/index.js @@ -1,41 +1,87 @@ import expect from 'expect.js'; import * as kbnTestServer from '../../../../test/utils/kbn_server'; +import fromRoot from '../../../utils/from_root'; + +describe('routes', function () { + this.slow(10000); + this.timeout(60000); -describe('cookie validation', function () { let kbnServer; beforeEach(function () { - kbnServer = kbnTestServer.createServer(); + kbnServer = kbnTestServer.createServer({ + plugins: { + scanDirs: [ + fromRoot('src/plugins') + ] + } + }); return kbnServer.ready(); }); afterEach(function () { return kbnServer.close(); }); - it('allows non-strict cookies', function (done) { - const options = { - method: 'GET', - url: '/', - headers: { - cookie: 'test:80=value;test_80=value' - } - }; - kbnTestServer.makeRequest(kbnServer, options, (res) => { - expect(res.payload).not.to.contain('Invalid cookie header'); - done(); + describe('cookie validation', function () { + it('allows non-strict cookies', function (done) { + const options = { + method: 'GET', + url: '/', + headers: { + cookie: 'test:80=value;test_80=value' + } + }; + kbnTestServer.makeRequest(kbnServer, options, (res) => { + expect(res.payload).not.to.contain('Invalid cookie header'); + done(); + }); + }); + + it('returns an error if the cookie can\'t be parsed', function (done) { + const options = { + method: 'GET', + url: '/', + headers: { + cookie: 'a' + } + }; + kbnTestServer.makeRequest(kbnServer, options, (res) => { + expect(res.payload).to.contain('Invalid cookie header'); + done(); + }); }); }); - it('returns an error if the cookie can\'t be parsed', function (done) { - const options = { - method: 'GET', - url: '/', - headers: { - cookie: 'a' + describe('url shortener', () => { + const shortenOptions = { + method: 'POST', + url: '/shorten', + payload: { + url: '/app/kibana#/visualize/create' } }; - kbnTestServer.makeRequest(kbnServer, options, (res) => { - expect(res.payload).to.contain('Invalid cookie header'); - done(); + + it('generates shortened urls', (done) => { + kbnTestServer.makeRequest(kbnServer, shortenOptions, (res) => { + expect(typeof res.payload).to.be('string'); + expect(res.payload.length > 0).to.be(true); + done(); + }); + }); + + it('redirects shortened urls', (done) => { + kbnTestServer.makeRequest(kbnServer, shortenOptions, (res) => { + const gotoOptions = { + method: 'GET', + url: '/goto/' + res.payload + }; + kbnTestServer.makeRequest(kbnServer, gotoOptions, (res) => { + expect(res.statusCode).to.be(302); + expect(res.headers.location).to.be(shortenOptions.payload.url); + done(); + }); + }); }); + }); + });