Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LEVWEB-1173] Test full marriage details #389

Merged
merged 13 commits into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const conf = {
env: process.env.NODE_ENV,
port: process.env.PORT || 8001,
listen_host: process.env.LISTEN_HOST || '0.0.0.0',
fullDetailsRoleName: 'full-details',
api: {
protocol: process.env.API_PROTOCOL || 'http',
host: process.env.API_PORT_8080_TCP_ADDR || process.env.API_HOST || 'localhost',
Expand Down
9 changes: 5 additions & 4 deletions controllers/marriage-details.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const conf = require('../config');
const api = require('../api');
const helpers = require('../lib/helpers');
const fields = require('../fields/marriage');
Expand All @@ -14,11 +15,12 @@ const handleError = (err, next) => {
return next(err instanceof Error ? err : new Error(err));
};

const showFullDetails = ri => !!ri.roles.filter(r => r === conf.fullDetailsRoleName).length;

module.exports = function renderDetails(req, res, next) {
req.params = req.params || {};
const systemNumber = req.params.sysnum;
const ri = reqInfo(req);
const fullDetails = ri.roles.filter(v => v === 'full-details').reduce((acc, val) => acc || val, false) && true;

if (systemNumber === undefined) {
return next(new ReferenceError('The parameter \'id\' was not defined'), req, res);
Expand All @@ -27,13 +29,12 @@ module.exports = function renderDetails(req, res, next) {
return next(new TypeError('The parameter \'id\' was not an integer'), req, res);
}

const accessToken = req.headers['X-Auth-Token'] || req.headers['x-auth-token'];
const canRedirectToResults = (req.query && req.query.multipleResults) !== undefined;

return api.findMarriageBySystemNumber(Number(systemNumber), accessToken)
return api.findMarriageBySystemNumber(Number(systemNumber), ri.token)
.then(result => res.render('pages/marriage-details', {
record: result,
showAll: fullDetails,
showAll: showFullDetails(ri),
querystring: helpers.serialize(_.pick(req.query, _.keys(fields))),
canRedirectToResults: canRedirectToResults
}),
Expand Down
5 changes: 3 additions & 2 deletions lib/req-info.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

module.exports = (req) => ({
module.exports = (req) => (req && req.headers && {
RobinKnipe marked this conversation as resolved.
Show resolved Hide resolved
token: req.headers['x-auth-token'],
username: req.headers['x-auth-username'],
client: req.headers['x-auth-aud'],
groups: req.headers['x-auth-groups'] && String(req.headers['x-auth-groups']).split(',') || [],
roles: req.headers['x-auth-roles'] && String(req.headers['x-auth-roles']).split(',') || []
});
}) || {};
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"acceptance:done": "rm -f ./.acceptance.waiting",
"watch:chimp": "nodemon -d 1 -w test/acceptance -w views -w .acceptance.trgr -w app.js -w config.js -w routes -w middleware -w locales -w lib -w fields -w controllers -w api -e js,json,html,trgr -x 'npm-run-all -s acceptance:wait chimp:check'",
"chimp:check": "[ -e ./.acceptance.lock ] && printf '\n==> NOTE: Waiting for linting and unit tests to complete before running E2E tests\n\n' || npm-run-all -s -c chimp acceptance:done",
"chimp": "NODE_ENV=acceptance chimp --mocha --browser=phantomjs --path=./test/acceptance/spec/",
"chimp:ff": "NODE_ENV=acceptance chimp --mocha --browser=firefox --path=./test/acceptance/spec/ --watch",
"smoke": "chimp --mocha --browser=phantomjs --path=./test/smoke/",
"chimp": "NODE_ENV=acceptance chimpy --mocha --browser=phantomjs --path=./test/acceptance/spec/",
"chimp:ff": "NODE_ENV=acceptance chimpy --mocha --browser=firefox --path=./test/acceptance/spec/ --watch",
"smoke": "chimpy --mocha --browser=phantomjs --path=./test/smoke/",
"test:browser": "npm run $([ -n \"${SMOKE_TEST}\" ] && echo smoke || echo chimp)",
"create:trigger": "touch ./.acceptance.trgr 2>/dev/null",
"lint": "eslint .",
Expand Down Expand Up @@ -82,7 +82,7 @@
"broken-link-checker": "^0.7.8",
"chai": "^3.5.0",
"chai-as-promised": "^5.3.0",
"chimp": "^0.51.1",
"chimpy": "^0.54.0",
"eslint": "^3.4.0",
"eslint-plugin-filenames": "^1.0.0",
"eslint-plugin-mocha": "^4.5.0",
Expand Down
5 changes: 4 additions & 1 deletion test/acceptance/expected-marriage-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ module.exports = {
signature: 'T. Bride'
},
fatherOfGroom: {
forenames: 'Test',
forenames: 'Test Fog',
surname: 'FATHER',
occupation: 'Father'
},
fatherOfBride: {
forenames: 'Test Fob',
surname: 'BRIDE',
occupation: 'Father'
RobinKnipe marked this conversation as resolved.
Show resolved Hide resolved
},
witness1: {
signature: 'A. Witness'
Expand Down
5 changes: 4 additions & 1 deletion test/acceptance/expected-marriage-records.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ module.exports = {
signature: 'T. Bride'
},
fatherOfGroom: {
forenames: 'Test',
forenames: 'Test Fog',
surname: 'FATHER',
occupation: 'Father'
},
fatherOfBride: {
forenames: 'Test Fob',
surname: 'BRIDE',
occupation: 'Father'
},
witness1: {
signature: 'A. Witness'
Expand Down
18 changes: 17 additions & 1 deletion test/acceptance/mixins/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ module.exports = (target) => {
this.submitMarriageSearchPage(systemNumber, surname, forenames, dom);
};

target.jsRefreshWithRoles = function (roles) {
this.jsRefreshWithHeaders({ 'X-Auth-Roles': roles });
};

target.jsRefreshWithHeaders = function(headers) {
this.execute((u, h) => {
/* eslint-env browser */
var client = new XMLHttpRequest();
client.open('GET', u, false);
Object.keys(h).forEach(key => client.setRequestHeader(key, h[key]));
client.send();
document.body.parentElement.innerHTML = client.responseText;
/* eslint-env node, mocha */
}, this.getUrl(), headers);
};
RobinKnipe marked this conversation as resolved.
Show resolved Hide resolved

target.goToSearchPage = function() {
this.url(url);
};
Expand Down Expand Up @@ -77,7 +93,7 @@ module.exports = (target) => {
this.click('input[type="submit"]');
};

target.submitBirthSearchPage = target.submitBirthSearchPage;
target.submitBirthSearchPage = target.submitSearchPage;

target.submitDeathSearchPage = function(systemNumber, surname, forenames, dobd) {
this.setValue('input[name="system-number"]', systemNumber);
Expand Down
107 changes: 98 additions & 9 deletions test/acceptance/spec/22-marriage-details.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

var expectedRecord = require('../expected-marriage-record');
var expectedRecords = require('../expected-marriage-records');
const expectedRecord = require('../expected-marriage-record');
const expectedRecords = require('../expected-marriage-records');
const role = require('../../../config').fullDetailsRoleName;

describe('Marriage details page', () => {
/* eslint-disable no-unused-vars */
Expand All @@ -19,6 +20,49 @@ describe('Marriage details page', () => {
};

const recordDisplayed = (record) => {
it('a limited version is displayed in a table', () => {
const rowTexts = browser.$$('table tr');
const tableText = browser.$('table').getText();
// Regexes used here as htmlunit and chrome differ in showing space so need regex to work with both
rowTexts[0].getText().should.match(new RegExp('System number *' + record.id));
rowTexts[1].getText().should.match(new RegExp('Date of marriage *' + record.dateOfMarriage));
rowTexts[2].getText().should.match(new RegExp('Place of marriage *' + record.placeOfMarriage));
rowTexts[4].getText().should.match(new RegExp('Surname *' + record.groom.surname));
rowTexts[5].getText().should.match(new RegExp('Forename\\(s\\) *' + record.groom.forenames));
tableText.should.not.match(new RegExp('Age *' + record.groom.age));
tableText.should.not.match(new RegExp('Occupation *' + record.groom.occupation));
rowTexts[6].getText().should.match(new RegExp('Address *' + record.groom.address));
tableText.should.not.match(new RegExp('Condition *' + record.groom.condition));
tableText.should.not.match(new RegExp('Signature *' + record.groom.signature));
rowTexts[8].getText().should.match(new RegExp('Surname *' + record.bride.surname));
rowTexts[9].getText().should.match(new RegExp('Forename\\(s\\) *' + record.bride.forenames));
tableText.should.not.match(new RegExp('Age *' + record.bride.age));
tableText.should.not.match(new RegExp('Occupation *' + record.bride.occupation));
rowTexts[10].getText().should.match(new RegExp('Address *' + record.bride.address));
tableText.should.not.match(new RegExp('Condition *' + record.bride.condition));
tableText.should.not.match(new RegExp('Signature *' + record.bride.signature));
tableText.should.not.match(new RegExp('Surname *' + record.fatherOfGroom.surname));
tableText.should.not.match(new RegExp(`Forename\\(s\\) *${record.fatherOfGroom.forenames} *Occupation`));
tableText.should.not.match(new RegExp('Occupation *' + record.fatherOfGroom.occupation));
tableText.should.not.match(new RegExp('Bride\s*Surname *' + record.fatherOfBride.surname));
tableText.should.not.match(new RegExp('Forename\\(s\\) *' + record.fatherOfBride.forenames));
tableText.should.not.match(new RegExp('Occupation *' + record.fatherOfBride.occupation));
tableText.should.not.match(new RegExp('Signature *' + record.witness1.signature));
tableText.should.not.match(new RegExp('Signature *' + record.witness2.signature));
tableText.should.not.match(new RegExp('Registrar signature *' + record.registrar.signature));
tableText.should.not.match(new RegExp('Registrar designation *' + record.registrar.designation));
tableText.should.not.match(new RegExp(
'Superintendent registrar signature *' + record.registrar.superintendentSignature));
tableText.should.not.match(new RegExp(
'Superintendent registrar designation *' + record.registrar.superintendentDesignation));
rowTexts[12].getText().should.match(new RegExp('District *' + record.registrar.district));
rowTexts[13].getText().should.match(new RegExp('Administrative area *' + record.registrar.administrativeArea));
rowTexts[14].getText().should.match(new RegExp('Date of registration *' + record.date));
tableText.should.not.match(new RegExp('Entry number *' + record.entryNumber));
});
};

const fullRecordDisplayed = (record) => {
it('the complete record is displayed in a table', () => {
const browserText = browser.$$('table tr');
// Regexes used here as htmlunit and chrome differ in showing space so need regex to work with both
Expand All @@ -27,13 +71,36 @@ describe('Marriage details page', () => {
browserText[2].getText().should.match(new RegExp('Place of marriage *' + record.placeOfMarriage));
browserText[4].getText().should.match(new RegExp('Surname *' + record.groom.surname));
browserText[5].getText().should.match(new RegExp('Forename\\(s\\) *' + record.groom.forenames));
browserText[6].getText().should.match(new RegExp('Address *' + record.groom.address));
browserText[8].getText().should.match(new RegExp('Surname *' + record.bride.surname));
browserText[9].getText().should.match(new RegExp('Forename\\(s\\) *' + record.bride.forenames));
browserText[10].getText().should.match(new RegExp('Address *' + record.bride.address));
browserText[12].getText().should.match(new RegExp('District *' + record.registrar.district));
browserText[13].getText().should.match(new RegExp('Administrative area *' + record.registrar.administrativeArea));
browserText[14].getText().should.match(new RegExp('Date of registration *' + record.date));
browserText[6].getText().should.match(new RegExp('Age *' + record.groom.age));
browserText[7].getText().should.match(new RegExp('Occupation *' + record.groom.occupation));
browserText[8].getText().should.match(new RegExp('Address *' + record.groom.address));
browserText[9].getText().should.match(new RegExp('Condition *' + record.groom.condition));
browserText[10].getText().should.match(new RegExp('Signature *' + record.groom.signature));
browserText[12].getText().should.match(new RegExp('Surname *' + record.bride.surname));
browserText[13].getText().should.match(new RegExp('Forename\\(s\\) *' + record.bride.forenames));
browserText[14].getText().should.match(new RegExp('Age *' + record.bride.age));
browserText[15].getText().should.match(new RegExp('Occupation *' + record.bride.occupation));
browserText[16].getText().should.match(new RegExp('Address *' + record.bride.address));
browserText[17].getText().should.match(new RegExp('Condition *' + record.bride.condition));
browserText[18].getText().should.match(new RegExp('Signature *' + record.bride.signature));
browserText[20].getText().should.match(new RegExp('Surname *' + record.fatherOfGroom.surname));
browserText[21].getText().should.match(new RegExp('Forename\\(s\\) *' + record.fatherOfGroom.forenames));
browserText[22].getText().should.match(new RegExp('Occupation *' + record.fatherOfGroom.occupation));
browserText[24].getText().should.match(new RegExp('Surname *' + record.fatherOfBride.surname));
browserText[25].getText().should.match(new RegExp('Forename\\(s\\) *' + record.fatherOfBride.forenames));
browserText[26].getText().should.match(new RegExp('Occupation *' + record.fatherOfBride.occupation));
browserText[28].getText().should.match(new RegExp('Signature *' + record.witness1.signature));
browserText[30].getText().should.match(new RegExp('Signature *' + record.witness2.signature));
browserText[32].getText().should.match(new RegExp('Registrar signature *' + record.registrar.signature));
browserText[33].getText().should.match(new RegExp('Registrar designation *' + record.registrar.designation));
browserText[34].getText().should.match(new RegExp(
'Superintendent registrar signature *' + record.registrar.superintendentSignature));
browserText[35].getText().should.match(new RegExp(
'Superintendent registrar designation *' + record.registrar.superintendentDesignation));
browserText[36].getText().should.match(new RegExp('District *' + record.registrar.district));
browserText[37].getText().should.match(new RegExp('Administrative area *' + record.registrar.administrativeArea));
browserText[38].getText().should.match(new RegExp('Date of registration *' + record.date));
browserText[39].getText().should.match(new RegExp('Entry number *' + record.entryNumber));
});
};

Expand All @@ -60,6 +127,17 @@ describe('Marriage details page', () => {
recordDisplayed(expectedRecord);
editSearchDisplayed();
backToSearchResultsNotDisplayed();

describe('which shows the full details to select users', () => {
// NOTE: anyone with the appropriate role should see the full info
before(() => browser.jsRefreshWithRoles([role]));

urlShouldContainDetails();
messageDisplayed(expectedRecord);
fullRecordDisplayed(expectedRecord);
editSearchDisplayed();
backToSearchResultsNotDisplayed();
});
});

describe('When there is more than one result', () => {
Expand All @@ -76,6 +154,17 @@ describe('Marriage details page', () => {
recordDisplayed(expectedRecords);
editSearchDisplayed();
backToSearchResultsDisplayed();

describe('which shows the full details to select users', () => {
// NOTE: anyone with the appropriate role should see the full info
before(() => browser.jsRefreshWithRoles([role]));

urlShouldContainDetails();
messageDisplayed(expectedRecords);
fullRecordDisplayed(expectedRecords);
editSearchDisplayed();
backToSearchResultsNotDisplayed();
});
});

describe('When I select the "New search" button', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/api/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ describe('api/helpers.js', () => {
});

describe('processRecord()', () => {
it('is a function', () => (typeof helpers.processRecord).should.equal('function'));
it('is a function', () => helpers.processRecord.should.be.a('function'));
it('takes one argument', () => helpers.processRecord.should.have.lengthOf(1));

describe('when called with an argument that is a valid record', () => {
Expand Down
8 changes: 4 additions & 4 deletions test/unit/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('api/index.js', () => {
});

describe('findByNameDOB()', () => {
it('is a function', () => (typeof api.findByNameDOB).should.equal('function'));
it('is a function', () => api.findByNameDOB.should.be.a('function'));
it('takes two arguments', () => api.findByNameDOB.should.have.lengthOf(2));

describe('when called with no arguments', () => {
Expand Down Expand Up @@ -265,7 +265,7 @@ describe('api/index.js', () => {
});

describe('findBirths()', () => {
it('is a function', () => (typeof api.findBirths).should.equal('function'));
it('is a function', () => api.findBirths.should.be.a('function'));
it('takes two arguments', () => api.findBirths.should.have.lengthOf(2));

describe('when called with no arguments', () => {
Expand Down Expand Up @@ -448,7 +448,7 @@ describe('api/index.js', () => {
});

describe('findBySystemNumber()', () => {
it('is a function', () => (typeof api.findBySystemNumber).should.equal('function'));
it('is a function', () => api.findBySystemNumber.should.be.a('function'));
it('takes two arguments', () => api.findBySystemNumber.should.have.lengthOf(2));

describe('when called with no arguments', () => {
Expand Down Expand Up @@ -544,7 +544,7 @@ describe('api/index.js', () => {
});

describe('userActivityReport()', () => {
it('is a function', () => (typeof api.userActivityReport).should.equal('function'));
it('is a function', () => api.userActivityReport.should.be.a('function'));
it('should throw a ReferenceError when no parameters are provided', () => {
expect(api.userActivityReport).to.throw(ReferenceError);
});
Expand Down
Loading