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 branch 'main' into feature/update-library-versions
- Loading branch information
Showing
11 changed files
with
397 additions
and
46 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { logger } from "./../../logger"; | ||
import { GenericValidator } from "./../../validation/generic"; | ||
|
||
export class PscVerificationFormsValidator extends GenericValidator { | ||
|
||
constructor (classParam?: string) { | ||
super(); | ||
} | ||
|
||
validatePscType (payload: any): Promise<Object> { | ||
logger.info(`Request to validate PSC-Type form`); | ||
try { | ||
if (typeof payload.pscType === "undefined" || !this.isValidPscType(payload.pscType)) { | ||
this.errors.stack.pscType = this.errorManifest.validation.pscType.blank; | ||
} | ||
|
||
// validate additional form fields here | ||
|
||
if (!Object.keys(this.errors.stack).length) { | ||
return Promise.resolve({}); | ||
} else { | ||
return Promise.reject(this.errors); | ||
} | ||
} catch (err) { | ||
this.errors.serverError = this.errorManifest.generic.serverError; | ||
return Promise.reject(this.errors); | ||
} | ||
} | ||
|
||
validateRleVerificationStatus (payload: any): Promise<any> { | ||
return Promise.resolve({}); | ||
} | ||
|
||
validateRelevantOfficerDetails (payload: any): Promise<any> { | ||
return Promise.resolve({}); | ||
} | ||
|
||
validateRelevantOfficerConfirmationStatements (payload: any): Promise<any> { | ||
return Promise.resolve({}); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Single field validators that are called by the form validators or "field-group" validators | ||
|
||
import { logger } from "./../logger"; | ||
import errorManifest from "../utils/error-manifests/errorManifest"; | ||
|
||
export class GenericValidator { | ||
|
||
errors: any; | ||
payload: any; | ||
errorManifest: any; | ||
|
||
constructor () { | ||
this.errors = this.getErrorSignature(); | ||
this.errorManifest = errorManifest; | ||
} | ||
|
||
protected getErrorSignature () { | ||
return { | ||
status: 400, | ||
name: "VALIDATION_ERRORS", | ||
message: errorManifest.validation.default.summary, | ||
stack: {} | ||
}; | ||
} | ||
|
||
isValidPscType (pscType: string): boolean { | ||
logger.info(`Request to validate PSC Type`); | ||
// List of PSC types can be separated out into a util file | ||
if (["individual", "rle"].includes(pscType)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
isValidFirstName (firstName: string): boolean { | ||
logger.info(`Request to validate email: ${firstName}`); | ||
const regex = /^[a-z\d_-][a-z\d_\-.\s&]{1,71}$/ig; | ||
if (regex.test(firstName)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
isValidMiddleName (middleName: string): boolean { | ||
logger.info(`Request to validate company name: ${middleName}`); | ||
const regex = /^[a-z\d_-][a-z\d_\-.\s&]{1,71}$/ig; | ||
if (regex.test(middleName)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
isValidLastName (lastName: string): boolean { | ||
logger.info(`Request to validate company name: ${lastName}`); | ||
const regex = /^[a-z\d_-][a-z\d_\-.\s&]{1,71}$/ig; | ||
if (regex.test(lastName)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
isValidDateOfBirth (dob: string): boolean { | ||
logger.info(`Request to validate PostCode: ${dob}`); | ||
|
||
// use Luxon to validate DOB | ||
|
||
if (dob) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { HttpStatusCode } from "axios"; | ||
import * as cheerio from "cheerio"; | ||
import request from "supertest"; | ||
import middlewareMocks from "../../../mocks/allMiddleware.mock"; | ||
import app from "../../../../src/app"; | ||
import { PrefixedUrls } from "../../../../src/constants"; | ||
import { getUrlWithTransactionIdAndSubmissionId } from "../../../../src/utils/url"; | ||
import { CREATED_RESOURCE, PSC_VERIFICATION_ID, TRANSACTION_ID } from "../../../mocks/pscVerification.mock"; | ||
import { getPscVerification } from "../../../../src/services/pscVerificationService"; | ||
import { URLSearchParams } from "url"; | ||
|
||
jest.mock("../../../../src/services/pscVerificationService", () => ({ | ||
getPscVerification: () => ({ | ||
httpStatusCode: HttpStatusCode.Ok, | ||
resource: CREATED_RESOURCE | ||
}) | ||
})); | ||
|
||
const mockGetPscVerification = getPscVerification as jest.Mock; | ||
|
||
describe.skip("psc type view", () => { | ||
|
||
beforeEach(() => { | ||
middlewareMocks.mockSessionMiddleware.mockClear(); | ||
}); | ||
|
||
afterEach(() => { | ||
expect(middlewareMocks.mockSessionMiddleware).toHaveBeenCalledTimes(1); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
/** | ||
* This test does not appear to be needed. Will skip it for now until there has been another discussion around it. | ||
*/ | ||
it.each([[undefined, undefined], ["individual", "pscType=individual"], ["rle", "pscType=rle"]])("Should render the Psc Type page with a success status code and %s radio button checked", async (expectedSelection, expectedQuery) => { | ||
const queryParams = new URLSearchParams(expectedQuery); | ||
const uriWithQuery = `${PrefixedUrls.PSC_TYPE}?${queryParams}`; | ||
const uri = getUrlWithTransactionIdAndSubmissionId(uriWithQuery, TRANSACTION_ID, PSC_VERIFICATION_ID); | ||
|
||
const resp = await request(app).get(uri); | ||
|
||
const $ = cheerio.load(resp.text); | ||
|
||
expect(resp.status).toBe(HttpStatusCode.Ok); | ||
expect($("input[name=pscType]:checked").val()).toBe(expectedSelection); | ||
}); | ||
|
||
}); |
Oops, something went wrong.