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(""); + }); }); });