Skip to content

Commit 0ec50ae

Browse files
committed
chore: [AB#17315] move cigarette health checks behind a feature flag
1 parent 19d0da6 commit 0ec50ae

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

api/src/libs/healthCheck.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
import { runHealthChecks } from "@libs/healthCheck";
22
import { DummyLogWriter } from "@libs/logWriter";
3+
import { CONFIG_VARS, getConfigValue } from "@libs/ssmUtils";
34
import axios from "axios";
45

56
jest.mock("axios");
67
const mockAxios = axios as jest.Mocked<typeof axios>;
78

9+
jest.mock("@libs/ssmUtils", () => ({
10+
getConfigValue: jest.fn(),
11+
}));
12+
13+
const mockGetConfigValue = getConfigValue as jest.MockedFunction<typeof getConfigValue>;
14+
815
describe("healthCheck", () => {
916
const logger = DummyLogWriter;
1017

18+
beforeEach(() => {
19+
mockGetConfigValue.mockImplementation(async (paramName: CONFIG_VARS) => {
20+
if (paramName === "FEATURE_CIGARETTE_LICENSE") return "true";
21+
return "false";
22+
});
23+
});
24+
1125
it("returns an object with pass statuses if success is true", async () => {
1226
mockAxios.get.mockResolvedValue({ data: { success: true } });
1327
expect(await runHealthChecks(logger)).toStrictEqual({
@@ -61,4 +75,22 @@ describe("healthCheck", () => {
6175
taxFilingClient: "ERROR",
6276
});
6377
});
78+
79+
describe("flagged health checks", () => {
80+
it("includes cigarette health checks when feature flag is on", async () => {
81+
const result = await runHealthChecks(logger);
82+
expect(Object.keys(result)).toContain("cigaretteLicense");
83+
expect(Object.keys(result)).toContain("cigaretteEmailClient");
84+
});
85+
86+
it("excludes cigarette health checks when feature flag is off", async () => {
87+
mockGetConfigValue.mockImplementation(async () => {
88+
return "false";
89+
});
90+
91+
const result = await runHealthChecks(logger);
92+
expect(Object.keys(result)).not.toContain("cigaretteLicense");
93+
expect(Object.keys(result)).not.toContain("cigaretteEmailClient");
94+
});
95+
});
6496
});

api/src/libs/healthCheck.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CloudWatchClient, PutMetricDataCommand } from "@aws-sdk/client-cloudwatch";
22
import { LogWriterType } from "@libs/logWriter";
3+
import { getConfigValue } from "@libs/ssmUtils";
34
import axios, { AxiosError, AxiosResponse } from "axios";
45

56
type Status = "PASS" | "FAIL" | "ERROR";
@@ -17,11 +18,23 @@ const healthCheckEndPoints: Record<string, string> = {
1718
webserviceFormation: "webservice/formation",
1819
taxClearance: "tax-clearance",
1920
xrayRegistration: "xray-registration",
20-
cigaretteEmailClient: "cigarette-email-client",
21-
cigaretteLicense: "cigarette-license",
2221
taxFilingClient: "tax-filing-client",
2322
};
2423

24+
const addFlaggedHealthChecks = (
25+
endpoints: Record<string, string>,
26+
flagValues: { cigarette: boolean },
27+
): Record<string, string> => {
28+
if (flagValues.cigarette) {
29+
return {
30+
...endpoints,
31+
cigaretteEmailClient: "cigarette-email-client",
32+
cigaretteLicense: "cigarette-license",
33+
};
34+
}
35+
return endpoints;
36+
};
37+
2538
const healthCheck = async (type: string, url: string, logger: LogWriterType): Promise<Status> => {
2639
const fullUrl = `${url}/health/${type}`;
2740

@@ -82,7 +95,14 @@ export const runHealthChecks = async (logger: LogWriterType): Promise<StatusResu
8295
throw new Error("API URL is undefined");
8396
}
8497

85-
const entries = Object.entries(healthCheckEndPoints).map(([type, endpoint]) =>
98+
const isCigaretteLicenseEnabled =
99+
(await getConfigValue("FEATURE_CIGARETTE_LICENSE", logger)) === "true";
100+
101+
const endpoints = addFlaggedHealthChecks(healthCheckEndPoints, {
102+
cigarette: isCigaretteLicenseEnabled,
103+
});
104+
105+
const entries = Object.entries(endpoints).map(([type, endpoint]) =>
86106
healthCheck(endpoint ?? "", url, logger).then((result) => [type, result] as const),
87107
);
88108

api/src/libs/ssmUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export type CONFIG_VARS =
1414
| ENV_REQ_CONFIG_VARS
1515
| USER_MESSAGING_CONFIG_VARS
1616
| "dep_base_url"
17-
| "zod_parsing_on";
17+
| "zod_parsing_on"
18+
| "FEATURE_CIGARETTE_LICENSE";
1819

1920
export type CIGARETTE_PAYMENT_CONFIG_VARS =
2021
| "cigarette_license_base_url"

0 commit comments

Comments
 (0)