diff --git a/src/app.constants.ts b/src/app.constants.ts index d4ffe1e1ff..43bfd1389e 100644 --- a/src/app.constants.ts +++ b/src/app.constants.ts @@ -30,7 +30,6 @@ export const PATH_NAMES = { CREATE_ACCOUNT_ENTER_PHONE_NUMBER: "/enter-phone-number", CREATE_ACCOUNT_SUCCESSFUL: "/account-created", CHECK_YOUR_PHONE: "/check-your-phone", - SHARE_INFO: "/share-info", UPDATED_TERMS_AND_CONDITIONS: "/updated-terms-and-conditions", ENTER_MFA: "/enter-code", SECURITY_CODE_INVALID: "/security-code-invalid", diff --git a/src/app.ts b/src/app.ts index c18cb24926..12856bf9e7 100644 --- a/src/app.ts +++ b/src/app.ts @@ -52,7 +52,6 @@ import { getSessionIdMiddleware, initialiseSessionMiddleware, } from "./middleware/session-middleware"; -import { shareInfoRouter } from "./components/share-info/share-info-routes"; import { updatedTermsConditionsRouter } from "./components/updated-terms-conditions/updated-terms-conditions-routes"; import { signInOrCreateRouter } from "./components/sign-in-or-create/sign-in-or-create-routes"; import { accountNotFoundRouter } from "./components/account-not-found/account-not-found-routes"; @@ -123,7 +122,6 @@ function registerRoutes(app: express.Application) { app.use(resendMfaCodeAccountCreationRouter); app.use(resendEmailCodeRouter); app.use(signedOutRouter); - app.use(shareInfoRouter); app.use(updatedTermsConditionsRouter); app.use(resetPasswordRouter); if (support2FABeforePasswordReset()) { diff --git a/src/assets/javascript/cookies.js b/src/assets/javascript/cookies.js index 7c3ec1f3b3..e5cdf98843 100644 --- a/src/assets/javascript/cookies.js +++ b/src/assets/javascript/cookies.js @@ -219,7 +219,6 @@ var cookies = function (trackingId, analyticsCookieDomain) { "sign in", "middle" ), - "/share-info": generateSessionJourney("sign in", "middle"), "/reset-password-check-email": generateSessionJourney( "password reset", "start" diff --git a/src/components/common/state-machine/state-machine.ts b/src/components/common/state-machine/state-machine.ts index 2873942da3..f3145c2030 100644 --- a/src/components/common/state-machine/state-machine.ts +++ b/src/components/common/state-machine/state-machine.ts @@ -450,11 +450,6 @@ const authStateMachine = createMachine( ], }, }, - [PATH_NAMES.SHARE_INFO]: { - on: { - [USER_JOURNEY_EVENTS.CONSENT_ACCEPTED]: [PATH_NAMES.AUTH_CODE], - }, - }, [PATH_NAMES.RESET_PASSWORD_REQUEST]: { on: { [USER_JOURNEY_EVENTS.PASSWORD_RESET_REQUESTED]: [ diff --git a/src/components/share-info/index.njk b/src/components/share-info/index.njk deleted file mode 100644 index 40b8f50203..0000000000 --- a/src/components/share-info/index.njk +++ /dev/null @@ -1,64 +0,0 @@ -{% extends "common/layout/base.njk" %} -{% from "govuk/components/button/macro.njk" import govukButton %} -{% from "govuk/components/radios/macro.njk" import govukRadios %} - -{% set pageTitleName = 'pages.shareInfo.title' | translate %} - -{% block content %} - -
{{'pages.shareInfo.bulletPointSectionHeader' | translate}}
- -{{'pages.shareInfo.paragraph1' | translate}}
-{{'pages.shareInfo.paragraph2' | translate}}
-{{'pages.shareInfo.paragraph3' | translate}}
- - - -{% endblock %} diff --git a/src/components/share-info/share-info-controller.ts b/src/components/share-info/share-info-controller.ts deleted file mode 100644 index 4bfdfa7946..0000000000 --- a/src/components/share-info/share-info-controller.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { Request, Response } from "express"; -import { ExpressRouteFunc } from "../../types"; - -import { BadRequestError } from "../../utils/error"; -import { - UpdateProfileServiceInterface, - UpdateType, -} from "../common/update-profile/types"; -import { updateProfileService } from "../common/update-profile/update-profile-service"; -import { USER_JOURNEY_EVENTS } from "../common/state-machine/state-machine"; -import { getNextPathAndUpdateJourney } from "../common/constants"; - -export function shareInfoGet(req: Request, res: Response): void { - const prettyScopes = mapScopes(req.session.client.scopes); - - res.render("share-info/index.njk", { - clientName: req.session.client.name, - prettyScopes, - }); -} - -export function shareInfoPost( - service: UpdateProfileServiceInterface = updateProfileService() -): ExpressRouteFunc { - return async function (req: Request, res: Response) { - const consentValue = req.body.consentValue; - const { email } = req.session.user; - const { sessionId, clientSessionId, persistentSessionId } = res.locals; - - const result = await service.updateProfile( - sessionId, - clientSessionId, - email, - { - profileInformation: consentValue, - updateProfileType: UpdateType.CAPTURE_CONSENT, - }, - req.ip, - persistentSessionId - ); - - if (!result.success) { - throw new BadRequestError(result.data.message, result.data.code); - } - - res.redirect( - await getNextPathAndUpdateJourney( - req, - req.path, - USER_JOURNEY_EVENTS.CONSENT_ACCEPTED, - null, - sessionId - ) - ); - }; -} - -function mapScopes(scopes: string[]) { - const returnScopes: string[] = []; - scopes.forEach(function (item) { - if (item === "email") { - returnScopes.push("email address"); - } - if (item === "phone") { - returnScopes.push("phone number"); - } - }); - return returnScopes; -} diff --git a/src/components/share-info/share-info-routes.ts b/src/components/share-info/share-info-routes.ts deleted file mode 100644 index a16965e5a8..0000000000 --- a/src/components/share-info/share-info-routes.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { PATH_NAMES } from "../../app.constants"; - -import * as express from "express"; -import { shareInfoGet, shareInfoPost } from "./share-info-controller"; -import { validateSessionMiddleware } from "../../middleware/session-middleware"; -import { asyncHandler } from "../../utils/async"; -import { validateShareInfoRequest } from "./share-info-validation"; -import { allowUserJourneyMiddleware } from "../../middleware/allow-user-journey-middleware"; - -const router = express.Router(); - -router.get( - PATH_NAMES.SHARE_INFO, - validateSessionMiddleware, - allowUserJourneyMiddleware, - shareInfoGet -); - -router.post( - PATH_NAMES.SHARE_INFO, - validateSessionMiddleware, - allowUserJourneyMiddleware, - validateShareInfoRequest(), - asyncHandler(shareInfoPost()) -); - -export { router as shareInfoRouter }; diff --git a/src/components/share-info/share-info-validation.ts b/src/components/share-info/share-info-validation.ts deleted file mode 100644 index 1f9592524b..0000000000 --- a/src/components/share-info/share-info-validation.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { body } from "express-validator"; -import { validateBodyMiddleware } from "../../middleware/form-validation-middleware"; -import { ValidationChainFunc } from "../../types"; - -export function validateShareInfoRequest(): ValidationChainFunc { - return [ - body("consentValue") - .notEmpty() - .withMessage((value, { req }) => { - return req.t("pages.shareInfo.radios.radioText.errorMessage", { - value, - }); - }), - validateBodyMiddleware("share-info/index.njk"), - ]; -} diff --git a/src/components/share-info/tests/share-info-controller.test.ts b/src/components/share-info/tests/share-info-controller.test.ts deleted file mode 100644 index 79df0ec633..0000000000 --- a/src/components/share-info/tests/share-info-controller.test.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { expect } from "chai"; -import { describe } from "mocha"; -import { sinon } from "../../../../test/utils/test-utils"; -import { Request, Response } from "express"; -import { shareInfoGet, shareInfoPost } from "../share-info-controller"; - -import { BadRequestError } from "../../../utils/error"; -import { UpdateProfileServiceInterface } from "../../common/update-profile/types"; -import { PATH_NAMES } from "../../../app.constants"; -import { mockResponse, RequestOutput, ResponseOutput } from "mock-req-res"; -import { createMockRequest } from "../../../../test/helpers/mock-request-helper"; - -describe("share-info controller", () => { - let req: RequestOutput; - let res: ResponseOutput; - - beforeEach(() => { - req = createMockRequest(PATH_NAMES.SHARE_INFO); - req.session.client = { - name: "clientname", - scopes: ["openid", "email", "phone"], - }; - res = mockResponse(); - }); - - afterEach(() => { - sinon.restore(); - }); - - describe("shareInfoGet", () => { - it("should render share-info page", () => { - shareInfoGet(req as Request, res as Response); - - expect(res.render).to.have.calledWith("share-info/index.njk"); - }); - }); - - describe("shareInfoPost", () => { - it("should redirect to /auth-code when accepted sharing info", async () => { - const fakeService: UpdateProfileServiceInterface = { - updateProfile: sinon.fake.returns({ - success: true, - }), - } as unknown as UpdateProfileServiceInterface; - - req.body.consentValue = true; - res.locals.sessionId = "s-123456-djjad"; - res.locals.clientSessionId = "c-123456-djjad"; - res.locals.persistentSessionId = "dips-123456-abc"; - req.session.user.email = "test@test.com"; - - await shareInfoPost(fakeService)(req as Request, res as Response); - - expect(fakeService.updateProfile).to.have.been.calledOnce; - expect(res.redirect).to.have.calledWith(PATH_NAMES.AUTH_CODE); - }); - }); - - describe("shareInfoPostError", () => { - it("should throw error when update profile returns false", async () => { - const fakeService: UpdateProfileServiceInterface = { - updateProfile: sinon.fake.returns({ - success: false, - data: { code: "1000", message: "error" }, - }), - } as unknown as UpdateProfileServiceInterface; - - req.body.consentValue = true; - res.locals.sessionId = "s-123456-djjad"; - res.locals.clientSessionId = "c-123456-djjad"; - req.session.user.email = "test@test.com"; - - await expect( - shareInfoPost(fakeService)(req as Request, res as Response) - ).to.be.rejectedWith(BadRequestError, "1000:error"); - - expect(fakeService.updateProfile).to.have.been.calledOnce; - }); - }); -}); diff --git a/src/components/share-info/tests/share-info-integration.test.ts b/src/components/share-info/tests/share-info-integration.test.ts deleted file mode 100644 index b4c5d959e7..0000000000 --- a/src/components/share-info/tests/share-info-integration.test.ts +++ /dev/null @@ -1,130 +0,0 @@ -import request from "supertest"; -import { describe } from "mocha"; -import { expect, sinon } from "../../../../test/utils/test-utils"; -import nock = require("nock"); -import * as cheerio from "cheerio"; -import decache from "decache"; -import { - API_ENDPOINTS, - HTTP_STATUS_CODES, - PATH_NAMES, -} from "../../../app.constants"; - -describe("Integration::share info", () => { - let token: string | string[]; - let cookies: string; - let app: any; - let baseApi: string; - - before(async () => { - decache("../../../app"); - decache("../../../middleware/session-middleware"); - const sessionMiddleware = require("../../../middleware/session-middleware"); - - sinon - .stub(sessionMiddleware, "validateSessionMiddleware") - .callsFake(function (req: any, res: any, next: any): void { - res.locals.sessionId = "tDy103saszhcxbQq0-mjdzU854"; - res.locals.clientSessionId = "csy103saszhcxbQq0-mjdzU854"; - res.locals.persistentSessionId = "dips-123456-abc"; - - req.session.user = { - email: "test@test.com", - journey: { - nextPath: PATH_NAMES.SHARE_INFO, - }, - }; - - req.session.client = { - name: "clientname", - scopes: ["openid", "email", "phone"], - }; - - next(); - }); - - app = await require("../../../app").createApp(); - baseApi = process.env.FRONTEND_API_BASE_URL; - - request(app) - .get(PATH_NAMES.SHARE_INFO) - .end((err, res) => { - const $ = cheerio.load(res.text); - token = $("[name=_csrf]").val(); - cookies = res.headers["set-cookie"]; - }); - }); - - beforeEach(() => { - nock.cleanAll(); - }); - - after(() => { - sinon.restore(); - app = undefined; - }); - - it("should return share info page", (done) => { - request(app).get(PATH_NAMES.SHARE_INFO).expect(200, done); - }); - - it("should return error when csrf not present", (done) => { - request(app) - .post(PATH_NAMES.SHARE_INFO) - .type("form") - .send({ - consentValue: "true", - }) - .expect(500, done); - }); - - it("should return validation error when consentValue not selected", (done) => { - request(app) - .post(PATH_NAMES.SHARE_INFO) - .type("form") - .set("Cookie", cookies) - .send({ - _csrf: token, - consentValue: undefined, - }) - .expect(function (res) { - const $ = cheerio.load(res.text); - expect($("#consentValue-error").text()).to.contains( - "Select if you want to share your email address and phone number or not" - ); - }) - .expect(400, done); - }); - - it("should redirect to /auth-code page when consentValue valid", (done) => { - nock(baseApi) - .post(API_ENDPOINTS.UPDATE_PROFILE) - .once() - .reply(HTTP_STATUS_CODES.NO_CONTENT); - - request(app) - .post(PATH_NAMES.SHARE_INFO) - .type("form") - .set("Cookie", cookies) - .send({ - _csrf: token, - consentValue: "true", - }) - .expect("Location", PATH_NAMES.AUTH_CODE) - .expect(302, done); - }); - - it("should return internal server error when /update-profile API call response is 500", (done) => { - nock(baseApi).post(API_ENDPOINTS.UPDATE_PROFILE).once().reply(500, {}); - - request(app) - .post(PATH_NAMES.SHARE_INFO) - .type("form") - .set("Cookie", cookies) - .send({ - _csrf: token, - consentValue: "true", - }) - .expect(500, done); - }); -}); diff --git a/src/locales/cy/translation.json b/src/locales/cy/translation.json index 77fa9212fd..84ca3f1a19 100644 --- a/src/locales/cy/translation.json +++ b/src/locales/cy/translation.json @@ -668,24 +668,6 @@ "signInLinkText": "mewngofnodwch", "paragraph2": "i’ch GOV.UK One Login." }, - "shareInfo": { - "title": "Rhannu gwybodaeth o’ch GOV.UK One Login", - "header": "Rhannu gwybodaeth o’ch GOV.UK One Login", - "continue": "Parhau", - "bulletPointSectionHeader": "Mae’r gwasanaeth hwn angen defnyddio eich:", - "paragraph1": "Rydych wedi ychwanegu’r wybodaeth hon i’ch GOV.UK One Login pan wnaethoch ei greu. Gallwch ddewis ei rannu gyda’r gwasanaeth yn lle ei roi i mewn eto pan fyddwch yn defnyddio’r gwasanaeth.", - "paragraph2": "Bydd y gwasanaeth ond yn defnyddio’r wybodaeth yma i gysylltu â chi am y gwasanaeth. Ni fydd yn rhannu eich gwybodaeth ag unrhyw un arall. Bydd yn cadw eich gwybodaeth cyhyd ag y mae ei angen neu mae’r gyfraith yn ei gwneud yn ofynnol iddo.", - "paragraph3": "Os ydych yn dewis peidio â rhannu gwybodaeth o’ch GOV.UK One Login,efallai y gofynnir i chi am y wybodaeth honno o hyd wrth i chi ddefnyddio’r gwasanaeth. Er enghraifft os ydych yn dewis peidio â rhannu eich cyfeiriad e-bost a’ch rhif ffôn ac mae’r gwasanaeth angen ffordd i gysylltu â chi.", - "essentialHeader": "Ydych chi eisiau rhannu gwybodaeth o’ch GOV.UK One Login? ", - "radios": { - "shareMy": "Ydych chi eisiau rhannu gwybodaeth o’ch GOV.UK One Login?", - "radioText": { - "agree": "Rhannwch fy nghyfeiriad e-bost a’m rhif ffôn", - "doNotAgree": "Peidiwch rhannu fy nghyfeiriad e-bost â’m rhif ffôn", - "errorMessage": "Dewiswch os ydych am rannu eich cyfeiriad e-bost a’ch rhif ffôn neu beidio" - } - } - }, "updatedTermsAndConds": { "title": "Diweddariad telerau defnyddio GOV.UK One Login", "header": "Diweddariad telerau defnyddio GOV.UK One Login", diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 5cbc8fc083..7fd8bf73f0 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -668,24 +668,6 @@ "signInLinkText": "sign in", "paragraph2": "to your GOV.UK One Login." }, - "shareInfo": { - "title": "Share information from your GOV.UK One Login", - "header": "Share information from your GOV.UK One Login", - "continue": "Continue", - "bulletPointSectionHeader": "This service needs to use your:", - "paragraph1": "You added this information to your GOV.UK One Login when you created it. You can choose to share the information with the service instead of entering it again when you use the service.", - "paragraph2": "The service will only use this information to contact you about the service. It won’t share your information with anyone else. It will keep your information for as long as it needs to or the law requires it to.", - "paragraph3": "If you choose not to share information from your GOV.UK One Login, you may still be asked for that information as you use the service. For example if you choose not to share your email address and phone number and the service needs a way to contact you.", - "essentialHeader": "Do you want to share information from your GOV.UK One Login? ", - "radios": { - "shareMy": "Do you want to share information from your GOV.UK One Login?", - "radioText": { - "agree": "Share my email address and phone number", - "doNotAgree": "Do not share my email address and phone number", - "errorMessage": "Select if you want to share your email address and phone number or not" - } - } - }, "updatedTermsAndConds": { "title": "GOV.UK One Login terms of use update", "header": "GOV.UK One Login terms of use update",