Skip to content

Commit 151e3b0

Browse files
VIA-206 MD Add Eligibility API endpoint fetch call + test to wiremock for now
1 parent f08a2cd commit 151e3b0

File tree

8 files changed

+124
-69
lines changed

8 files changed

+124
-69
lines changed

src/_lambda/content-cache-hydrator/content-fetcher.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const fetchContentForVaccine = async (
2121

2222
const uri: string = `${apiEndpoint}${CONTENT_API_PATH_PREFIX}${vaccinePath}`;
2323
let response: AxiosResponse;
24+
2425
try {
2526
log.info("Fetching content from %s", uri);
2627
response = await axios.get(uri, {

src/app/_components/vaccine/Vaccine.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { render, screen } from "@testing-library/react";
99
import { ContentErrorTypes } from "@src/services/content-api/types";
1010
import { EligibilityStatus } from "@src/services/eligibility-api/types";
11-
import { getEligibilityContentForPerson } from "@src/services/eligibility-api/gateway/eligibility-reader-service";
11+
import { getEligibilityForPerson } from "@src/services/eligibility-api/gateway/eligibility-reader-service";
1212
import { mockStyledEligibility } from "@test-data/eligibility-api/data";
1313

1414
jest.mock("@src/services/content-api/gateway/content-reader-service");
@@ -31,7 +31,7 @@ describe("Any vaccine page", () => {
3131
(getContentForVaccine as jest.Mock).mockResolvedValue({
3232
styledVaccineContent: mockStyledContent,
3333
});
34-
(getEligibilityContentForPerson as jest.Mock).mockResolvedValue({
34+
(getEligibilityForPerson as jest.Mock).mockResolvedValue({
3535
styledEligibilityContent: mockStyledEligibility,
3636
});
3737
});
@@ -182,7 +182,7 @@ describe("Any vaccine page", () => {
182182

183183
describe("when eligible", () => {
184184
beforeEach(() => {
185-
(getEligibilityContentForPerson as jest.Mock).mockResolvedValue({
185+
(getEligibilityForPerson as jest.Mock).mockResolvedValue({
186186
eligibilityStatus: EligibilityStatus.ELIGIBLE_BOOKABLE,
187187
styledEligibilityContent: mockStyledEligibility,
188188
});
@@ -198,7 +198,7 @@ describe("Any vaccine page", () => {
198198

199199
describe("when not eligible", () => {
200200
beforeEach(() => {
201-
(getEligibilityContentForPerson as jest.Mock).mockResolvedValue({
201+
(getEligibilityForPerson as jest.Mock).mockResolvedValue({
202202
eligibilityStatus: EligibilityStatus.NOT_ELIGIBLE,
203203
styledEligibilityContent: mockStyledEligibility,
204204
});
@@ -265,7 +265,7 @@ describe("Any vaccine page", () => {
265265
(getContentForVaccine as jest.Mock).mockResolvedValue({
266266
styledVaccineContent: mockStyledContent,
267267
});
268-
(getEligibilityContentForPerson as jest.Mock).mockResolvedValue({
268+
(getEligibilityForPerson as jest.Mock).mockResolvedValue({
269269
styledEligibilityContent: mockStyledEligibility,
270270
});
271271
});

src/services/eligibility-api/gateway/eligibility-reader-service.test.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,23 @@
11
import { VaccineTypes } from "@src/models/vaccine";
2-
import { GetEligibilityForPersonResponse } from "@src/services/eligibility-api/types";
3-
import { AppConfig, configProvider } from "@src/utils/config";
4-
import axios, { AxiosResponse } from "axios";
5-
import { logger } from "@src/utils/logger";
2+
import {
3+
EligibilityStatus,
4+
GetEligibilityForPersonResponse,
5+
} from "@src/services/eligibility-api/types";
66

7-
const log = logger.child({ module: "content-fetcher" });
8-
const ELIGIBILITY_API_PATH_PREFIX = "/patient-check/";
9-
10-
const getEligibilityContentForPerson = async (
7+
const getEligibilityForPerson = async (
118
nhsNumber: string, // eslint-disable-line @typescript-eslint/no-unused-vars
129
vaccineType: VaccineTypes, // eslint-disable-line @typescript-eslint/no-unused-vars
1310
): Promise<GetEligibilityForPersonResponse> => {
14-
const config: AppConfig = await configProvider();
15-
16-
const apiEndpoint: string = config.ELIGIBILITY_API_ENDPOINT;
17-
const apiKey: string = config.ELIGIBILITY_API_KEY;
11+
const styledEligibilityContent = {
12+
heading: "dummy heading",
13+
content: "dummy content",
14+
};
1815

19-
const uri: string = `${apiEndpoint}${ELIGIBILITY_API_PATH_PREFIX}/${nhsNumber}`;
20-
let response: AxiosResponse;
21-
try {
22-
log.info("Fetching content from %s", uri);
23-
response = await axios.get(uri, {
24-
headers: {
25-
accept: "application/json",
26-
apikey: apiKey,
27-
},
28-
});
29-
log.info("Successfully fetched content from %s", uri);
30-
return response.data;
31-
} catch (error) {
32-
log.error(`Error in fetching ${uri}: ${error}`);
33-
throw error;
34-
}
35-
// const styledEligibilityContent = {
36-
// heading: "dummy heading",
37-
// content: "dummy content",
38-
// };
39-
//
40-
// return {
41-
// eligibilityStatus: EligibilityStatus.NOT_ELIGIBLE,
42-
// styledEligibilityContent,
43-
// eligibilityError: undefined,
44-
// };
16+
return {
17+
eligibilityStatus: EligibilityStatus.NOT_ELIGIBLE,
18+
styledEligibilityContent,
19+
eligibilityError: undefined,
20+
};
4521
};
4622

47-
export { getEligibilityContentForPerson };
23+
export { getEligibilityForPerson };
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @jest-environment node
3+
*/
4+
5+
import { expect } from "@playwright/test";
6+
import { mockEligibilityResponse } from "@test-data/eligibility-api/data";
7+
import { fetchEligibilityContent } from "@src/services/eligibility-api/gateway/fetch-eligibility-content";
8+
import { AppConfig, configProvider } from "@src/utils/config";
9+
10+
jest.mock("@src/utils/config");
11+
12+
describe("getEligibilityContentForPerson", () => {
13+
const testApiKey: string = "api key";
14+
const testApiEndpoint: string =
15+
"http://localhost:8081/eligibility-signposting-api/"; // is wiremock, but will not work in CI/CD
16+
17+
beforeEach(() => {
18+
(configProvider as jest.Mock).mockImplementation(
19+
(): Partial<AppConfig> => ({
20+
ELIGIBILITY_API_KEY: testApiKey,
21+
ELIGIBILITY_API_ENDPOINT: testApiEndpoint,
22+
}),
23+
);
24+
});
25+
26+
it("return eligibility content for non-eligible person", async () => {
27+
const nhsNumber: string = "5000000014";
28+
29+
const response = await fetchEligibilityContent(nhsNumber);
30+
31+
expect(response).toEqual(mockEligibilityResponse);
32+
});
33+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { AppConfig, configProvider } from "@src/utils/config";
2+
import axios, { AxiosResponse } from "axios";
3+
import { logger } from "@src/utils/logger";
4+
5+
const log = logger.child({ module: "fetch-eligibility-content" });
6+
const ELIGIBILITY_API_PATH_SUFFIX = "patient-check";
7+
8+
export const fetchEligibilityContent = async (nhsNumber: string) => {
9+
const config: AppConfig = await configProvider();
10+
11+
const apiEndpoint: string = config.ELIGIBILITY_API_ENDPOINT;
12+
const apiKey: string = config.ELIGIBILITY_API_KEY;
13+
14+
const uri: string = `${apiEndpoint}${ELIGIBILITY_API_PATH_SUFFIX}/${nhsNumber}`;
15+
let response: AxiosResponse;
16+
try {
17+
log.info("Fetching content from %s", uri);
18+
response = await axios.get(uri, {
19+
headers: {
20+
accept: "application/json",
21+
apikey: apiKey,
22+
},
23+
});
24+
log.info("Successfully fetched content from %s", uri);
25+
return response.data;
26+
} catch (error) {
27+
console.error("Aggregate error caught:", error);
28+
log.error(`Error in fetching ${uri}: ${error}`);
29+
throw error;
30+
}
31+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"responseId": "1a233ba5-e1eb-4080-a086-2962f6fc3473",
3+
"meta": {
4+
"lastUpdated": "2025-02-12T16:11:22Z"
5+
},
6+
"processedSuggestions": [
7+
{
8+
"condition": "RSV",
9+
"status": "NotEligible",
10+
"statusText": "We do not believe you should have this vaccine",
11+
"eligibilityCohorts": [
12+
{
13+
"cohortCode": "rsv_age_rolling",
14+
"cohortText": "You are not aged 75 to 79 years old.",
15+
"cohortStatus": "NotEligible"
16+
},
17+
{
18+
"cohortCode": "rsv_age_catchup",
19+
"cohortText": "You did not turn 80 between 2nd September 2024 and 31st August 2025",
20+
"cohortStatus": "NotEligible"
21+
}
22+
]
23+
}
24+
]
25+
}

wiremock/mappings/mapping-vaccines.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@
5151
"Content-Type": "application/json"
5252
}
5353
}
54+
},
55+
{
56+
"request": {
57+
"method": "GET",
58+
"url": "/eligibility-signposting-api/patient-check/5000000014"
59+
},
60+
"response": {
61+
"status": 200,
62+
"bodyFileName": "non-eligible-person.json",
63+
"headers": {
64+
"Content-Type": "application/json",
65+
"apikey": "api key"
66+
}
67+
}
5468
}
5569
]
5670
}

0 commit comments

Comments
 (0)