From bf7ed1c2bd2465245f2c12a354b0a56a173e4285 Mon Sep 17 00:00:00 2001 From: rdas Date: Wed, 23 Oct 2024 09:32:10 +0100 Subject: [PATCH 01/13] IDVA51337-- should NOT be merged --- src/app.ts | 4 +++- src/middleware/authentication_middleware.ts | 8 +++++--- .../authentication_middleware_sole_trader.ts | 16 ++++++++++++++++ src/utils/properties.ts | 2 ++ test/mocks/all_middleware_mock.ts | 2 ++ ...authentication_middleware_sole_trader_mock.ts | 11 +++++++++++ 6 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 src/middleware/authentication_middleware_sole_trader.ts create mode 100644 test/mocks/authentication_middleware_sole_trader_mock.ts diff --git a/src/app.ts b/src/app.ts index b9ab1fa3..074b0f92 100755 --- a/src/app.ts +++ b/src/app.ts @@ -5,6 +5,7 @@ import logger from "./utils/logger"; import routerDispatch from "./router.dispatch"; import cookieParser from "cookie-parser"; import { authenticationMiddleware } from "./middleware/authentication_middleware"; +import { authenticationMiddlewareForSoleTrader } from "./middleware/authentication_middleware_sole_trader"; import { sessionMiddleware } from "./middleware/session_middleware"; import { @@ -16,7 +17,7 @@ import { PIWIK_URL, PIWIK_SITE_ID } from "./utils/properties"; -import { BASE_URL, HEALTHCHECK, ACCESSIBILITY_STATEMENT } from "./types/pageURL"; +import { BASE_URL, SOLE_TRADER, SOLE_TRADER_WHAT_IS_YOUR_ROLE, HEALTHCHECK, ACCESSIBILITY_STATEMENT } from "./types/pageURL"; import { commonTemplateVariablesMiddleware } from "./middleware/common_variables_middleware"; import { getLocalesService, selectLang } from "./utils/localise"; import { ErrorService } from "./services/errorService"; @@ -55,6 +56,7 @@ app.use(express.static(path.join(__dirname, "/../assets/public"))); app.use(cookieParser()); app.use(`^(?!(${BASE_URL}${HEALTHCHECK}|${BASE_URL}$|${BASE_URL}${ACCESSIBILITY_STATEMENT}))*`, sessionMiddleware); app.use(`^(?!(${BASE_URL}${HEALTHCHECK}|${BASE_URL}$|${BASE_URL}${ACCESSIBILITY_STATEMENT}))*`, authenticationMiddleware); +app.use(`^(${BASE_URL}${SOLE_TRADER_WHAT_IS_YOUR_ROLE})*`, authenticationMiddlewareForSoleTrader); app.use(commonTemplateVariablesMiddleware); // Company Auth redirect diff --git a/src/middleware/authentication_middleware.ts b/src/middleware/authentication_middleware.ts index 3b76e84d..e7192243 100644 --- a/src/middleware/authentication_middleware.ts +++ b/src/middleware/authentication_middleware.ts @@ -1,7 +1,7 @@ import { NextFunction, Request, Response } from "express"; -import { AuthOptions, acspProfileCreateAuthMiddleware } from "@companieshouse/web-security-node"; +import { AuthOptions, authMiddleware, acspProfileCreateAuthMiddleware } from "@companieshouse/web-security-node"; -import { CHS_URL } from "../utils/properties"; +import { CHS_URL, FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION } from "../utils/properties"; import { BASE_URL, CHECK_SAVED_APPLICATION } from "../types/pageURL"; export const authenticationMiddleware = (req: Request, res: Response, next: NextFunction) => { @@ -11,5 +11,7 @@ export const authenticationMiddleware = (req: Request, res: Response, next: Next returnUrl: BASE_URL + CHECK_SAVED_APPLICATION }; - return acspProfileCreateAuthMiddleware(authMiddlewareConfig)(req, res, next); + return FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION === "true" + ? authMiddleware(authMiddlewareConfig)(req, res, next) + : acspProfileCreateAuthMiddleware(authMiddlewareConfig)(req, res, next); }; diff --git a/src/middleware/authentication_middleware_sole_trader.ts b/src/middleware/authentication_middleware_sole_trader.ts new file mode 100644 index 00000000..0dd5f15d --- /dev/null +++ b/src/middleware/authentication_middleware_sole_trader.ts @@ -0,0 +1,16 @@ +import { NextFunction, Request, Response } from "express"; +import { AuthOptions, acspProfileCreateAuthMiddleware } from "@companieshouse/web-security-node"; + +import { CHS_URL } from "../utils/properties"; +import { BASE_URL, CHECK_SAVED_APPLICATION } from "../types/pageURL"; + +export const authenticationMiddlewareForSoleTrader = (req: Request, res: Response, next: NextFunction) => { + + const authMiddlewareConfig: AuthOptions = { + chsWebUrl: CHS_URL, + returnUrl: BASE_URL + CHECK_SAVED_APPLICATION + }; + + return acspProfileCreateAuthMiddleware(authMiddlewareConfig)(req, res, next); + +}; diff --git a/src/utils/properties.ts b/src/utils/properties.ts index 69e0b34e..6f616493 100644 --- a/src/utils/properties.ts +++ b/src/utils/properties.ts @@ -47,3 +47,5 @@ export const PIWIK_START_GOAL_ID = getEnvironmentValue("PIWIK_START_GOAL_ID", "4 export const FEATURE_FLAG_DISABLE_LIMITED_JOURNEY = getEnvironmentValue("FEATURE_FLAG_DISABLE_LIMITED_JOURNEY", "false"); export const FEATURE_FLAG_DISABLE_PARTNERSHIP_JOURNEY = getEnvironmentValue("FEATURE_FLAG_DISABLE_PARTNERSHIP_JOURNEY", "false"); + +export const FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION = getEnvironmentValue("FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION", "true"); diff --git a/test/mocks/all_middleware_mock.ts b/test/mocks/all_middleware_mock.ts index 6235d2e5..08ba6ad0 100644 --- a/test/mocks/all_middleware_mock.ts +++ b/test/mocks/all_middleware_mock.ts @@ -1,10 +1,12 @@ import mockAuthenticationMiddleware from "./authentication_middleware_mock"; +import mockAuthenticationMiddlewareForSoleTrader from "./authentication_middleware_sole_trader_mock"; import mockSessionMiddleware from "./session_middleware_mock"; import mockCompanyAuthenticationMiddleware from "./company_authentication_middleware_mock"; import mockUKAddressesFromPostcode from "./postcode_lookup_service_mock"; export default { mockAuthenticationMiddleware, + mockAuthenticationMiddlewareForSoleTrader, mockSessionMiddleware, mockCompanyAuthenticationMiddleware, mockUKAddressesFromPostcode diff --git a/test/mocks/authentication_middleware_sole_trader_mock.ts b/test/mocks/authentication_middleware_sole_trader_mock.ts new file mode 100644 index 00000000..2f9d02eb --- /dev/null +++ b/test/mocks/authentication_middleware_sole_trader_mock.ts @@ -0,0 +1,11 @@ +import { NextFunction, Request, Response } from "express"; +import { authenticationMiddlewareForSoleTrader } from "../../src/middleware/authentication_middleware_sole_trader"; +jest.mock("../../src/middleware/authentication_middleware_sole_trader"); + +// get handle on mocked function +const mockAuthenticationMiddlewareForSoleTrader = authenticationMiddlewareForSoleTrader as jest.Mock; + +// tell the mock what to return +mockAuthenticationMiddlewareForSoleTrader.mockImplementation((req: Request, res: Response, next: NextFunction) => next()); + +export default mockAuthenticationMiddlewareForSoleTrader; From 00a95c1f87fd35209c53d15a898ac6e60d8b833a Mon Sep 17 00:00:00 2001 From: rdas Date: Wed, 23 Oct 2024 13:15:54 +0100 Subject: [PATCH 02/13] IDVA5-1337 [Registration] Sole Trader Only IDV - Feature Flag --- .../authentication_middleware.test.ts | 4 +-- ...hentication_middleware_sole_trader.test.ts | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 test/src/middleware/authentication_middleware_sole_trader.test.ts diff --git a/test/src/middleware/authentication_middleware.test.ts b/test/src/middleware/authentication_middleware.test.ts index 6c29986b..b4d648d7 100644 --- a/test/src/middleware/authentication_middleware.test.ts +++ b/test/src/middleware/authentication_middleware.test.ts @@ -2,13 +2,13 @@ jest.mock("@companieshouse/web-security-node"); -import { acspProfileCreateAuthMiddleware, AuthOptions } from "@companieshouse/web-security-node"; +import { authMiddleware, AuthOptions } from "@companieshouse/web-security-node"; import { Request, Response } from "express"; import { authenticationMiddleware } from "../../../src/middleware/authentication_middleware"; import { BASE_URL, CHECK_SAVED_APPLICATION } from "../../../src/types/pageURL"; // get handle on mocked function and create mock function to be returned from calling authMiddleware -const mockAuthMiddleware = acspProfileCreateAuthMiddleware as jest.Mock; +const mockAuthMiddleware = authMiddleware as jest.Mock; const mockAuthReturnedFunction = jest.fn(); // when the mocked authMiddleware is called, make it return a mocked function so we can verify it gets called diff --git a/test/src/middleware/authentication_middleware_sole_trader.test.ts b/test/src/middleware/authentication_middleware_sole_trader.test.ts new file mode 100644 index 00000000..dc94970f --- /dev/null +++ b/test/src/middleware/authentication_middleware_sole_trader.test.ts @@ -0,0 +1,32 @@ +/* eslint-disable import/first */ + +jest.mock("@companieshouse/web-security-node"); + +import { acspProfileCreateAuthMiddleware, AuthOptions } from "@companieshouse/web-security-node"; +import { Request, Response } from "express"; +import { authenticationMiddlewareForSoleTrader } from "../../../src/middleware/authentication_middleware_sole_trader"; +import { BASE_URL, CHECK_SAVED_APPLICATION } from "../../../src/types/pageURL"; + +// get handle on mocked function and create mock function to be returned from calling authMiddleware +const mockAuthMiddleware = acspProfileCreateAuthMiddleware as jest.Mock; +const mockAuthReturnedFunction = jest.fn(); + +// when the mocked authMiddleware is called, make it return a mocked function so we can verify it gets called +mockAuthMiddleware.mockReturnValue(mockAuthReturnedFunction); + +const req: Request = {} as Request; +const res: Response = {} as Response; +const next = jest.fn(); + +const expectedAuthMiddlewareConfig: AuthOptions = { + chsWebUrl: "http://chs.local", + returnUrl: BASE_URL + CHECK_SAVED_APPLICATION +}; + +describe("authentication middleware tests", () => { + it("should call CH authentication library", () => { + authenticationMiddlewareForSoleTrader(req, res, next); + expect(mockAuthMiddleware).toHaveBeenCalledWith(expectedAuthMiddlewareConfig); + expect(mockAuthReturnedFunction).toHaveBeenCalledWith(req, res, next); + }); +}); From 7308583baf92c3ceddc18c2eddd53e2a226c49ac Mon Sep 17 00:00:00 2001 From: rdas Date: Wed, 23 Oct 2024 13:59:55 +0100 Subject: [PATCH 03/13] IDVA5-1337 [Registration] Sole Trader Only IDV - Feature Flag --- test/src/middleware/authentication_middleware.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/src/middleware/authentication_middleware.test.ts b/test/src/middleware/authentication_middleware.test.ts index b4d648d7..33f0f1db 100644 --- a/test/src/middleware/authentication_middleware.test.ts +++ b/test/src/middleware/authentication_middleware.test.ts @@ -4,6 +4,7 @@ jest.mock("@companieshouse/web-security-node"); import { authMiddleware, AuthOptions } from "@companieshouse/web-security-node"; import { Request, Response } from "express"; +import { FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION } from "../../../src/utils/properties"; import { authenticationMiddleware } from "../../../src/middleware/authentication_middleware"; import { BASE_URL, CHECK_SAVED_APPLICATION } from "../../../src/types/pageURL"; @@ -25,6 +26,14 @@ const expectedAuthMiddlewareConfig: AuthOptions = { describe("authentication middleware tests", () => { it("should call CH authentication library", () => { + process.env[FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION] = "false"; + authenticationMiddleware(req, res, next); + expect(mockAuthMiddleware).toHaveBeenCalledWith(expectedAuthMiddlewareConfig); + expect(mockAuthReturnedFunction).toHaveBeenCalledWith(req, res, next); + }); + + it("should call CH authentication library", () => { + process.env[FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION] = "true"; authenticationMiddleware(req, res, next); expect(mockAuthMiddleware).toHaveBeenCalledWith(expectedAuthMiddlewareConfig); expect(mockAuthReturnedFunction).toHaveBeenCalledWith(req, res, next); From 8d51cfa080a2aafcaf95d6a5de875922cc6c1bb3 Mon Sep 17 00:00:00 2001 From: rdas Date: Thu, 24 Oct 2024 16:04:03 +0100 Subject: [PATCH 04/13] should NOT be merged --- src/middleware/authentication_middleware.ts | 9 ++++-- .../authentication_middleware.test.ts | 29 ++++++++++++------- test/src/setup.ts | 2 +- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/middleware/authentication_middleware.ts b/src/middleware/authentication_middleware.ts index e7192243..84d88a1b 100644 --- a/src/middleware/authentication_middleware.ts +++ b/src/middleware/authentication_middleware.ts @@ -11,7 +11,10 @@ export const authenticationMiddleware = (req: Request, res: Response, next: Next returnUrl: BASE_URL + CHECK_SAVED_APPLICATION }; - return FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION === "true" - ? authMiddleware(authMiddlewareConfig)(req, res, next) - : acspProfileCreateAuthMiddleware(authMiddlewareConfig)(req, res, next); + if(FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION === "true"){ + return authMiddleware(authMiddlewareConfig)(req, res, next) + } else { + return acspProfileCreateAuthMiddleware(authMiddlewareConfig)(req, res, next); + } + }; diff --git a/test/src/middleware/authentication_middleware.test.ts b/test/src/middleware/authentication_middleware.test.ts index 33f0f1db..2cb9a588 100644 --- a/test/src/middleware/authentication_middleware.test.ts +++ b/test/src/middleware/authentication_middleware.test.ts @@ -2,18 +2,22 @@ jest.mock("@companieshouse/web-security-node"); -import { authMiddleware, AuthOptions } from "@companieshouse/web-security-node"; +import { acspProfileCreateAuthMiddleware, authMiddleware, AuthOptions } from "@companieshouse/web-security-node"; import { Request, Response } from "express"; -import { FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION } from "../../../src/utils/properties"; import { authenticationMiddleware } from "../../../src/middleware/authentication_middleware"; import { BASE_URL, CHECK_SAVED_APPLICATION } from "../../../src/types/pageURL"; +import * as module from "../../../src/utils/environment/environment_value"; // get handle on mocked function and create mock function to be returned from calling authMiddleware const mockAuthMiddleware = authMiddleware as jest.Mock; -const mockAuthReturnedFunction = jest.fn(); +const mockAuthReturnedFunctionAuthMiddleware = jest.fn(); + +const mockAcspProfileCreateAuthMiddleware = acspProfileCreateAuthMiddleware as jest.Mock; +const mockAuthReturnedFunctionAcspProfileCreateAuthMiddleware = jest.fn(); // when the mocked authMiddleware is called, make it return a mocked function so we can verify it gets called -mockAuthMiddleware.mockReturnValue(mockAuthReturnedFunction); +mockAuthMiddleware.mockReturnValue(mockAuthReturnedFunctionAuthMiddleware); +mockAcspProfileCreateAuthMiddleware.mockReturnValue(mockAuthReturnedFunctionAcspProfileCreateAuthMiddleware); const req: Request = {} as Request; const res: Response = {} as Response; @@ -25,17 +29,20 @@ const expectedAuthMiddlewareConfig: AuthOptions = { }; describe("authentication middleware tests", () => { + it("should call CH authentication library", () => { - process.env[FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION] = "false"; + + // (getEnvironmentValue as jest.Mock).mockImplementation(() => {return "true"}); + + authenticationMiddleware(req, res, next); expect(mockAuthMiddleware).toHaveBeenCalledWith(expectedAuthMiddlewareConfig); - expect(mockAuthReturnedFunction).toHaveBeenCalledWith(req, res, next); + expect(mockAuthReturnedFunctionAuthMiddleware).toHaveBeenCalledWith(req, res, next); }); - it("should call CH authentication library", () => { - process.env[FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION] = "true"; + jest.spyOn(module, "getEnvironmentValue").mockImplementation(() => {return "false"}); authenticationMiddleware(req, res, next); - expect(mockAuthMiddleware).toHaveBeenCalledWith(expectedAuthMiddlewareConfig); - expect(mockAuthReturnedFunction).toHaveBeenCalledWith(req, res, next); + expect(mockAcspProfileCreateAuthMiddleware).toHaveBeenCalledWith(expectedAuthMiddlewareConfig); + expect(mockAuthReturnedFunctionAcspProfileCreateAuthMiddleware).toHaveBeenCalledWith(req, res, next); }); -}); +}); \ No newline at end of file diff --git a/test/src/setup.ts b/test/src/setup.ts index a65dc9f2..d8bbbb17 100644 --- a/test/src/setup.ts +++ b/test/src/setup.ts @@ -10,4 +10,4 @@ process.env.API_URL = "http://testapi.co"; process.env.COOKIE_SECRET = "Xy6onkjQWF0TkRn0hfdqUw=="; process.env.COOKIE_DOMAIN = "cookie domain"; process.env.CACHE_SERVER = "test"; -process.env.CDN_URL_CSS = "//d7blrfb1p86zg.cloudfront.net/stylesheets/services/bankrupt-officers"; +process.env.CDN_URL_CSS = "//d7blrfb1p86zg.cloudfront.net/stylesheets/services/bankrupt-officers"; \ No newline at end of file From e6d00cefcca9635960702058a9eb982d5c9127f4 Mon Sep 17 00:00:00 2001 From: rdas Date: Fri, 25 Oct 2024 11:38:23 +0100 Subject: [PATCH 05/13] IDVA5-1337 [Registration] Sole Trader Only IDV - Feature Flag --- src/middleware/authentication_middleware.ts | 9 ++--- .../authentication_middleware.test.ts | 21 +++-------- ...n_middleware_disabled_verification.test.ts | 36 +++++++++++++++++++ 3 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 test/src/middleware/authentication_middleware_disabled_verification.test.ts diff --git a/src/middleware/authentication_middleware.ts b/src/middleware/authentication_middleware.ts index 84d88a1b..e7192243 100644 --- a/src/middleware/authentication_middleware.ts +++ b/src/middleware/authentication_middleware.ts @@ -11,10 +11,7 @@ export const authenticationMiddleware = (req: Request, res: Response, next: Next returnUrl: BASE_URL + CHECK_SAVED_APPLICATION }; - if(FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION === "true"){ - return authMiddleware(authMiddlewareConfig)(req, res, next) - } else { - return acspProfileCreateAuthMiddleware(authMiddlewareConfig)(req, res, next); - } - + return FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION === "true" + ? authMiddleware(authMiddlewareConfig)(req, res, next) + : acspProfileCreateAuthMiddleware(authMiddlewareConfig)(req, res, next); }; diff --git a/test/src/middleware/authentication_middleware.test.ts b/test/src/middleware/authentication_middleware.test.ts index 2cb9a588..28601968 100644 --- a/test/src/middleware/authentication_middleware.test.ts +++ b/test/src/middleware/authentication_middleware.test.ts @@ -1,13 +1,10 @@ /* eslint-disable import/first */ - jest.mock("@companieshouse/web-security-node"); - +process.env.FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION = "false"; import { acspProfileCreateAuthMiddleware, authMiddleware, AuthOptions } from "@companieshouse/web-security-node"; import { Request, Response } from "express"; import { authenticationMiddleware } from "../../../src/middleware/authentication_middleware"; import { BASE_URL, CHECK_SAVED_APPLICATION } from "../../../src/types/pageURL"; -import * as module from "../../../src/utils/environment/environment_value"; - // get handle on mocked function and create mock function to be returned from calling authMiddleware const mockAuthMiddleware = authMiddleware as jest.Mock; const mockAuthReturnedFunctionAuthMiddleware = jest.fn(); @@ -29,20 +26,10 @@ const expectedAuthMiddlewareConfig: AuthOptions = { }; describe("authentication middleware tests", () => { - - it("should call CH authentication library", () => { - - // (getEnvironmentValue as jest.Mock).mockImplementation(() => {return "true"}); - - - authenticationMiddleware(req, res, next); - expect(mockAuthMiddleware).toHaveBeenCalledWith(expectedAuthMiddlewareConfig); - expect(mockAuthReturnedFunctionAuthMiddleware).toHaveBeenCalledWith(req, res, next); - }); - it("should call CH authentication library", () => { - jest.spyOn(module, "getEnvironmentValue").mockImplementation(() => {return "false"}); + it("should call CH authentication library", async () => { authenticationMiddleware(req, res, next); expect(mockAcspProfileCreateAuthMiddleware).toHaveBeenCalledWith(expectedAuthMiddlewareConfig); expect(mockAuthReturnedFunctionAcspProfileCreateAuthMiddleware).toHaveBeenCalledWith(req, res, next); }); -}); \ No newline at end of file + +}); diff --git a/test/src/middleware/authentication_middleware_disabled_verification.test.ts b/test/src/middleware/authentication_middleware_disabled_verification.test.ts new file mode 100644 index 00000000..82b5104f --- /dev/null +++ b/test/src/middleware/authentication_middleware_disabled_verification.test.ts @@ -0,0 +1,36 @@ +/* eslint-disable import/first */ +jest.mock("@companieshouse/web-security-node"); +process.env.FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION = "true"; +import { acspProfileCreateAuthMiddleware, authMiddleware, AuthOptions } from "@companieshouse/web-security-node"; +import { Request, Response } from "express"; +import { BASE_URL, CHECK_SAVED_APPLICATION } from "../../../src/types/pageURL"; +import { authenticationMiddleware } from "../../../src/middleware/authentication_middleware"; +// get handle on mocked function and create mock function to be returned from calling authMiddleware +const mockAuthMiddleware = authMiddleware as jest.Mock; +const mockAuthReturnedFunctionAuthMiddleware = jest.fn(); + +const mockAcspProfileCreateAuthMiddleware = acspProfileCreateAuthMiddleware as jest.Mock; +const mockAuthReturnedFunctionAcspProfileCreateAuthMiddleware = jest.fn(); + +// when the mocked authMiddleware is called, make it return a mocked function so we can verify it gets called +mockAuthMiddleware.mockReturnValue(mockAuthReturnedFunctionAuthMiddleware); +mockAcspProfileCreateAuthMiddleware.mockReturnValue(mockAuthReturnedFunctionAcspProfileCreateAuthMiddleware); + +const req: Request = {} as Request; +const res: Response = {} as Response; +const next = jest.fn(); + +const expectedAuthMiddlewareConfig: AuthOptions = { + chsWebUrl: "http://chs.local", + returnUrl: BASE_URL + CHECK_SAVED_APPLICATION +}; + +describe("authentication middleware tests", () => { + it("should call CH authentication library", async () => { + authenticationMiddleware(req, res, next); + authenticationMiddleware(req, res, next); + expect(mockAuthMiddleware).toHaveBeenCalledWith(expectedAuthMiddlewareConfig); + expect(mockAuthReturnedFunctionAuthMiddleware).toHaveBeenCalledWith(req, res, next); + }); + +}); From 91d7e52fb3c4d073610b33ec902d3a6035021be9 Mon Sep 17 00:00:00 2001 From: rdas Date: Fri, 25 Oct 2024 13:11:42 +0100 Subject: [PATCH 06/13] IDVA5-1337 [Registration] Sole Trader Only IDV - Feature Flag --- test/src/middleware/authentication_middleware.test.ts | 7 ++----- ...authentication_middleware_disabled_verification.test.ts | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/test/src/middleware/authentication_middleware.test.ts b/test/src/middleware/authentication_middleware.test.ts index 28601968..77dd3330 100644 --- a/test/src/middleware/authentication_middleware.test.ts +++ b/test/src/middleware/authentication_middleware.test.ts @@ -1,19 +1,16 @@ /* eslint-disable import/first */ jest.mock("@companieshouse/web-security-node"); process.env.FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION = "false"; -import { acspProfileCreateAuthMiddleware, authMiddleware, AuthOptions } from "@companieshouse/web-security-node"; +import { acspProfileCreateAuthMiddleware, AuthOptions } from "@companieshouse/web-security-node"; import { Request, Response } from "express"; import { authenticationMiddleware } from "../../../src/middleware/authentication_middleware"; import { BASE_URL, CHECK_SAVED_APPLICATION } from "../../../src/types/pageURL"; -// get handle on mocked function and create mock function to be returned from calling authMiddleware -const mockAuthMiddleware = authMiddleware as jest.Mock; -const mockAuthReturnedFunctionAuthMiddleware = jest.fn(); +// get handle on mocked function and create mock function to be returned from calling authMiddleware const mockAcspProfileCreateAuthMiddleware = acspProfileCreateAuthMiddleware as jest.Mock; const mockAuthReturnedFunctionAcspProfileCreateAuthMiddleware = jest.fn(); // when the mocked authMiddleware is called, make it return a mocked function so we can verify it gets called -mockAuthMiddleware.mockReturnValue(mockAuthReturnedFunctionAuthMiddleware); mockAcspProfileCreateAuthMiddleware.mockReturnValue(mockAuthReturnedFunctionAcspProfileCreateAuthMiddleware); const req: Request = {} as Request; diff --git a/test/src/middleware/authentication_middleware_disabled_verification.test.ts b/test/src/middleware/authentication_middleware_disabled_verification.test.ts index 82b5104f..0aff031c 100644 --- a/test/src/middleware/authentication_middleware_disabled_verification.test.ts +++ b/test/src/middleware/authentication_middleware_disabled_verification.test.ts @@ -1,20 +1,17 @@ /* eslint-disable import/first */ jest.mock("@companieshouse/web-security-node"); process.env.FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION = "true"; -import { acspProfileCreateAuthMiddleware, authMiddleware, AuthOptions } from "@companieshouse/web-security-node"; +import { authMiddleware, AuthOptions } from "@companieshouse/web-security-node"; import { Request, Response } from "express"; import { BASE_URL, CHECK_SAVED_APPLICATION } from "../../../src/types/pageURL"; import { authenticationMiddleware } from "../../../src/middleware/authentication_middleware"; + // get handle on mocked function and create mock function to be returned from calling authMiddleware const mockAuthMiddleware = authMiddleware as jest.Mock; const mockAuthReturnedFunctionAuthMiddleware = jest.fn(); -const mockAcspProfileCreateAuthMiddleware = acspProfileCreateAuthMiddleware as jest.Mock; -const mockAuthReturnedFunctionAcspProfileCreateAuthMiddleware = jest.fn(); - // when the mocked authMiddleware is called, make it return a mocked function so we can verify it gets called mockAuthMiddleware.mockReturnValue(mockAuthReturnedFunctionAuthMiddleware); -mockAcspProfileCreateAuthMiddleware.mockReturnValue(mockAuthReturnedFunctionAcspProfileCreateAuthMiddleware); const req: Request = {} as Request; const res: Response = {} as Response; From 085429bdf815124218816f2e1631c14f5f714a0c Mon Sep 17 00:00:00 2001 From: rdas Date: Mon, 28 Oct 2024 15:49:38 +0000 Subject: [PATCH 07/13] IDVA5-1337 [Registration] Sole Trader Only IDV - Feature Flag --- src/middleware/authentication_middleware_sole_trader.ts | 4 ++-- test/src/middleware/authentication_middleware.test.ts | 6 +++++- .../authentication_middleware_disabled_verification.test.ts | 6 +++++- .../authentication_middleware_sole_trader.test.ts | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/middleware/authentication_middleware_sole_trader.ts b/src/middleware/authentication_middleware_sole_trader.ts index 0dd5f15d..3fc3af99 100644 --- a/src/middleware/authentication_middleware_sole_trader.ts +++ b/src/middleware/authentication_middleware_sole_trader.ts @@ -2,13 +2,13 @@ import { NextFunction, Request, Response } from "express"; import { AuthOptions, acspProfileCreateAuthMiddleware } from "@companieshouse/web-security-node"; import { CHS_URL } from "../utils/properties"; -import { BASE_URL, CHECK_SAVED_APPLICATION } from "../types/pageURL"; +import { BASE_URL, SOLE_TRADER_WHAT_IS_YOUR_ROLE, } from "../types/pageURL"; export const authenticationMiddlewareForSoleTrader = (req: Request, res: Response, next: NextFunction) => { const authMiddlewareConfig: AuthOptions = { chsWebUrl: CHS_URL, - returnUrl: BASE_URL + CHECK_SAVED_APPLICATION + returnUrl: BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_ROLE }; return acspProfileCreateAuthMiddleware(authMiddlewareConfig)(req, res, next); diff --git a/test/src/middleware/authentication_middleware.test.ts b/test/src/middleware/authentication_middleware.test.ts index 77dd3330..c79806e3 100644 --- a/test/src/middleware/authentication_middleware.test.ts +++ b/test/src/middleware/authentication_middleware.test.ts @@ -1,16 +1,20 @@ /* eslint-disable import/first */ jest.mock("@companieshouse/web-security-node"); process.env.FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION = "false"; -import { acspProfileCreateAuthMiddleware, AuthOptions } from "@companieshouse/web-security-node"; +import { acspProfileCreateAuthMiddleware, authMiddleware, AuthOptions } from "@companieshouse/web-security-node"; import { Request, Response } from "express"; import { authenticationMiddleware } from "../../../src/middleware/authentication_middleware"; import { BASE_URL, CHECK_SAVED_APPLICATION } from "../../../src/types/pageURL"; // get handle on mocked function and create mock function to be returned from calling authMiddleware +const mockAuthMiddleware = authMiddleware as jest.Mock; +const mockAuthReturnedFunctionAuthMiddleware = jest.fn(); + const mockAcspProfileCreateAuthMiddleware = acspProfileCreateAuthMiddleware as jest.Mock; const mockAuthReturnedFunctionAcspProfileCreateAuthMiddleware = jest.fn(); // when the mocked authMiddleware is called, make it return a mocked function so we can verify it gets called +mockAuthMiddleware.mockReturnValue(mockAuthReturnedFunctionAuthMiddleware); mockAcspProfileCreateAuthMiddleware.mockReturnValue(mockAuthReturnedFunctionAcspProfileCreateAuthMiddleware); const req: Request = {} as Request; diff --git a/test/src/middleware/authentication_middleware_disabled_verification.test.ts b/test/src/middleware/authentication_middleware_disabled_verification.test.ts index 0aff031c..d41f6776 100644 --- a/test/src/middleware/authentication_middleware_disabled_verification.test.ts +++ b/test/src/middleware/authentication_middleware_disabled_verification.test.ts @@ -1,7 +1,7 @@ /* eslint-disable import/first */ jest.mock("@companieshouse/web-security-node"); process.env.FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION = "true"; -import { authMiddleware, AuthOptions } from "@companieshouse/web-security-node"; +import { acspProfileCreateAuthMiddleware, authMiddleware, AuthOptions } from "@companieshouse/web-security-node"; import { Request, Response } from "express"; import { BASE_URL, CHECK_SAVED_APPLICATION } from "../../../src/types/pageURL"; import { authenticationMiddleware } from "../../../src/middleware/authentication_middleware"; @@ -10,8 +10,12 @@ import { authenticationMiddleware } from "../../../src/middleware/authentication const mockAuthMiddleware = authMiddleware as jest.Mock; const mockAuthReturnedFunctionAuthMiddleware = jest.fn(); +const mockAcspProfileCreateAuthMiddleware = acspProfileCreateAuthMiddleware as jest.Mock; +const mockAuthReturnedFunctionAcspProfileCreateAuthMiddleware = jest.fn(); + // when the mocked authMiddleware is called, make it return a mocked function so we can verify it gets called mockAuthMiddleware.mockReturnValue(mockAuthReturnedFunctionAuthMiddleware); +mockAcspProfileCreateAuthMiddleware.mockReturnValue(mockAuthReturnedFunctionAcspProfileCreateAuthMiddleware); const req: Request = {} as Request; const res: Response = {} as Response; diff --git a/test/src/middleware/authentication_middleware_sole_trader.test.ts b/test/src/middleware/authentication_middleware_sole_trader.test.ts index dc94970f..0c354a72 100644 --- a/test/src/middleware/authentication_middleware_sole_trader.test.ts +++ b/test/src/middleware/authentication_middleware_sole_trader.test.ts @@ -5,7 +5,7 @@ jest.mock("@companieshouse/web-security-node"); import { acspProfileCreateAuthMiddleware, AuthOptions } from "@companieshouse/web-security-node"; import { Request, Response } from "express"; import { authenticationMiddlewareForSoleTrader } from "../../../src/middleware/authentication_middleware_sole_trader"; -import { BASE_URL, CHECK_SAVED_APPLICATION } from "../../../src/types/pageURL"; +import { BASE_URL, SOLE_TRADER_WHAT_IS_YOUR_ROLE } from "../../../src/types/pageURL"; // get handle on mocked function and create mock function to be returned from calling authMiddleware const mockAuthMiddleware = acspProfileCreateAuthMiddleware as jest.Mock; @@ -20,7 +20,7 @@ const next = jest.fn(); const expectedAuthMiddlewareConfig: AuthOptions = { chsWebUrl: "http://chs.local", - returnUrl: BASE_URL + CHECK_SAVED_APPLICATION + returnUrl: BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_ROLE }; describe("authentication middleware tests", () => { From c69bf830a56cf05c160cf5f4ab3b35451a86ae3a Mon Sep 17 00:00:00 2001 From: rdas Date: Mon, 28 Oct 2024 15:51:06 +0000 Subject: [PATCH 08/13] IDVA5-1337 [Registration] Sole Trader Only IDV - Feature Flag --- src/middleware/authentication_middleware_sole_trader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/middleware/authentication_middleware_sole_trader.ts b/src/middleware/authentication_middleware_sole_trader.ts index 3fc3af99..47acd90c 100644 --- a/src/middleware/authentication_middleware_sole_trader.ts +++ b/src/middleware/authentication_middleware_sole_trader.ts @@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from "express"; import { AuthOptions, acspProfileCreateAuthMiddleware } from "@companieshouse/web-security-node"; import { CHS_URL } from "../utils/properties"; -import { BASE_URL, SOLE_TRADER_WHAT_IS_YOUR_ROLE, } from "../types/pageURL"; +import { BASE_URL, SOLE_TRADER_WHAT_IS_YOUR_ROLE } from "../types/pageURL"; export const authenticationMiddlewareForSoleTrader = (req: Request, res: Response, next: NextFunction) => { From cd56fe2d9ccc2d8935c62fa9a8612f2cce514c5b Mon Sep 17 00:00:00 2001 From: rdas Date: Thu, 31 Oct 2024 12:19:32 +0000 Subject: [PATCH 09/13] IDVA5-1337 [Registration] Sole Trader Only IDV - Feature Flag --- src/middleware/authentication_middleware.ts | 4 ++-- src/utils/properties.ts | 2 +- test/src/middleware/authentication_middleware.test.ts | 2 +- .../authentication_middleware_disabled_verification.test.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/middleware/authentication_middleware.ts b/src/middleware/authentication_middleware.ts index e7192243..8098e428 100644 --- a/src/middleware/authentication_middleware.ts +++ b/src/middleware/authentication_middleware.ts @@ -1,7 +1,7 @@ import { NextFunction, Request, Response } from "express"; import { AuthOptions, authMiddleware, acspProfileCreateAuthMiddleware } from "@companieshouse/web-security-node"; -import { CHS_URL, FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION } from "../utils/properties"; +import { CHS_URL, FEATURE_FLAG_VERIFY_SOLE_TRADER_ONLY } from "../utils/properties"; import { BASE_URL, CHECK_SAVED_APPLICATION } from "../types/pageURL"; export const authenticationMiddleware = (req: Request, res: Response, next: NextFunction) => { @@ -11,7 +11,7 @@ export const authenticationMiddleware = (req: Request, res: Response, next: Next returnUrl: BASE_URL + CHECK_SAVED_APPLICATION }; - return FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION === "true" + return FEATURE_FLAG_VERIFY_SOLE_TRADER_ONLY === "true" ? authMiddleware(authMiddlewareConfig)(req, res, next) : acspProfileCreateAuthMiddleware(authMiddlewareConfig)(req, res, next); }; diff --git a/src/utils/properties.ts b/src/utils/properties.ts index 9f168c24..6492cc4b 100644 --- a/src/utils/properties.ts +++ b/src/utils/properties.ts @@ -50,4 +50,4 @@ export const FEATURE_FLAG_DISABLE_LIMITED_JOURNEY = getEnvironmentValue("FEATURE export const FEATURE_FLAG_DISABLE_PARTNERSHIP_JOURNEY = getEnvironmentValue("FEATURE_FLAG_DISABLE_PARTNERSHIP_JOURNEY", "false"); -export const FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION = getEnvironmentValue("FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION", "true"); +export const FEATURE_FLAG_VERIFY_SOLE_TRADER_ONLY = getEnvironmentValue("FEATURE_FLAG_VERIFY_SOLE_TRADER_ONLY", "true"); diff --git a/test/src/middleware/authentication_middleware.test.ts b/test/src/middleware/authentication_middleware.test.ts index c79806e3..66cf3bb3 100644 --- a/test/src/middleware/authentication_middleware.test.ts +++ b/test/src/middleware/authentication_middleware.test.ts @@ -1,6 +1,6 @@ /* eslint-disable import/first */ jest.mock("@companieshouse/web-security-node"); -process.env.FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION = "false"; +process.env.FEATURE_FLAG_VERIFY_SOLE_TRADER_ONLY = "false"; import { acspProfileCreateAuthMiddleware, authMiddleware, AuthOptions } from "@companieshouse/web-security-node"; import { Request, Response } from "express"; import { authenticationMiddleware } from "../../../src/middleware/authentication_middleware"; diff --git a/test/src/middleware/authentication_middleware_disabled_verification.test.ts b/test/src/middleware/authentication_middleware_disabled_verification.test.ts index d41f6776..d72b7ec6 100644 --- a/test/src/middleware/authentication_middleware_disabled_verification.test.ts +++ b/test/src/middleware/authentication_middleware_disabled_verification.test.ts @@ -1,6 +1,6 @@ /* eslint-disable import/first */ jest.mock("@companieshouse/web-security-node"); -process.env.FEATURE_FLAG_DISABLE_MANDATORY_VERIFICATION = "true"; +process.env.FEATURE_FLAG_VERIFY_SOLE_TRADER_ONLY = "true"; import { acspProfileCreateAuthMiddleware, authMiddleware, AuthOptions } from "@companieshouse/web-security-node"; import { Request, Response } from "express"; import { BASE_URL, CHECK_SAVED_APPLICATION } from "../../../src/types/pageURL"; From d426b319d9e7835f6181518f648415d0b2f1a76b Mon Sep 17 00:00:00 2001 From: rdas Date: Fri, 1 Nov 2024 11:05:27 +0000 Subject: [PATCH 10/13] IDVA5-1337 [Registration] Sole Trader Only IDV - Feature Flag --- src/middleware/authentication_middleware.ts | 4 ++-- src/utils/properties.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/middleware/authentication_middleware.ts b/src/middleware/authentication_middleware.ts index 8098e428..99a3317a 100644 --- a/src/middleware/authentication_middleware.ts +++ b/src/middleware/authentication_middleware.ts @@ -1,6 +1,6 @@ import { NextFunction, Request, Response } from "express"; import { AuthOptions, authMiddleware, acspProfileCreateAuthMiddleware } from "@companieshouse/web-security-node"; - +import { isActiveFeature } from "../utils/feature.flag"; import { CHS_URL, FEATURE_FLAG_VERIFY_SOLE_TRADER_ONLY } from "../utils/properties"; import { BASE_URL, CHECK_SAVED_APPLICATION } from "../types/pageURL"; @@ -11,7 +11,7 @@ export const authenticationMiddleware = (req: Request, res: Response, next: Next returnUrl: BASE_URL + CHECK_SAVED_APPLICATION }; - return FEATURE_FLAG_VERIFY_SOLE_TRADER_ONLY === "true" + return isActiveFeature(FEATURE_FLAG_VERIFY_SOLE_TRADER_ONLY) === true ? authMiddleware(authMiddlewareConfig)(req, res, next) : acspProfileCreateAuthMiddleware(authMiddlewareConfig)(req, res, next); }; diff --git a/src/utils/properties.ts b/src/utils/properties.ts index 6492cc4b..1671560c 100644 --- a/src/utils/properties.ts +++ b/src/utils/properties.ts @@ -50,4 +50,4 @@ export const FEATURE_FLAG_DISABLE_LIMITED_JOURNEY = getEnvironmentValue("FEATURE export const FEATURE_FLAG_DISABLE_PARTNERSHIP_JOURNEY = getEnvironmentValue("FEATURE_FLAG_DISABLE_PARTNERSHIP_JOURNEY", "false"); -export const FEATURE_FLAG_VERIFY_SOLE_TRADER_ONLY = getEnvironmentValue("FEATURE_FLAG_VERIFY_SOLE_TRADER_ONLY", "true"); +export const FEATURE_FLAG_VERIFY_SOLE_TRADER_ONLY = getEnvironmentValue("FEATURE_FLAG_VERIFY_SOLE_TRADER_ONLY", "false"); From 797535c77c99186e37c2ddd76ed59613ae454942 Mon Sep 17 00:00:00 2001 From: rdas Date: Fri, 1 Nov 2024 14:02:02 +0000 Subject: [PATCH 11/13] IDVA5-1337 [Registration] Sole Trader Only IDV - Feature Flag --- src/app.ts | 2 +- .../controllers/soleTrader/whatIsYourRoleController.test.ts | 6 +++--- test/src/setup.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app.ts b/src/app.ts index 074b0f92..cb3d89e4 100755 --- a/src/app.ts +++ b/src/app.ts @@ -55,7 +55,7 @@ app.use(express.static(path.join(__dirname, "/../assets/public"))); // Apply middleware app.use(cookieParser()); app.use(`^(?!(${BASE_URL}${HEALTHCHECK}|${BASE_URL}$|${BASE_URL}${ACCESSIBILITY_STATEMENT}))*`, sessionMiddleware); -app.use(`^(?!(${BASE_URL}${HEALTHCHECK}|${BASE_URL}$|${BASE_URL}${ACCESSIBILITY_STATEMENT}))*`, authenticationMiddleware); +app.use(`^(?!(${BASE_URL}${HEALTHCHECK}|${BASE_URL}$|${BASE_URL}${ACCESSIBILITY_STATEMENT})|(${BASE_URL}${SOLE_TRADER_WHAT_IS_YOUR_ROLE}))*`, authenticationMiddleware); app.use(`^(${BASE_URL}${SOLE_TRADER_WHAT_IS_YOUR_ROLE})*`, authenticationMiddlewareForSoleTrader); app.use(commonTemplateVariablesMiddleware); diff --git a/test/src/controllers/soleTrader/whatIsYourRoleController.test.ts b/test/src/controllers/soleTrader/whatIsYourRoleController.test.ts index 09e20c32..bcabb825 100644 --- a/test/src/controllers/soleTrader/whatIsYourRoleController.test.ts +++ b/test/src/controllers/soleTrader/whatIsYourRoleController.test.ts @@ -32,7 +32,7 @@ describe("Statement Relevant Officer Router", () => { const response = await router.get(BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_ROLE); expect(response.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(response.text).toContain("What is your role in the business?"); }); @@ -40,7 +40,7 @@ describe("Statement Relevant Officer Router", () => { const response = await router.get(BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_ROLE); expect(response.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("catch error when rendering the page", async () => { @@ -78,7 +78,7 @@ describe("POST " + SOLE_TRADER_WHAT_IS_YOUR_ROLE, () => { expect(response.status).toBe(400); expect(response.text).toContain("Select if you are the sole trader or someone else"); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("should show the error page if an error occurs during PUT request", async () => { diff --git a/test/src/setup.ts b/test/src/setup.ts index d8bbbb17..a65dc9f2 100644 --- a/test/src/setup.ts +++ b/test/src/setup.ts @@ -10,4 +10,4 @@ process.env.API_URL = "http://testapi.co"; process.env.COOKIE_SECRET = "Xy6onkjQWF0TkRn0hfdqUw=="; process.env.COOKIE_DOMAIN = "cookie domain"; process.env.CACHE_SERVER = "test"; -process.env.CDN_URL_CSS = "//d7blrfb1p86zg.cloudfront.net/stylesheets/services/bankrupt-officers"; \ No newline at end of file +process.env.CDN_URL_CSS = "//d7blrfb1p86zg.cloudfront.net/stylesheets/services/bankrupt-officers"; From 09ee8f87c1504139ca9f6fd08ed5cd664402279a Mon Sep 17 00:00:00 2001 From: rdas Date: Sun, 3 Nov 2024 14:01:51 +0000 Subject: [PATCH 12/13] IDVA5-1337 [Registration] Sole Trader Only IDV - Feature Flag --- src/app.ts | 4 ++-- src/middleware/authentication_middleware.ts | 2 +- ...rrespodanceAddressDetailsController.test.ts | 8 ++++---- ...pondenceAddressAutoLookupController.test.ts | 16 ++++++++-------- ...respondenceAddressConfirmController.test.ts | 10 +++++----- ...rrespondenceAddressManualController.test.ts | 6 +++--- .../soleTrader/dateOfBirthController.test.ts | 4 ++-- .../soleTrader/nameController.test.ts | 8 ++++---- .../soleTrader/nationalityController.test.ts | 4 ++-- .../sectorYouWorkInController.test.ts | 4 ++-- .../selectAmlSupervisorController.test.ts | 6 +++--- .../soleTrader/whatIsTheBusinessName.test.ts | 18 +++++++++--------- .../whatIsYourEmailAddressController.test.ts | 4 ++-- .../whereDoYouLiveController.test.ts | 4 ++-- .../whichSectorOtherController.test.ts | 6 +++--- 15 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/app.ts b/src/app.ts index cb3d89e4..40bb30b4 100755 --- a/src/app.ts +++ b/src/app.ts @@ -55,8 +55,8 @@ app.use(express.static(path.join(__dirname, "/../assets/public"))); // Apply middleware app.use(cookieParser()); app.use(`^(?!(${BASE_URL}${HEALTHCHECK}|${BASE_URL}$|${BASE_URL}${ACCESSIBILITY_STATEMENT}))*`, sessionMiddleware); -app.use(`^(?!(${BASE_URL}${HEALTHCHECK}|${BASE_URL}$|${BASE_URL}${ACCESSIBILITY_STATEMENT})|(${BASE_URL}${SOLE_TRADER_WHAT_IS_YOUR_ROLE}))*`, authenticationMiddleware); -app.use(`^(${BASE_URL}${SOLE_TRADER_WHAT_IS_YOUR_ROLE})*`, authenticationMiddlewareForSoleTrader); +app.use(`^(?!(${BASE_URL}${HEALTHCHECK}|${BASE_URL}$|${BASE_URL}${ACCESSIBILITY_STATEMENT})|(${BASE_URL}${SOLE_TRADER}))*`, authenticationMiddleware); +app.use(`^(${BASE_URL}${SOLE_TRADER})*`, authenticationMiddlewareForSoleTrader); app.use(commonTemplateVariablesMiddleware); // Company Auth redirect diff --git a/src/middleware/authentication_middleware.ts b/src/middleware/authentication_middleware.ts index 99a3317a..00bc0314 100644 --- a/src/middleware/authentication_middleware.ts +++ b/src/middleware/authentication_middleware.ts @@ -11,7 +11,7 @@ export const authenticationMiddleware = (req: Request, res: Response, next: Next returnUrl: BASE_URL + CHECK_SAVED_APPLICATION }; - return isActiveFeature(FEATURE_FLAG_VERIFY_SOLE_TRADER_ONLY) === true + return isActiveFeature(FEATURE_FLAG_VERIFY_SOLE_TRADER_ONLY) ? authMiddleware(authMiddlewareConfig)(req, res, next) : acspProfileCreateAuthMiddleware(authMiddlewareConfig)(req, res, next); }; diff --git a/test/src/controllers/soleTrader/correspodanceAddressDetailsController.test.ts b/test/src/controllers/soleTrader/correspodanceAddressDetailsController.test.ts index 34e09ead..a70c0e5d 100644 --- a/test/src/controllers/soleTrader/correspodanceAddressDetailsController.test.ts +++ b/test/src/controllers/soleTrader/correspodanceAddressDetailsController.test.ts @@ -25,7 +25,7 @@ describe("GET" + SOLE_TRADER_AUTO_LOOKUP_ADDRESS_LIST, () => { const res = await router.get(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS_LIST); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.text).toContain("John Doe"); expect(res.text).toContain("Select the correspondence address"); }); @@ -34,7 +34,7 @@ describe("GET" + SOLE_TRADER_AUTO_LOOKUP_ADDRESS_LIST, () => { const res = await router.get(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS_LIST); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("should return status 200 when applicantDetails is undefined", async () => { @@ -45,14 +45,14 @@ describe("GET" + SOLE_TRADER_AUTO_LOOKUP_ADDRESS_LIST, () => { const res = await router.get(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS_LIST); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("should return status 200", async () => { const res = await router.get(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS_LIST); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("should render the error page if an error is thrown in get function", async () => { mockGetAcspRegistration.mockImplementationOnce(() => { throw new Error(); }); diff --git a/test/src/controllers/soleTrader/correspondenceAddressAutoLookupController.test.ts b/test/src/controllers/soleTrader/correspondenceAddressAutoLookupController.test.ts index 02c76d2b..c7c55248 100644 --- a/test/src/controllers/soleTrader/correspondenceAddressAutoLookupController.test.ts +++ b/test/src/controllers/soleTrader/correspondenceAddressAutoLookupController.test.ts @@ -45,7 +45,7 @@ describe("Correspondence address auto look up tests", () => { const res = await router.get(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.text).toContain("What is the correspondence address?"); }); @@ -54,7 +54,7 @@ describe("Correspondence address auto look up tests", () => { const res = await router.get(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.text).toContain("What is the correspondence address?"); }); @@ -67,14 +67,14 @@ describe("Correspondence address auto look up tests", () => { const res = await router.get(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.text).toContain("What is the correspondence address?"); }); it("should return status 500 after calling GET endpoint and failing", async () => { mockGetAcspRegistration.mockRejectedValueOnce(new Error("Error getting data")); const res = await router.get(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.status).toBe(500); expect(res.text).toContain("Sorry we are experiencing technical difficulties"); }); @@ -98,7 +98,7 @@ describe("POST" + SOLE_TRADER_AUTO_LOOKUP_ADDRESS, () => { mockPutAcspRegistration.mockResolvedValueOnce(acspData); expect(res.status).toBe(302); // Expect a redirect status code expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.header.location).toBe(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS_LIST + "?lang=en"); }); @@ -118,7 +118,7 @@ describe("POST" + SOLE_TRADER_AUTO_LOOKUP_ADDRESS, () => { const res = await router.post(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS).send(formData); expect(res.status).toBe(302); // Expect a redirect status code expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.header.location).toBe(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM + "?lang=en"); }); @@ -133,7 +133,7 @@ describe("POST" + SOLE_TRADER_AUTO_LOOKUP_ADDRESS, () => { const res = await router.post(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS).send(formData); expect(res.status).toBe(302); // Expect a redirect status code expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.header.location).toBe(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM + "?lang=en"); }); @@ -260,7 +260,7 @@ describe("POST" + SOLE_TRADER_AUTO_LOOKUP_ADDRESS, () => { const res = await router.post(BASE_URL + SOLE_TRADER_AUTO_LOOKUP_ADDRESS).send(formData); expect(res.status).toBe(302); // Expect a redirect status code expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.header.location).toBe(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM + "?lang=en"); }); }); diff --git a/test/src/controllers/soleTrader/correspondenceAddressConfirmController.test.ts b/test/src/controllers/soleTrader/correspondenceAddressConfirmController.test.ts index f84be56b..4ad08bd5 100644 --- a/test/src/controllers/soleTrader/correspondenceAddressConfirmController.test.ts +++ b/test/src/controllers/soleTrader/correspondenceAddressConfirmController.test.ts @@ -43,7 +43,7 @@ describe("GET" + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, () => { mockGetAcspRegistration.mockResolvedValueOnce(acspData); const res = await router.get(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.status).toBe(200); expect(res.text).toContain("John Doe"); expect(res.text).toContain("Confirm the correspondence address"); @@ -53,7 +53,7 @@ describe("GET" + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, () => { it("should return status 200 when acspData is undefined", async () => { const res = await router.get(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.status).toBe(200); }); @@ -65,7 +65,7 @@ describe("GET" + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM, () => { mockGetAcspRegistration.mockResolvedValueOnce(acspDataWithoutApplicantDetails); const res = await router.get(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.status).toBe(200); }); @@ -81,7 +81,7 @@ describe("POST SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM", () => { it("should redirect to /select-aml-supervisor with status 302", async () => { const res = await router.post(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.status).toBe(302); expect(res.header.location).toBe(BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_EMAIL + "?lang=en"); }); @@ -157,7 +157,7 @@ describe("POST SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM", () => { createMockSessionMiddleware(acspDataSameAddress); const res = await router.post(BASE_URL + SOLE_TRADER_CORRESPONDENCE_ADDRESS_CONFIRM).send(formData); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.status).toBe(302); expect(res.header.location).toBe(BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_EMAIL + "?lang=en"); }); diff --git a/test/src/controllers/soleTrader/correspondenceAddressManualController.test.ts b/test/src/controllers/soleTrader/correspondenceAddressManualController.test.ts index ec3a08bc..f2cac7ac 100644 --- a/test/src/controllers/soleTrader/correspondenceAddressManualController.test.ts +++ b/test/src/controllers/soleTrader/correspondenceAddressManualController.test.ts @@ -24,7 +24,7 @@ describe("GET" + SOLE_TRADER_MANUAL_CORRESPONDENCE_ADDRESS, () => { mockGetAcspRegistration.mockResolvedValueOnce(acspData); const res = await router.get(BASE_URL + SOLE_TRADER_MANUAL_CORRESPONDENCE_ADDRESS); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.status).toBe(200); expect(res.text).toContain("Enter the correspondence address"); }); @@ -32,7 +32,7 @@ describe("GET" + SOLE_TRADER_MANUAL_CORRESPONDENCE_ADDRESS, () => { it("should return status 200 when acspData is undefined", async () => { const res = await router.get(BASE_URL + SOLE_TRADER_MANUAL_CORRESPONDENCE_ADDRESS); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.status).toBe(200); expect(res.text).toContain("Enter the correspondence address"); }); @@ -45,7 +45,7 @@ describe("GET" + SOLE_TRADER_MANUAL_CORRESPONDENCE_ADDRESS, () => { mockGetAcspRegistration.mockResolvedValueOnce(acspDataWithoutApplicantDetails); const res = await router.get(BASE_URL + SOLE_TRADER_MANUAL_CORRESPONDENCE_ADDRESS); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.status).toBe(200); expect(res.text).toContain("Enter the correspondence address"); }); diff --git a/test/src/controllers/soleTrader/dateOfBirthController.test.ts b/test/src/controllers/soleTrader/dateOfBirthController.test.ts index 19663c4f..580cfe8e 100644 --- a/test/src/controllers/soleTrader/dateOfBirthController.test.ts +++ b/test/src/controllers/soleTrader/dateOfBirthController.test.ts @@ -32,7 +32,7 @@ describe("GET" + SOLE_TRADER_DATE_OF_BIRTH, () => { const res = await router.get(BASE_URL + SOLE_TRADER_DATE_OF_BIRTH); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.text).toContain("What is your date of birth?"); }); @@ -41,7 +41,7 @@ describe("GET" + SOLE_TRADER_DATE_OF_BIRTH, () => { const res = await router.get(BASE_URL + SOLE_TRADER_DATE_OF_BIRTH); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.text).toContain("What is your date of birth?"); }); diff --git a/test/src/controllers/soleTrader/nameController.test.ts b/test/src/controllers/soleTrader/nameController.test.ts index c1d89c50..a2f9089a 100644 --- a/test/src/controllers/soleTrader/nameController.test.ts +++ b/test/src/controllers/soleTrader/nameController.test.ts @@ -23,7 +23,7 @@ describe("GET" + SOLE_TRADER_WHAT_IS_YOUR_NAME, () => { const res = await router.get(BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_NAME); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("should return status 200", async () => { @@ -31,7 +31,7 @@ describe("GET" + SOLE_TRADER_WHAT_IS_YOUR_NAME, () => { const res = await router.get(BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_NAME); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("should return status 200 when applicantDetails is undefined", async () => { @@ -42,7 +42,7 @@ describe("GET" + SOLE_TRADER_WHAT_IS_YOUR_NAME, () => { const res = await router.get(BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_NAME); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("catch error when rendering the page", async () => { @@ -66,7 +66,7 @@ describe("POST" + SOLE_TRADER_WHAT_IS_YOUR_NAME, () => { }); expect(res.status).toBe(302); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); // Test for incorrect form details entered, will return 400. diff --git a/test/src/controllers/soleTrader/nationalityController.test.ts b/test/src/controllers/soleTrader/nationalityController.test.ts index 245dd3d3..071895c6 100644 --- a/test/src/controllers/soleTrader/nationalityController.test.ts +++ b/test/src/controllers/soleTrader/nationalityController.test.ts @@ -35,7 +35,7 @@ describe("GET" + SOLE_TRADER_WHAT_IS_YOUR_NATIONALITY, () => { const res = await router.get(BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_NATIONALITY); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.text).toContain("What is your nationality?"); }); @@ -48,7 +48,7 @@ describe("GET" + SOLE_TRADER_WHAT_IS_YOUR_NATIONALITY, () => { const res = await router.get(BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_NATIONALITY); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("catch error when rendering the page", async () => { diff --git a/test/src/controllers/soleTrader/sectorYouWorkInController.test.ts b/test/src/controllers/soleTrader/sectorYouWorkInController.test.ts index 1d7828cc..1a023ce9 100644 --- a/test/src/controllers/soleTrader/sectorYouWorkInController.test.ts +++ b/test/src/controllers/soleTrader/sectorYouWorkInController.test.ts @@ -25,7 +25,7 @@ describe("GET" + SOLE_TRADER_SECTOR_YOU_WORK_IN, () => { mockGetAcspRegistration.mockResolvedValueOnce(acspData); await router.get(BASE_URL + SOLE_TRADER_SECTOR_YOU_WORK_IN).expect(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("should return status 200", async () => { @@ -36,7 +36,7 @@ describe("GET" + SOLE_TRADER_SECTOR_YOU_WORK_IN, () => { mockGetAcspRegistration.mockResolvedValueOnce(acspDataWithoutApplicantDetails); await router.get(BASE_URL + SOLE_TRADER_SECTOR_YOU_WORK_IN).expect(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("catch error when rendering the page", async () => { diff --git a/test/src/controllers/soleTrader/selectAmlSupervisorController.test.ts b/test/src/controllers/soleTrader/selectAmlSupervisorController.test.ts index f802810e..6e77520d 100644 --- a/test/src/controllers/soleTrader/selectAmlSupervisorController.test.ts +++ b/test/src/controllers/soleTrader/selectAmlSupervisorController.test.ts @@ -27,7 +27,7 @@ describe("GET" + SOLE_TRADER_SELECT_AML_SUPERVISOR, () => { const res = await router.get(BASE_URL + SOLE_TRADER_SELECT_AML_SUPERVISOR); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.text).toContain("Which Anti-Money Laundering (AML) supervisory bodies are you registered with?"); }); @@ -40,7 +40,7 @@ describe("GET" + SOLE_TRADER_SELECT_AML_SUPERVISOR, () => { const res = await router.get(BASE_URL + SOLE_TRADER_SELECT_AML_SUPERVISOR); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.text).toContain("Which Anti-Money Laundering (AML) supervisory bodies are you registered with?"); }); @@ -59,7 +59,7 @@ describe("POST" + SOLE_TRADER_SELECT_AML_SUPERVISOR, () => { const res = await router.post(BASE_URL + SOLE_TRADER_SELECT_AML_SUPERVISOR).send({ "AML-supervisory-bodies": "ACCA" }); expect(res.status).toBe(302); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.header.location).toBe(BASE_URL + AML_MEMBERSHIP_NUMBER + "?lang=en"); }); diff --git a/test/src/controllers/soleTrader/whatIsTheBusinessName.test.ts b/test/src/controllers/soleTrader/whatIsTheBusinessName.test.ts index 8d0d98cd..7296491d 100644 --- a/test/src/controllers/soleTrader/whatIsTheBusinessName.test.ts +++ b/test/src/controllers/soleTrader/whatIsTheBusinessName.test.ts @@ -30,7 +30,7 @@ describe("GET" + SOLE_TRADER_WHAT_IS_THE_BUSINESS_NAME, () => { const res = await router.get(BASE_URL + SOLE_TRADER_WHAT_IS_THE_BUSINESS_NAME); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("should return status 200 when applicantDetails is undefined", async () => { @@ -42,7 +42,7 @@ describe("GET" + SOLE_TRADER_WHAT_IS_THE_BUSINESS_NAME, () => { const res = await router.get(BASE_URL + SOLE_TRADER_WHAT_IS_THE_BUSINESS_NAME); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("catch error when rendering the page", async () => { @@ -71,7 +71,7 @@ describe("POST" + SOLE_TRADER_WHAT_IS_THE_BUSINESS_NAME, () => { expect(response.status).toBe(302); // Expect a redirect status code expect(response.header.location).toBe(BASE_URL + SOLE_TRADER_SECTOR_YOU_WORK_IN + "?lang=en"); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("should redirect with status 302 on successful form submission", async () => { @@ -90,7 +90,7 @@ describe("POST" + SOLE_TRADER_WHAT_IS_THE_BUSINESS_NAME, () => { expect(response.status).toBe(302); // Expect a redirect status code expect(response.header.location).toBe(BASE_URL + SOLE_TRADER_SECTOR_YOU_WORK_IN + "?lang=en"); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("should redirect with status 302 on successful form submission", async () => { @@ -104,7 +104,7 @@ describe("POST" + SOLE_TRADER_WHAT_IS_THE_BUSINESS_NAME, () => { expect(response.status).toBe(302); // Expect a redirect status code expect(response.header.location).toBe(BASE_URL + SOLE_TRADER_SECTOR_YOU_WORK_IN + "?lang=en"); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("should return status 400 for incorrect data entered", async () => { @@ -122,7 +122,7 @@ describe("POST" + SOLE_TRADER_WHAT_IS_THE_BUSINESS_NAME, () => { expect(response.status).toBe(400); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(response.text).toContain("Select business name"); }); @@ -141,7 +141,7 @@ describe("POST" + SOLE_TRADER_WHAT_IS_THE_BUSINESS_NAME, () => { expect(response.status).toBe(400); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(response.text).toContain("Enter the business name"); }); @@ -160,7 +160,7 @@ describe("POST" + SOLE_TRADER_WHAT_IS_THE_BUSINESS_NAME, () => { expect(response.status).toBe(400); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(response.text).toContain("Business name must only include letters a to z, and common special characters such as hyphens, spaces and apostrophes"); }); @@ -180,7 +180,7 @@ describe("POST" + SOLE_TRADER_WHAT_IS_THE_BUSINESS_NAME, () => { expect(response.status).toBe(400); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(response.text).toContain("Business name must be 155 characters or less"); }); diff --git a/test/src/controllers/soleTrader/whatIsYourEmailAddressController.test.ts b/test/src/controllers/soleTrader/whatIsYourEmailAddressController.test.ts index 395de0fb..1c2859ac 100644 --- a/test/src/controllers/soleTrader/whatIsYourEmailAddressController.test.ts +++ b/test/src/controllers/soleTrader/whatIsYourEmailAddressController.test.ts @@ -22,7 +22,7 @@ describe("GET" + SOLE_TRADER_WHAT_IS_YOUR_EMAIL, () => { mockGetAcspRegistration.mockResolvedValueOnce(acspData); const res = await router.get(BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_EMAIL); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.status).toBe(200); expect(res.text).toContain("What email address should we use for correspondence?"); }); @@ -31,7 +31,7 @@ describe("GET" + SOLE_TRADER_WHAT_IS_YOUR_EMAIL, () => { mockGetAcspRegistration.mockRejectedValueOnce(new Error("Error getting data")); const res = await router.get(BASE_URL + SOLE_TRADER_WHAT_IS_YOUR_EMAIL); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.status).toBe(500); expect(res.text).toContain("Sorry we are experiencing technical difficulties"); }); diff --git a/test/src/controllers/soleTrader/whereDoYouLiveController.test.ts b/test/src/controllers/soleTrader/whereDoYouLiveController.test.ts index 2075783c..8975cfec 100644 --- a/test/src/controllers/soleTrader/whereDoYouLiveController.test.ts +++ b/test/src/controllers/soleTrader/whereDoYouLiveController.test.ts @@ -33,7 +33,7 @@ describe("GET" + SOLE_TRADER_WHERE_DO_YOU_LIVE, () => { const res = await router.get(BASE_URL + SOLE_TRADER_WHERE_DO_YOU_LIVE); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); expect(res.text).toContain("Where do you live?"); }); @@ -46,7 +46,7 @@ describe("GET" + SOLE_TRADER_WHERE_DO_YOU_LIVE, () => { const res = await router.get(BASE_URL + SOLE_TRADER_WHERE_DO_YOU_LIVE); expect(res.status).toBe(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("catch error when rendering the page", async () => { diff --git a/test/src/controllers/soleTrader/whichSectorOtherController.test.ts b/test/src/controllers/soleTrader/whichSectorOtherController.test.ts index 5e2c40ee..e78a8670 100644 --- a/test/src/controllers/soleTrader/whichSectorOtherController.test.ts +++ b/test/src/controllers/soleTrader/whichSectorOtherController.test.ts @@ -25,13 +25,13 @@ describe("GET" + SOLE_TRADER_WHICH_SECTOR_OTHER, () => { mockGetAcspRegistration.mockResolvedValueOnce(acspData); await router.get(BASE_URL + SOLE_TRADER_WHICH_SECTOR_OTHER).expect(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("should return status 200", async () => { await router.get(BASE_URL + SOLE_TRADER_WHICH_SECTOR_OTHER).expect(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("should return status 200", async () => { @@ -41,7 +41,7 @@ describe("GET" + SOLE_TRADER_WHICH_SECTOR_OTHER, () => { mockGetAcspRegistration.mockResolvedValueOnce(acspDataWithoutApplicantDetails); await router.get(BASE_URL + SOLE_TRADER_WHICH_SECTOR_OTHER).expect(200); expect(mocks.mockSessionMiddleware).toHaveBeenCalled(); - expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled(); + expect(mocks.mockAuthenticationMiddlewareForSoleTrader).toHaveBeenCalled(); }); it("catch error when rendering the page", async () => { From 114fd8912b65ac21ff8ad32a52ace671e0679df0 Mon Sep 17 00:00:00 2001 From: rdas Date: Mon, 4 Nov 2024 09:02:24 +0000 Subject: [PATCH 13/13] IDVA5-1337 [Registration] Sole Trader Only IDV - Feature Flag --- src/app.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.ts b/src/app.ts index 40bb30b4..1660ceda 100755 --- a/src/app.ts +++ b/src/app.ts @@ -17,7 +17,7 @@ import { PIWIK_URL, PIWIK_SITE_ID } from "./utils/properties"; -import { BASE_URL, SOLE_TRADER, SOLE_TRADER_WHAT_IS_YOUR_ROLE, HEALTHCHECK, ACCESSIBILITY_STATEMENT } from "./types/pageURL"; +import { BASE_URL, SOLE_TRADER, HEALTHCHECK, ACCESSIBILITY_STATEMENT } from "./types/pageURL"; import { commonTemplateVariablesMiddleware } from "./middleware/common_variables_middleware"; import { getLocalesService, selectLang } from "./utils/localise"; import { ErrorService } from "./services/errorService";