Skip to content

Commit

Permalink
Merge pull request #19 from clout-stack/task/add-test-for-redirects
Browse files Browse the repository at this point in the history
add tests for redirects
  • Loading branch information
muhammaddadu authored Feb 18, 2020
2 parents 8db384b + d2c67ef commit 02c7de7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/e2e_redirect_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const should = require('should');
const testLib = require('./lib');
const request = testLib.request;

describe('e2e User Auth Tests', function () {
let clout;

before(() => {
process.env.PORT = 8420;
process.env.NODE_ENV = 'test';
clout = testLib.createInstance();
});

it('start server', (done) => {
clout.start();
clout.on('started', () => {
let server = clout.server['http'];
if (server) {
let port = server.address().port;
serverAddress = `http://localhost:${port}`;
}
done();
});
});

describe('/redirect', () => {
it('should give 302 /redirect/google', async () => {
const response = await request({ uri: `/redirect/google`, followRedirect: false });
should(response.statusCode).be.equal(302);
should(response.headers.location).be.equal('https://google.com');
});
});

after('stop server', (done) => {
clout.on('stopped', () => done());
clout.stop();
});
});
10 changes: 10 additions & 0 deletions test/fixed/kitchensink/controllers/redirect/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
path: '/redirect/google',
method: 'get',
description: `
Controller Example to demonstrate redirections
`,
fn: (req, resp) => {
return resp.redirect('https://google.com');
}
};

0 comments on commit 02c7de7

Please sign in to comment.