From c20386d2968a868c56cfc3617984bc73ccf474b0 Mon Sep 17 00:00:00 2001 From: GTVJ Date: Fri, 7 Jun 2024 15:31:16 +0100 Subject: [PATCH] AUT-1466: Show end of telephone number on MFA resend screen * includes the last three digits of a user's telephone number in the relevant template, making use of the returnLastCharacters Nunjucks filter * introduces a new test to validate the last three digits of the user's telephone number are included in the response * updates returnLastCharactersOnly to ensure an empty string will be returned if the function receives a non-string argument. I have done this because I found that is possible for the Nunjucks macro to receive a undefined value which it then passed to the function. If this happens, there would have been an error resulting in a 500. --- src/components/resend-mfa-code/index.njk | 10 +++------- .../tests/resend-mfa-code-integration.test.ts | 14 +++++++++++++- src/utils/phone-number.ts | 2 +- test/unit/utils/phone-number.test.ts | 3 +++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/components/resend-mfa-code/index.njk b/src/components/resend-mfa-code/index.njk index af60efa3e..3f7f376ab 100644 --- a/src/components/resend-mfa-code/index.njk +++ b/src/components/resend-mfa-code/index.njk @@ -6,13 +6,9 @@ {% set showBack = true %} {% set hrefBack = 'enter-code' %} -{% if isResendCodeRequest %} - {% set phoneNumberMessage %} - {{ 'pages.resendMfaCode.phoneNumber.isResendCodeRequest' | translate }} {{ phoneNumber }} - {% endset %} -{% else %} - {% set phoneNumberMessage = 'pages.resendMfaCode.phoneNumber.default' | translate | replace("[mobile]", phoneNumber) %} -{% endif %} +{% set phoneNumberMessage %} + {{ 'pages.resendMfaCode.phoneNumber.isResendCodeRequest' | translate }} {{ phoneNumber | returnLastCharacters({limit: 3}) }} +{% endset %} {% block content %}
diff --git a/src/components/resend-mfa-code/tests/resend-mfa-code-integration.test.ts b/src/components/resend-mfa-code/tests/resend-mfa-code-integration.test.ts index b33cb46a5..66db89f88 100644 --- a/src/components/resend-mfa-code/tests/resend-mfa-code-integration.test.ts +++ b/src/components/resend-mfa-code/tests/resend-mfa-code-integration.test.ts @@ -1,6 +1,6 @@ import request from "supertest"; import { describe } from "mocha"; -import { sinon } from "../../../../test/utils/test-utils"; +import { expect, sinon } from "../../../../test/utils/test-utils"; import nock = require("nock"); import * as cheerio from "cheerio"; import decache from "decache"; @@ -61,6 +61,18 @@ describe("Integration:: resend mfa code", () => { it("should return resend mfa code page", (done) => { request(app).get(PATH_NAMES.RESEND_MFA_CODE).expect(200, done); + + it("should include the last three digits of the user's telephone number", (done) => { + request(app) + .get(PATH_NAMES.RESEND_MFA_CODE) + .expect(function (res) { + const $ = cheerio.load(res.text); + expect($(".govuk-inset-text").text()).to.eq( + "We will send a code to your phone number ending with 867" + ); + }) + .expect(200, done); + }); }); it("should return error when csrf not present", (done) => { diff --git a/src/utils/phone-number.ts b/src/utils/phone-number.ts index 493cd38ec..4186cce4a 100644 --- a/src/utils/phone-number.ts +++ b/src/utils/phone-number.ts @@ -60,5 +60,5 @@ export function returnLastCharactersOnly( value: string, options: { limit: number } = { limit: 4 } ): string { - return value.slice(-options.limit); + return value?.length ? value.slice(-options.limit) : ""; } diff --git a/test/unit/utils/phone-number.test.ts b/test/unit/utils/phone-number.test.ts index 6fb2eedb6..fd044f888 100644 --- a/test/unit/utils/phone-number.test.ts +++ b/test/unit/utils/phone-number.test.ts @@ -252,5 +252,8 @@ describe("phone-number", () => { ).to.equal(i); }); }); + it("should return an empty string if passed empty string", () => { + expect(returnLastCharactersOnly("", { limit: 3 })).to.equal(""); + }); }); });