generated from companieshouse/node-review-web-starter-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from companieshouse/IDVA5-467-which-name-is-re…
…gistered-with-AML IDVA5-467 which name is registered with AML
- Loading branch information
Showing
10 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"nameRegisteredWithAmlTitle" : "Which name is registered with your Anti-Money Laundering (AML) supervisory body? welsh", | ||
"nameRegisteredWithAmlBody": "We'll check this matches what the AML supervisory body holds welsh", | ||
"nameRegisteredWithAmlNameOfTheBusinessOption": "Name of the business welsh", | ||
"nameRegisteredWithAmlYourNameOption": "Your name welsh", | ||
"nameRegisteredWithAmlBothOption": "Both welsh", | ||
"nameRegisteredWithAmlContinueBtn": "Continue welsh", | ||
|
||
"error-nameRegisteredWithAmlSelectRadio" : "Select which name is registered welsh" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"nameRegisteredWithAmlTitle" : "Which name is registered with your Anti-Money Laundering (AML) supervisory body?", | ||
"nameRegisteredWithAmlBody": "We'll check this matches what the AML supervisory body holds", | ||
"nameRegisteredWithAmlNameOfTheBusinessOption": "Name of the business", | ||
"nameRegisteredWithAmlYourNameOption": "Your name", | ||
"nameRegisteredWithAmlBothOption": "Both", | ||
"nameRegisteredWithAmlContinueBtn": "Continue", | ||
|
||
"error-nameRegisteredWithAmlSelectRadio" : "Select which name is registered" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/controllers/features/limited/nameRegisteredWithAmlController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { NextFunction, Request, Response, Router } from "express"; | ||
import { validationResult } from "express-validator"; | ||
import * as config from "../../../config"; | ||
import { FormattedValidationErrors, formatValidationError } from "../../../validation/validation"; | ||
import { selectLang, addLangToUrl, getLocalesService, getLocaleInfo } from "../../../utils/localise"; | ||
import { SOLE_TRADER_SECTOR_YOU_WORK_IN, LIMITED_NAME_REGISTERED_WITH_AML, LIMITED_WHAT_IS_YOUR_ROLE, BASE_URL } from "../../../types/pageURL"; | ||
|
||
export const get = async (req: Request, res: Response, next: NextFunction) => { | ||
const lang = selectLang(req.query.lang); | ||
const locales = getLocalesService(); | ||
res.render(config.LIMITED_NAME_REGISTERED_WITH_AML, { | ||
previousPage: addLangToUrl(BASE_URL + LIMITED_WHAT_IS_YOUR_ROLE, lang), | ||
title: "Which name is registered with your AML supervisory body?", | ||
...getLocaleInfo(locales, lang), | ||
currentUrl: BASE_URL + LIMITED_NAME_REGISTERED_WITH_AML | ||
}); | ||
}; | ||
|
||
export const post = async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const lang = selectLang(req.query.lang); | ||
const locales = getLocalesService(); | ||
const errorList = validationResult(req); | ||
if (!errorList.isEmpty()) { | ||
const pageProperties = getPageProperties(formatValidationError(errorList.array(), lang)); | ||
res.status(400).render(config.LIMITED_NAME_REGISTERED_WITH_AML, { | ||
previousPage: addLangToUrl(BASE_URL + LIMITED_WHAT_IS_YOUR_ROLE, lang), | ||
title: "Which name is registered with your AML supervisory body?", | ||
...getLocaleInfo(locales, lang), | ||
currentUrl: BASE_URL + LIMITED_NAME_REGISTERED_WITH_AML, | ||
...pageProperties | ||
}); | ||
} else { | ||
const nextPageUrl = addLangToUrl(BASE_URL + SOLE_TRADER_SECTOR_YOU_WORK_IN, lang); | ||
res.redirect(nextPageUrl); | ||
} | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
const getPageProperties = (errors?: FormattedValidationErrors) => ({ | ||
errors | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { body } from "express-validator"; | ||
|
||
export const nameRegisteredWithAmlValidator = [ | ||
body("nameRegisteredWithAml", "nameRegisteredWithAmlSelectRadio").notEmpty() | ||
]; |
58 changes: 58 additions & 0 deletions
58
src/main/views/features/limited/name-registered-with-aml/name-registered-with-aml.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{% from "govuk/components/radios/macro.njk" import govukRadios %} | ||
{% extends "layouts/default.njk" %} | ||
|
||
{% block main_content %} | ||
|
||
<main> | ||
<form action="" method="POST"> | ||
{% include "partials/user_name.njk" %} | ||
<div class="govuk-form-group"> | ||
{{ govukRadios({ | ||
errorMessage: errors.nameRegisteredWithAml if errors, | ||
classes: "govuk-radios", | ||
id: "name-registered-with-aml-radios", | ||
name: "nameRegisteredWithAml", | ||
fieldset: { | ||
legend: { | ||
text: i18n.nameRegisteredWithAmlTitle, | ||
isPageHeading: true, | ||
classes: "govuk-fieldset__legend--l" | ||
} | ||
}, | ||
hint: { | ||
text: i18n.nameRegisteredWithAmlBody | ||
}, | ||
items: [ | ||
{ | ||
value: "NAME_OF_THE_BUSINESS", | ||
text: i18n.nameRegisteredWithAmlNameOfTheBusinessOption, | ||
checked: name-registered-with-aml == NAME_OF_THE_BUSINESS, | ||
attributes: { | ||
"data-event-id": "name-of-the-business-option" | ||
} | ||
}, | ||
{ | ||
value: "YOUR_NAME", | ||
text: i18n.nameRegisteredWithAmlYourNameOption, | ||
checked: name-registered-with-aml == YOUR_NAME, | ||
attributes: { | ||
"data-event-id": "your-company-option" | ||
} | ||
}, | ||
{ | ||
value: "BOTH", | ||
text: i18n.nameRegisteredWithAmlBothOption, | ||
checked: name-registered-with-aml == BOTH, | ||
attributes: { | ||
"data-event-id": "both-option" | ||
} | ||
} | ||
] | ||
}) }} | ||
</div> | ||
<button class="govuk-button">{{i18n.nameRegisteredWithAmlContinueBtn}}</button> | ||
</form> | ||
</main> | ||
|
||
|
||
{% endblock main_content %} |
23 changes: 23 additions & 0 deletions
23
src/test/src/controllers/nameRegisteredWithAmlController.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import supertest from "supertest"; | ||
import app from "../../../main/app"; | ||
import { LIMITED_NAME_REGISTERED_WITH_AML, BASE_URL } from "../../../main/types/pageURL"; | ||
const router = supertest(app); | ||
|
||
describe("GET" + LIMITED_NAME_REGISTERED_WITH_AML, () => { | ||
it("should return status 200", async () => { | ||
await router.get(BASE_URL + LIMITED_NAME_REGISTERED_WITH_AML).expect(200); | ||
}); | ||
}); | ||
|
||
// Test when radio btn selected, will return 302 after redirecting to the next page. | ||
describe("POST" + LIMITED_NAME_REGISTERED_WITH_AML, () => { | ||
it("should return status 302 after redirect", async () => { | ||
await router.post(BASE_URL + LIMITED_NAME_REGISTERED_WITH_AML).send({ nameRegisteredWithAml: "NAME_OF_THE_BUSINESS" }).expect(302); | ||
}); | ||
}); | ||
// Test for no radio btn value selected, will return 400. | ||
describe("POST" + LIMITED_NAME_REGISTERED_WITH_AML, () => { | ||
it("should return status 400 after incorrect data entered", async () => { | ||
await router.post(BASE_URL + LIMITED_NAME_REGISTERED_WITH_AML).send({ nameRegisteredWithAml: "" }).expect(400); | ||
}); | ||
}); |