Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhodine-orleans-lindsay committed May 12, 2022
1 parent 7614bad commit a3a72c3
Show file tree
Hide file tree
Showing 7 changed files with 353 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/common/behaviours/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const serviceMap = {
return {
template: 'delivery',
subject: 'Form submitted: Your BRP hasn\'t arrived. Ref: ' + setRef(data) +
'(Application Type: ' + appType(data) + ')'
' (Application Type: ' + appType(data) + ')'
};
},
'/correct-mistakes': data => {
Expand Down
59 changes: 59 additions & 0 deletions test/_unit/apps/collection/validation/validation.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

const Controller = require('hof').controller;

const DummyController = class DummyControllerBase extends Controller {
configure(req, res, next) {
super.configure(req, res, next);
}
};
describe('apps/collection/fields/application-type', () => {
let controller;
let req;
let res;

beforeEach(() => {
req = reqres.req();
res = reqres.res();

req.form.options = {};

controller = new DummyController({ template: 'index', route: '/index' });
});

describe('validation', () => {
let sandbox;

beforeEach(() => {
sandbox = sinon.createSandbox();
req.form.options.fields = {
'application-type': {
validate: ['required']
},
'application-type-other': {
validate: ['required']
}
};
});

afterEach(() => {
sandbox.restore();
});

it('adds a `required` validator if the application type is not selected', () => {
req.sessionModel.set('application-type');
controller.configure(req, res, () => {
req.form.options.fields['application-type'].should.have.property('validate');
expect(req.form.options.fields['application-type'].validate).to.deep.eql(['required' ]);
});
});

it('adds a`required` validator to the `other` input box', () => {
req.sessionModel.set('application-type', 'other');
controller.configure(req, res, () => {
req.form.options.fields['application-type-other'].should.have.property('validate');
expect(req.form.options.fields['application-type-other'].validate).to.deep.eql([ 'required']);
});
});
});
});
58 changes: 57 additions & 1 deletion test/_unit/apps/common/behaviours/email.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('apps/common/controllers/confirm', () => {
});
});

