Skip to content

Commit e160824

Browse files
VIA-629 AJ/EO Fix tests for covid-19
1 parent 24b9866 commit e160824

File tree

2 files changed

+2
-86
lines changed

2 files changed

+2
-86
lines changed
Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,17 @@
11
import { buildFilteredContentForCovid19Vaccine } from "@src/services/content-api/parsers/custom/covid-19";
22
import { ActionDisplayType, ButtonUrl, Content, Label } from "@src/services/eligibility-api/types";
33
import { buildNbsUrl } from "@src/services/nbs/nbs-service";
4-
import { Campaigns } from "@src/utils/campaigns/types";
5-
import config from "@src/utils/config";
6-
import { ConfigMock, configBuilder } from "@test-data/config/builders";
74
import { genericVaccineContentAPIResponse } from "@test-data/content-api/data";
8-
import { headers } from "next/headers";
95

106
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
117
jest.mock("@src/services/nbs/nbs-service", () => ({ buildNbsUrl: jest.fn() }));
12-
jest.mock("next/headers");
138

149
describe("buildFilteredContentForCovid19Vaccine", () => {
15-
const mockedConfig = config as ConfigMock;
16-
1710
beforeEach(() => {
18-
const defaultConfig = configBuilder()
19-
.withCampaigns(
20-
Campaigns.fromJson(
21-
JSON.stringify({
22-
COVID_19: [
23-
{ start: "2025-11-01T09:00:00Z", end: "2026-01-31T09:00:00Z" },
24-
{ start: "2026-11-01T09:00:00Z", end: "2027-01-31T09:00:00Z" },
25-
],
26-
}),
27-
)!,
28-
)
29-
.build();
30-
Object.assign(mockedConfig, defaultConfig);
31-
3211
(buildNbsUrl as jest.Mock).mockResolvedValue(new URL("https://test-nbs-url.example.com/sausages"));
33-
34-
const mockHeaders = {
35-
get: jest.fn(),
36-
};
37-
(headers as jest.Mock).mockResolvedValue(mockHeaders);
3812
});
3913

40-
jest.useFakeTimers();
41-
4214
it("should return standard vaccine content and additional content for COVID-19 vaccine", async () => {
43-
jest.setSystemTime(new Date("2025-10-01"));
44-
4515
const pageCopyForCovid19Vaccine = await buildFilteredContentForCovid19Vaccine(
4616
JSON.stringify(genericVaccineContentAPIResponse),
4717
);
@@ -58,10 +28,7 @@ describe("buildFilteredContentForCovid19Vaccine", () => {
5828
expect(pageCopyForCovid19Vaccine.recommendation?.heading).toEqual("The COVID-19 vaccine is recommended if you:");
5929
});
6030

61-
it("should return a callout but no actions when no campaign is active", async () => {
62-
// Given
63-
jest.setSystemTime(new Date("2025-10-01"));
64-
31+
it("should return callout and actions", async () => {
6532
const expected = {
6633
callout: {
6734
heading: "Booking service closed",
@@ -71,21 +38,6 @@ describe("buildFilteredContentForCovid19Vaccine", () => {
7138
"COVID-19 vaccinations will be available again in spring.",
7239
contentType: "markdown",
7340
},
74-
};
75-
76-
// When
77-
const pageCopy = await buildFilteredContentForCovid19Vaccine(JSON.stringify(genericVaccineContentAPIResponse));
78-
79-
// Then
80-
expect(pageCopy).toEqual(expect.objectContaining(expected));
81-
expect(pageCopy.actions).toHaveLength(0);
82-
});
83-
84-
it("should return actions but no callout when no campaign is active", async () => {
85-
// Given
86-
jest.setSystemTime(new Date("2025-12-01"));
87-
88-
const expected = {
8941
actions: [
9042
{
9143
type: ActionDisplayType.buttonWithInfo,
@@ -112,43 +64,8 @@ describe("buildFilteredContentForCovid19Vaccine", () => {
11264
],
11365
};
11466

115-
// When
11667
const pageCopy = await buildFilteredContentForCovid19Vaccine(JSON.stringify(genericVaccineContentAPIResponse));
11768

118-
// Then
11969
expect(pageCopy).toEqual(expect.objectContaining(expected));
120-
expect(pageCopy.callout).toBeUndefined();
121-
});
122-
123-
describe("with x-e2e-datetime header set", () => {
124-
it("should return a callout but no actions when no campaign is active", async () => {
125-
const mockHeaders = {
126-
get: jest.fn((key: string) => {
127-
if (key === "x-e2e-datetime") return "2025-10-01T12:00:00Z";
128-
return null;
129-
}),
130-
};
131-
(headers as jest.Mock).mockResolvedValue(mockHeaders);
132-
133-
const pageCopy = await buildFilteredContentForCovid19Vaccine(JSON.stringify(genericVaccineContentAPIResponse));
134-
135-
expect(pageCopy.callout).not.toBeUndefined();
136-
expect(pageCopy.actions).toHaveLength(0);
137-
});
138-
139-
it("should return actions but no callout when no campaign is active", async () => {
140-
const mockHeaders = {
141-
get: jest.fn((key: string) => {
142-
if (key === "x-e2e-datetime") return "2025-12-01T12:00:00Z";
143-
return null;
144-
}),
145-
};
146-
(headers as jest.Mock).mockResolvedValue(mockHeaders);
147-
148-
const pageCopy = await buildFilteredContentForCovid19Vaccine(JSON.stringify(genericVaccineContentAPIResponse));
149-
150-
expect(pageCopy.callout).toBeUndefined();
151-
expect(pageCopy.actions).not.toHaveLength(0);
152-
});
15370
});
15471
});

src/services/content-api/parsers/custom/covid-19.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ export const buildFilteredContentForCovid19Vaccine = async (apiContent: string):
2323
].join("\n\n"),
2424
contentType: "markdown",
2525
};
26-
const actions: Action[] = [];
27-
actions.push(...(await _buildActions()));
26+
const actions: Action[] = await _buildActions();
2827

2928
const recommendation: HeadingWithContent = {
3029
heading: "The COVID-19 vaccine is recommended if you:",

0 commit comments

Comments
 (0)