Skip to content

Commit

Permalink
test(integration): further integration tests
Browse files Browse the repository at this point in the history
integration tests for caching, gzipResponse, redirect
  • Loading branch information
wyvern8 committed Nov 2, 2017
1 parent f3e8bf0 commit d9dd92c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
20 changes: 5 additions & 15 deletions test/behaviors/caching.spec-int.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
import { before, describe, it } from 'mocha';
import { describe, it } from 'mocha';
import { expect } from 'chai';
import supertest from 'supertest';
import integration from './_integration.spec-int.js';

describe('BehaviorCpCode', () => {
describe('BehaviorCaching', () => {

let opts;
before( (done) => {
integration.behaviorConfig().then( (data) => {
opts = data['cpCode.papi.json'];
done();
});
});

describe('cpCode header', () => {
describe('caching header', () => {

let request = supertest(integration.urlPrefix);

it('should return the expected header', (done) => {

let header = opts.value.id + (opts.value.name ? '_' + opts.value.name.replace(' ', '_') : '');

request
.get(integration.behaviorTestUrl('cpCode.papi.json'))
.get(integration.behaviorTestUrl('caching.papi.json'))
.expect(200)
.end(function (err, res) {
expect(res.headers['x-aka-cpcode']).to.equal(header);
expect(res.headers['x-accel-expires']).to.equal('7200');
done();
});

Expand Down
28 changes: 9 additions & 19 deletions test/behaviors/gzipResponse.spec-int.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
import { describe, it } from 'mocha';
import { expect } from 'chai';
import supertest from 'supertest';
import integration from './_integration.spec-int.js';

describe('BehaviorDenyAccess', () => {
describe('BehaviorGzipResponse', () => {

describe('denyAccess enabled', () => {
describe('gzip header', () => {

let request = supertest(integration.urlPrefix);

it('should return denied status code', (done) => {
it('should return the expected header', (done) => {

request
.get(integration.behaviorTestUrl('denyAccess.enabled.papi.json'))
.expect(401)
.end(done);

});
});

describe('denyAccess disabled', () => {

let request = supertest(integration.urlPrefix);

it('should NOT return denied status code', (done) => {

request
.get(integration.behaviorTestUrl('denyAccess.disabled.papi.json'))
.get(integration.behaviorTestUrl('gzipResponse.papi.json'))
.expect(200)
.end(done);
.end(function (err, res) {
expect(res.headers['x-aka-gzipresponse']).to.equal('TODO_this_request_should_be_gzipped_by_proxy');
done();
});

});
});
Expand Down
8 changes: 4 additions & 4 deletions test/behaviors/modifyOutgoingResponseHeader.spec-int.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { expect } from 'chai';
import supertest from 'supertest';
import integration from './_integration.spec-int.js';

describe('BehaviorGzipResponse', () => {
describe('BehaviorModifyOutgoingResponseHeader', () => {

describe('gzip header', () => {
describe('response header', () => {

let request = supertest(integration.urlPrefix);

it('should return the expected header', (done) => {

request
.get(integration.behaviorTestUrl('gzipResponse.papi.json'))
.get(integration.behaviorTestUrl('modifyOutgoingResponseHeader.papi.json'))
.expect(200)
.end(function (err, res) {
expect(res.headers['x-aka-gzipresponse']).to.equal('TODO_this_request_should_be_gzipped_by_proxy');
expect(res.headers['strict-transport-security']).to.equal('max-age=31536000');
done();
});

Expand Down
3 changes: 2 additions & 1 deletion test/behaviors/redirect.path.papi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"queryString" : "APPEND",
"responseCode" : 301,
"destinationHostname" : "SAME_AS_REQUEST",
"destinationPath" : "/testredirect",
"destinationPath" : "OTHER",
"destinationPathOther": "/testredirect",
"destinationProtocol" : "HTTPS",
"mobileDefaultChoice" : "DEFAULT"
}
31 changes: 25 additions & 6 deletions test/behaviors/redirect.spec-int.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,38 @@ import { expect } from 'chai';
import supertest from 'supertest';
import integration from './_integration.spec-int.js';

describe('BehaviorGzipResponse', () => {
describe('BehaviorRedirect', () => {

describe('gzip header', () => {
describe('redirect to specific path on current domain', () => {

let request = supertest(integration.urlPrefix);

it('should return the expected header', (done) => {
it('should redirect to the correct location', (done) => {

request
.get(integration.behaviorTestUrl('gzipResponse.papi.json'))
.expect(200)
.get(integration.behaviorTestUrl('redirect.path.papi.json'))
.expect(301)
.end(function (err, res) {
expect(res.headers['x-aka-gzipresponse']).to.equal('TODO_this_request_should_be_gzipped_by_proxy');
expect(res.headers['location']).to.equal('https://localhost/testredirect?nocache=true');
done();
});

});
});

describe('redirect http to https', () => {

let request = supertest(integration.urlPrefix.replace('https', 'http'));

it('should redirect to the correct location', (done) => {

request
.get(integration.behaviorTestUrl('redirect.https.papi.json'))
.expect(301)
.end(function (err, res) {
expect(res.headers['location']).to.equal(
integration.urlPrefix + integration.behaviorTestUrl('redirect.https.papi.json')
);
done();
});

Expand Down

0 comments on commit d9dd92c

Please sign in to comment.