diff --git a/apps/common/behaviours/email.js b/apps/common/behaviours/email.js index fdaf7bb2..32c0510c 100644 --- a/apps/common/behaviours/email.js +++ b/apps/common/behaviours/email.js @@ -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 => { diff --git a/test/_unit/apps/collection/validation/validation.spec.js b/test/_unit/apps/collection/validation/validation.spec.js new file mode 100644 index 00000000..d97a8275 --- /dev/null +++ b/test/_unit/apps/collection/validation/validation.spec.js @@ -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']); + }); + }); + }); +}); diff --git a/test/_unit/apps/common/behaviours/email.spec.js b/test/_unit/apps/common/behaviours/email.spec.js index 9edbd0bf..d3163fb5 100644 --- a/test/_unit/apps/common/behaviours/email.spec.js +++ b/test/_unit/apps/common/behaviours/email.spec.js @@ -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'); @@ -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 => { diff --git a/test/_unit/apps/correct-mistakes/validation/validation.spec.js b/test/_unit/apps/correct-mistakes/validation/validation.spec.js new file mode 100644 index 00000000..07c8f591 --- /dev/null +++ b/test/_unit/apps/correct-mistakes/validation/validation.spec.js @@ -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']); + }); + }); + }); +}); diff --git a/test/_unit/apps/lost-stolen/validation/validation.spec.js b/test/_unit/apps/lost-stolen/validation/validation.spec.js new file mode 100644 index 00000000..97b527e7 --- /dev/null +++ b/test/_unit/apps/lost-stolen/validation/validation.spec.js @@ -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']); + }); + }); + }); +}); diff --git a/test/_unit/apps/not-arrived/validation/validation.spec.js b/test/_unit/apps/not-arrived/validation/validation.spec.js new file mode 100644 index 00000000..07f500ab --- /dev/null +++ b/test/_unit/apps/not-arrived/validation/validation.spec.js @@ -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']); + }); + }); + }); +}); diff --git a/test/_unit/apps/someone-else/validation/validation.spec.js b/test/_unit/apps/someone-else/validation/validation.spec.js new file mode 100644 index 00000000..b4e3b2d3 --- /dev/null +++ b/test/_unit/apps/someone-else/validation/validation.spec.js @@ -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']); + }); + }); + }); +});