it('sets errors in the subject for the correct mistakes journey', () => {
it('sets errors and application type in the subject for the correct mistakes journey', () => {
req.baseUrl = '/correct-mistakes';
req.sessionModel.set('test-error-checkbox', 'true');
req.sessionModel.set('test-error', 'testerror');
Expand All @@ -111,6 +111,62 @@ describe('apps/common/controllers/confirm', () => {
});
});

it('sets application type in the subject for the collection journey', () => {
req.baseUrl = '/collection';
req.sessionModel.set('submission-reference', 'fpgyxSgw7');
req.sessionModel.set('application-type', 'study-academic-visit');
controller.saveValues(req, res, err => {
expect(err).not.to.be.ok;
setStub.should.have.been.calledWith('subject',
'Form submitted: Report a collection problem. Ref: fpgyxSgw7 (Application Type: Study/Academic Visit)');
});
});

it('sets application type in the subject for the lost-stolen journey', () => {
req.baseUrl = '/lost-stolen';
req.sessionModel.set('submission-reference', 'fpgyxSgw7');
req.sessionModel.set('application-type', 'graduate');
controller.saveValues(req, res, err => {
expect(err).not.to.be.ok;
setStub.should.have.been.calledWith('subject',
'Form submitted: Report a lost or stolen BRP. Ref: fpgyxSgw7 (Application Type: Graduate)');
});
});

it('sets application type in the subject for the not-arrived journey', () => {
req.baseUrl = '/not-arrived';
req.sessionModel.set('submission-reference', 'fpgyxSgw7');
req.sessionModel.set('application-type', 'joining-family-human-rights');
controller.saveValues(req, res, err => {
expect(err).not.to.be.ok;
setStub.should.have.been.calledWith('subject',
'Form submitted: Your BRP hasn\'t arrived. Ref: fpgyxSgw7 (Application Type: Joining Family/Human Rights)');
});
});

it('sets application type in the subject for the someone-else journey', () => {
req.baseUrl = '/someone-else';
req.sessionModel.set('submission-reference', 'fpgyxSgw7');
req.sessionModel.set('application-type', 'business');
controller.saveValues(req, res, err => {
expect(err).not.to.be.ok;
setStub.should.have.been.calledWith('subject',
'Form submitted: Report someone else collecting your BRP. Ref: fpgyxSgw7 (Application Type: Business)');
});
});

it('sets freetext in the subject if the application type is `Other`', () => {
req.baseUrl = '/collection';
req.sessionModel.set('submission-reference', 'fpgyxSgw7');
req.sessionModel.set('application-type', 'other');
req.sessionModel.set('application-type-other', 'Test');
controller.saveValues(req, res, err => {
expect(err).not.to.be.ok;
setStub.should.have.been.calledWith('subject',
'Form submitted: Report a collection problem. Ref: fpgyxSgw7 (Application Type: Other - Test)');
});
});

it('throws an error if its not part of a recognised journey', () => {
req.baseUrl = '/unrecognised-journey';
controller.saveValues(req, res, err => {
Expand Down
59 changes: 59 additions & 0 deletions test/_unit/apps/correct-mistakes/validation/validation.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

const Controller = require('hof').controller;

const DummyController = class DummyControllerBase extends Controller {
configure(req, res, next) {
super.configure(req, res, next);
}
};
describe('apps/correct-mistakes/fields/application-type', () => {
let controller;
let req;
let res;

beforeEach(() => {
req = reqres.req();
res = reqres.res();

req.form.options = {};

controller = new DummyController({ template: 'index', route: '/index' });
});

describe('validation', () => {
let sandbox;

beforeEach(() => {
sandbox = sinon.createSandbox();
req.form.options.fields = {
'application-type': {
validate: ['required']
},
'application-type-other': {
validate: ['required']
}
};
});

afterEach(() => {
sandbox.restore();
});

it('adds a `required` validator if the application type is not selected', () => {
req.sessionModel.set('application-type');
controller.configure(req, res, () => {
req.form.options.fields['application-type'].should.have.property('validate');
expect(req.form.options.fields['application-type'].validate).to.deep.eql(['required' ]);
});
});

it('adds a`required` validator to the `other` input box', () => {
req.sessionModel.set('application-type', 'other');
controller.configure(req, res, () => {
req.form.options.fields['application-type-other'].should.have.property('validate');
expect(req.form.options.fields['application-type-other'].validate).to.deep.eql([ 'required']);
});
});
});
});
59 changes: 59 additions & 0 deletions test/_unit/apps/lost-stolen/validation/validation.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

const Controller = require('hof').controller;

const DummyController = class DummyControllerBase extends Controller {
configure(req, res, next) {
super.configure(req, res, next);
}
};
describe('apps/lost-stolen/fields/application-type', () => {
let controller;
let req;
let res;

beforeEach(() => {
req = reqres.req();
res = reqres.res();

req.form.options = {};

controller = new DummyController({ template: 'index', route: '/index' });
});

describe('validation', () => {
let sandbox;

beforeEach(() => {
sandbox = sinon.createSandbox();
req.form.options.fields = {
'application-type': {
validate: ['required']
},
'application-type-other': {
validate: ['required']
}
};
});

afterEach(() => {
sandbox.restore();
});

it('adds a `required` validator if the application type is not selected', () => {
req.sessionModel.set('application-type');
controller.configure(req, res, () => {
req.form.options.fields['application-type'].should.have.property('validate');
expect(req.form.options.fields['application-type'].validate).to.deep.eql(['required' ]);
});
});

it('adds a`required` validator to the `other` input box', () => {
req.sessionModel.set('application-type', 'other');
controller.configure(req, res, () => {
req.form.options.fields['application-type-other'].should.have.property('validate');
expect(req.form.options.fields['application-type-other'].validate).to.deep.eql([ 'required']);
});
});
});
});
59 changes: 59 additions & 0 deletions test/_unit/apps/not-arrived/validation/validation.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

const Controller = require('hof').controller;

const DummyController = class DummyControllerBase extends Controller {
configure(req, res, next) {
super.configure(req, res, next);
}
};
describe('apps/not-arrived/fields/application-type', () => {
let controller;
let req;
let res;

beforeEach(() => {
req = reqres.req();
res = reqres.res();

req.form.options = {};

controller = new DummyController({ template: 'index', route: '/index' });
});

describe('validation', () => {
let sandbox;

beforeEach(() => {
sandbox = sinon.createSandbox();
req.form.options.fields = {
'application-type': {
validate: ['required']
},
'application-type-other': {
validate: ['required']
}
};
});

afterEach(() => {
sandbox.restore();
});

it('adds a `required` validator if the application type is not selected', () => {
req.sessionModel.set('application-type');
controller.configure(req, res, () => {
req.form.options.fields['application-type'].should.have.property('validate');
expect(req.form.options.fields['application-type'].validate).to.deep.eql(['required' ]);
});
});

it('adds a`required` validator to the `other` input box', () => {
req.sessionModel.set('application-type', 'other');
controller.configure(req, res, () => {
req.form.options.fields['application-type-other'].should.have.property('validate');
expect(req.form.options.fields['application-type-other'].validate).to.deep.eql([ 'required']);
});
});
});
});
59 changes: 59 additions & 0 deletions test/_unit/apps/someone-else/validation/validation.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

const Controller = require('hof').controller;

const DummyController = class DummyControllerBase extends Controller {
configure(req, res, next) {
super.configure(req, res, next);
}
};
describe('apps/someone-else/fields/application-type', () => {
let controller;
let req;
let res;

beforeEach(() => {
req = reqres.req();
res = reqres.res();

req.form.options = {};

controller = new DummyController({ template: 'index', route: '/index' });
});

describe('validation', () => {
let sandbox;

beforeEach(() => {
sandbox = sinon.createSandbox();
req.form.options.fields = {
'application-type': {
validate: ['required']
},
'application-type-other': {
validate: ['required']
}
};
});

afterEach(() => {
sandbox.restore();
});

it('adds a `required` validator if the application type is not selected', () => {
req.sessionModel.set('application-type');
controller.configure(req, res, () => {
req.form.options.fields['application-type'].should.have.property('validate');
expect(req.form.options.fields['application-type'].validate).to.deep.eql(['required' ]);
});
});

it('adds a`required` validator to the `other` input box', () => {
req.sessionModel.set('application-type', 'other');
controller.configure(req, res, () => {
req.form.options.fields['application-type-other'].should.have.property('validate');
expect(req.form.options.fields['application-type-other'].validate).to.deep.eql([ 'required']);
});
});
});
});

0 comments on commit a3a72c3

Please sign in to comment.