generated from companieshouse/node-review-web-starter-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from companieshouse:feature/add-super-secure-…
…psc-validation Add exclusively super secure stop screen validation/routing
- Loading branch information
Showing
9 changed files
with
118 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,27 @@ | ||
import { CompanyProfile } from "@companieshouse/api-sdk-node/dist/services/company-profile/types"; | ||
import { NextFunction, Request, Response, Router } from "express"; | ||
import { PrefixedUrls, STOP_TYPE } from "../constants"; | ||
import { handleExceptions } from "../utils/asyncHandler"; | ||
import { addSearchParams } from "../utils/queryParams"; | ||
import { logger } from "../lib/logger"; | ||
import { getUrlWithStopType } from "../utils/url"; | ||
import { IndividualPscListHandler } from "./handlers/individual-psc-list/individualPscListHandler"; | ||
|
||
const individualPscListRouter: Router = Router({ mergeParams: true }); | ||
|
||
individualPscListRouter.get("/", handleExceptions(async (req: Request, res: Response, _next: NextFunction) => { | ||
const handler = new IndividualPscListHandler(); | ||
const companyProfile: CompanyProfile = res.locals?.companyProfile; | ||
const companyNumber = companyProfile.companyNumber; | ||
const lang = req.query.lang as string; | ||
const { templatePath, viewData } = await handler.executeGet(req, res); | ||
res.render(templatePath, viewData); | ||
|
||
if (viewData.exclusivelySuperSecure) { | ||
logger.debug(`individualPscListRouter.get - PSCs are exclusively Super Secure for company number ${companyNumber}: paper filing is required`); | ||
res.redirect(addSearchParams(getUrlWithStopType(PrefixedUrls.STOP_SCREEN, STOP_TYPE.SUPER_SECURE), { companyNumber, lang })); | ||
} else { | ||
res.render(templatePath, viewData); | ||
} | ||
})); | ||
|
||
export default individualPscListRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,60 @@ | ||
import request from "supertest"; | ||
import * as cheerio from "cheerio"; | ||
import mockSessionMiddleware from "../mocks/sessionMiddleware.mock"; | ||
import mockAuthenticationMiddleware from "../mocks/authenticationMiddleware.mock"; | ||
import app from "../../src/app"; | ||
import { PrefixedUrls } from "../../src/constants"; | ||
import { PrefixedUrls, STOP_TYPE } from "../../src/constants"; | ||
import { getCompanyProfile } from "../../src/services/companyProfileService"; | ||
import { getCompanyIndividualPscList } from "../../src/services/companyPscService"; | ||
import { validCompanyProfile } from "../mocks/companyProfile.mock"; | ||
import { COMPANY_NUMBER, INDIVIDUAL_PSCS_LIST } from "../mocks/companyPsc.mock"; | ||
import { COMPANY_NUMBER, INDIVIDUAL_PSCS_LIST, SUPER_SECURE_PSCS_EXCLUSIVE_LIST } from "../mocks/companyPsc.mock"; | ||
import { HttpStatusCode } from "axios"; | ||
import { getUrlWithStopType } from "../../src/utils/url"; | ||
|
||
jest.mock("../../src/services/companyProfileService"); | ||
const mockGetCompanyProfile = getCompanyProfile as jest.Mock; | ||
mockGetCompanyProfile.mockResolvedValue(validCompanyProfile); | ||
|
||
jest.mock("../../src/services/companyPscService"); | ||
const mockGetCompanyIndividualPscList = getCompanyIndividualPscList as jest.Mock; | ||
mockGetCompanyIndividualPscList.mockResolvedValue(INDIVIDUAL_PSCS_LIST); | ||
|
||
describe("GET psc individual list router", () => { | ||
beforeEach(() => { | ||
}); | ||
|
||
afterEach(() => { | ||
it("Should return with a successful status code", async () => { | ||
mockGetCompanyIndividualPscList.mockResolvedValue(INDIVIDUAL_PSCS_LIST); | ||
|
||
const resp = await request(app).get(PrefixedUrls.INDIVIDUAL_PSC_LIST + `?companyNumber=${COMPANY_NUMBER}&lang=en`); | ||
|
||
expect(resp.status).toBe(HttpStatusCode.Ok); | ||
expect(mockSessionMiddleware).toHaveBeenCalledTimes(1); | ||
expect(mockAuthenticationMiddleware).toHaveBeenCalledTimes(1); | ||
expect(mockGetCompanyProfile).toHaveBeenCalledTimes(1); | ||
expect(mockGetCompanyIndividualPscList).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it("Should return with a successful status code", async () => { | ||
it("Should render PSC List screen for ordinary PSCs only, when Super Secure are present", async () => { | ||
const ordinaryAndSuperSecurePscs = [...INDIVIDUAL_PSCS_LIST, ...SUPER_SECURE_PSCS_EXCLUSIVE_LIST]; | ||
|
||
mockGetCompanyIndividualPscList.mockResolvedValue(ordinaryAndSuperSecurePscs); | ||
|
||
const resp = await request(app).get(PrefixedUrls.INDIVIDUAL_PSC_LIST + `?companyNumber=${COMPANY_NUMBER}&lang=en`); | ||
|
||
expect(resp.status).toBe(HttpStatusCode.Ok); | ||
const $ = cheerio.load(resp.text); | ||
const pscNameCardTitles = [...$("div.govuk-summary-card__title-wrapper > h2").contents()].map(e => $(e).text().trim()); | ||
const templatePlaceholderName = "[Name of the psc]"; | ||
const expectedPscNames = [...INDIVIDUAL_PSCS_LIST.map(p => p.name), templatePlaceholderName]; | ||
expect(pscNameCardTitles).toMatchObject(expectedPscNames); | ||
}); | ||
|
||
it("Should redirect to super secure stop screen if PSCs are exclusively Super Secure", async () => { | ||
mockGetCompanyIndividualPscList.mockResolvedValue(SUPER_SECURE_PSCS_EXCLUSIVE_LIST); | ||
|
||
const resp = await request(app).get(PrefixedUrls.INDIVIDUAL_PSC_LIST + `?companyNumber=${COMPANY_NUMBER}&lang=en`); | ||
|
||
expect(resp.status).toBe(HttpStatusCode.Found); | ||
expect(resp.header.location).toBe(`${getUrlWithStopType(PrefixedUrls.STOP_SCREEN, STOP_TYPE.SUPER_SECURE)}?companyNumber=12345678&lang=en`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters