Skip to content

Commit

Permalink
Add healthcheck endpoint
Browse files Browse the repository at this point in the history
- fix h2 tag mismatch in start.njk
- revert govuk-frontent to 4.8.0
  • Loading branch information
hepsimo committed Oct 22, 2024
1 parent 7dfdf26 commit 631d642
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 17 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"express": "^4.21.1",
"govuk_frontend_toolkit": "^9.0.1",
"govuk-elements-sass": "^3.1.3",
"govuk-frontend": "^4.9.0",
"govuk-frontend": "^4.8.0",
"http-errors": "^1.8.1",
"ioredis": "4.28.5",
"js-yaml": "^3.14.1",
Expand Down Expand Up @@ -104,7 +104,7 @@
"overrides": {
"chokidar": "3.5.3",
"glob-parent": "6.0.2",
"micromatch":"4.0.8"
"micromatch": "4.0.8"
},
"nodemonConfig": {
"watch": [
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const urlWithTransactionIdAndSubmissionId = "/transaction/:transactionId/submiss

export const Urls = {
ACCESSIBILITY_STATEMENT: "/persons-with-significant-control-verification",
HEALTHCHECK: "/healthcheck",
START: "/start",
COMPANY_NUMBER: "/company-number",
CONFIRM_COMPANY: "/confirm-company",
Expand All @@ -23,6 +24,7 @@ export const Urls = {
export const PrefixedUrls = {
ACCESSIBILITY_STATEMENT: servicePathPrefix + Urls.ACCESSIBILITY_STATEMENT,
START: servicePathPrefix + Urls.START,
HEALTHCHECK: servicePathPrefix + Urls.HEALTHCHECK,
COMPANY_NUMBER: servicePathPrefix + Urls.COMPANY_NUMBER,
CONFIRM_COMPANY: servicePathPrefix + Urls.CONFIRM_COMPANY,
NEW_SUBMISSION: servicePathPrefix + Urls.NEW_SUBMISSION,
Expand Down
3 changes: 2 additions & 1 deletion src/routerDispatch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Do Router dispatch here, i.e. map incoming routes to appropriate router
import { Application, Request, Response, Router } from "express";
import { Urls, servicePathPrefix } from "./constants";
import { CompanyNumberRouter, ConfirmCompanyRouter, ConfirmRoStatementsRouter, IndividualPscListRouter, IndividualStatementRouter, NewSubmissionRouter, NotADirectorRouter, PersonalCodeRouter, PscTypeRouter, PscVerifiedRouter, RleDetailsRouter, RleDirectorRouter, RlePscListRouter, RleVerifiedRouter, StartRouter } from "./routers/utils";
import { CompanyNumberRouter, ConfirmCompanyRouter, ConfirmRoStatementsRouter, HealthCheckRouter, IndividualPscListRouter, IndividualStatementRouter, NewSubmissionRouter, NotADirectorRouter, PersonalCodeRouter, PscTypeRouter, PscVerifiedRouter, RleDetailsRouter, RleDirectorRouter, RlePscListRouter, RleVerifiedRouter, StartRouter } from "./routers/utils";
import { authenticate } from "./middleware/authentication";
import { fetchVerification } from "./middleware/fetchVerification";
import { fetchCompany } from "./middleware/fetchCompany";
Expand All @@ -14,6 +14,7 @@ const routerDispatch = (app: Application) => {

router.use("/", StartRouter);
router.use(Urls.START, StartRouter);
router.use(Urls.HEALTHCHECK, HealthCheckRouter);
router.use(Urls.COMPANY_NUMBER, authenticate, CompanyNumberRouter);
router.use(Urls.CONFIRM_COMPANY, authenticate, ConfirmCompanyRouter);
router.use(Urls.NEW_SUBMISSION, authenticate, NewSubmissionRouter);
Expand Down
13 changes: 13 additions & 0 deletions src/routers/healthCheckRouter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { HttpStatusCode } from "axios";
import { Request, Response, Router } from "express";
import { logger } from "../lib/logger";

const healthCheckRouter: Router = Router();

healthCheckRouter.get("/", (req: Request, res: Response) => {
logger.debugRequest(req, `GET healthcheck`);

res.status(HttpStatusCode.Ok).send("OK");
});

export default healthCheckRouter;
3 changes: 2 additions & 1 deletion src/routers/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import StartRouter from "./../startRouter";
import HealthCheckRouter from "./../healthCheckRouter";
import CompanyNumberRouter from "./../companyNumberRouter";
import ConfirmCompanyRouter from "./../confirmCompanyRouter";
import NewSubmissionRouter from "./../newSubmissionRouter";
Expand All @@ -14,7 +15,7 @@ import ConfirmRoStatementsRouter from "./../confirmRoStatementsRouter";
import NotADirectorRouter from "./../notADirectorRouter";
import RleVerifiedRouter from "./../rleVerifiedRouter";
import { logger } from "../../lib/logger";
export { StartRouter, CompanyNumberRouter, ConfirmCompanyRouter, PscTypeRouter, IndividualPscListRouter, PersonalCodeRouter, IndividualStatementRouter, NewSubmissionRouter, NotADirectorRouter, PscVerifiedRouter, RlePscListRouter, RleDetailsRouter, RleDirectorRouter, RleVerifiedRouter, ConfirmRoStatementsRouter };
export { StartRouter, HealthCheckRouter, CompanyNumberRouter, ConfirmCompanyRouter, PscTypeRouter, IndividualPscListRouter, PersonalCodeRouter, IndividualStatementRouter, NewSubmissionRouter, NotADirectorRouter, PscVerifiedRouter, RlePscListRouter, RleDetailsRouter, RleDirectorRouter, RleVerifiedRouter, ConfirmRoStatementsRouter };

export function formatDateBorn (dateOfBirth: any, lang: string): string {
try {
Expand Down
10 changes: 5 additions & 5 deletions src/views/router_views/start/start.njk
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

<h1 class="govuk-heading-l">{{ i18n.start_main_title }}</h1>
<p class="govuk-body-l">{{ i18n.start_service_description }}</p>

{{ govukInsetText({
text: i18n.start_inset_text
}) }}

<p class="govuk-body">{{ i18n.start_service_restriction_description }}</p>
<h2 class="govuk-heading-m">{{ i18n.start_when_to_verify_heading }}</h1>

<h2 class="govuk-heading-m">{{ i18n.start_when_to_verify_heading }}</h2>
<p class="govuk-body">{{ i18n.start_when_to_verify_description1 }}</p>
<p class="govuk-body">{{ i18n.start_when_to_verify_description2 }}</p>
<p class="govuk-body">{{ i18n.start_when_to_verify_description3 }}</p>
Expand All @@ -39,7 +39,7 @@

<p class="govuk-body"> {{i18n.start_before_list}} </p>


<ul class="govuk-list govuk-list--bullet">
<li>{{ i18n.start_before_list_item1 }}</li>
<li>{{ i18n.start_before_list_item2 }}</li>
Expand All @@ -59,7 +59,7 @@
"data-event-id": "what-is-ch-personal-code-dropdown"
}
}) }}

<h3 class="govuk-heading-s">{{ i18n.start_providing_details_for_rle }}</h3>
<p class="govuk-body">{{ i18n.start_details_for_rle_description1 }}</p>
<p class="govuk-body">{{ i18n.start_details_for_rle_description2 }}</p>
Expand Down
8 changes: 4 additions & 4 deletions terraform/groups/ecs-service/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ locals {
kms_alias = "alias/${var.aws_profile}/environment-services-kms"
lb_listener_rule_priority = 161
lb_listener_paths = ["/persons-with-significant-control-verification*"]
healthcheck_path = "/persons-with-significant-control-verification"
healthcheck_matcher = "200" # no explicit healthcheck in this service yet, change this when added!
healthcheck_path = "/persons-with-significant-control-verification/healthcheck"
healthcheck_matcher = "200"
vpc_name = data.aws_ssm_parameter.secret[format("/%s/%s", local.name_prefix, "vpc-name")].value
s3_config_bucket = data.vault_generic_secret.shared_s3.data["config_bucket_name"]
app_environment_filename = "psc-verification-web.env"
Expand All @@ -34,7 +34,7 @@ locals {
trimprefix(sec.name, "/${local.global_prefix}/") => sec.arn
}

global_secret_list = flatten([for key, value in local.global_secrets_arn_map :
global_secret_list = flatten([for key, value in local.global_secrets_arn_map :
{ "name" = upper(key), "valueFrom" = value }
])

Expand All @@ -49,7 +49,7 @@ locals {
trimprefix(sec.name, "/${local.service_name}-${var.environment}/") => sec.arn
}

service_secret_list = flatten([for key, value in local.service_secrets_arn_map :
service_secret_list = flatten([for key, value in local.service_secrets_arn_map :
{ "name" = upper(key), "valueFrom" = value }
])

Expand Down
28 changes: 28 additions & 0 deletions test/routers/healthCheck.int.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import middlewareMocks from "../mocks/allMiddleware.mock";
import request from "supertest";
import app from "../../src/app";
import { PrefixedUrls } from "../../src/constants";
import { HttpStatusCode } from "axios";

jest.mock("ioredis");

describe("Healthcheck integration tests", () => {
beforeEach(() => {
jest.clearAllMocks();
});

afterEach(() => {
expect(middlewareMocks.mockSessionMiddleware).toHaveBeenCalledTimes(1);
});

describe("GET method", () => {

it("should return status 200 and content 'OK'", async () => {
const resp = await request(app).get(PrefixedUrls.HEALTHCHECK);

expect(resp.status).toBe(HttpStatusCode.Ok);
expect(resp.text).toBe("OK");
});

});
});

0 comments on commit 631d642

Please sign in to comment.