Skip to content

Commit befaa77

Browse files
VIA-629 SB Don't show callout on Covid page when campaign active.
1 parent c4c6b9f commit befaa77

File tree

6 files changed

+112
-40
lines changed

6 files changed

+112
-40
lines changed

src/services/content-api/parsers/content-filter-service.test.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
_removeExcludedHyperlinks,
1010
getFilteredContentForVaccine,
1111
} from "@src/services/content-api/parsers/content-filter-service";
12+
import { buildFilteredContentForCovid19Vaccine } from "@src/services/content-api/parsers/custom/covid-19";
1213
import { buildFilteredContentForFluForChildrenVaccine } from "@src/services/content-api/parsers/custom/flu-for-children";
1314
import { buildFilteredContentForFluForSchoolAgedChildrenVaccine } from "@src/services/content-api/parsers/custom/flu-for-school-aged-children";
1415
import { buildFilteredContentForFluInPregnancyVaccine } from "@src/services/content-api/parsers/custom/flu-in-pregnancy";
@@ -30,6 +31,9 @@ jest.mock("@src/services/content-api/parsers/custom/flu-in-pregnancy");
3031
jest.mock("@src/services/content-api/parsers/custom/flu-vaccine");
3132
jest.mock("@src/services/content-api/parsers/custom/flu-for-children");
3233
jest.mock("@src/services/content-api/parsers/custom/flu-for-school-aged-children");
34+
jest.mock("@src/services/content-api/parsers/custom/covid-19");
35+
36+
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
3337

3438
describe("Content Filter", () => {
3539
describe("_extractDescriptionForVaccine", () => {
@@ -751,26 +755,6 @@ describe("Content Filter", () => {
751755
expect(buildFilteredContentForFluVaccine).toHaveBeenCalledWith(mockApiContent);
752756
});
753757

754-
it("should return standard vaccine content and additional content for COVID-19 vaccine", () => {
755-
const pageCopyForCovid19Vaccine = getFilteredContentForVaccine(
756-
VaccineType.COVID_19,
757-
JSON.stringify(genericVaccineContentAPIResponse),
758-
);
759-
760-
expect(pageCopyForCovid19Vaccine.overview).toBeDefined();
761-
expect(pageCopyForCovid19Vaccine.whatVaccineIsFor).toBeDefined();
762-
expect(pageCopyForCovid19Vaccine.whoVaccineIsFor).toBeDefined();
763-
expect(pageCopyForCovid19Vaccine.howToGetVaccine).toBeDefined();
764-
expect(pageCopyForCovid19Vaccine.vaccineSideEffects).toBeDefined();
765-
expect(pageCopyForCovid19Vaccine.webpageLink).toBeDefined();
766-
767-
// Additional COVID-19 vaccine content
768-
expect(pageCopyForCovid19Vaccine.callout?.heading).toEqual("Booking service closed");
769-
expect(pageCopyForCovid19Vaccine.recommendation?.heading).toEqual(
770-
"The COVID-19 vaccine is recommended if you:",
771-
);
772-
});
773-
774758
it("should call getFilteredContentForFluInPregnancyVaccine for flu in pregnancy vaccine", () => {
775759
const mockApiContent = "testContent";
776760

@@ -793,6 +777,14 @@ describe("Content Filter", () => {
793777
getFilteredContentForVaccine(VaccineType.FLU_FOR_SCHOOL_AGED_CHILDREN, mockApiContent);
794778
expect(buildFilteredContentForFluForSchoolAgedChildrenVaccine).toHaveBeenCalledWith(mockApiContent);
795779
});
780+
781+
it("should call buildFilteredContentForCovid19Vaccine for flu in pregnancy vaccine", () => {
782+
const mockApiContent = "testContent";
783+
784+
getFilteredContentForVaccine(VaccineType.COVID_19, mockApiContent);
785+
786+
expect(buildFilteredContentForCovid19Vaccine).toHaveBeenCalledWith(mockApiContent);
787+
});
796788
});
797789
});
798790
});
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { buildFilteredContentForCovid19Vaccine } from "@src/services/content-api/parsers/custom/covid-19";
2+
import { genericVaccineContentAPIResponse } from "@test-data/content-api/data";
3+
4+
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
5+
6+
describe("buildFilteredContentForCovid19Vaccine", () => {
7+
process.env.CAMPAIGNS = JSON.stringify({
8+
COVID_19: [
9+
{ start: "20251101", end: "20260131" },
10+
{ start: "20261101", end: "20270131" },
11+
],
12+
});
13+
jest.useFakeTimers();
14+
15+
it("should return standard vaccine content and additional content for COVID-19 vaccine", async () => {
16+
jest.setSystemTime(new Date("2025-10-01"));
17+
18+
const pageCopyForCovid19Vaccine = await buildFilteredContentForCovid19Vaccine(
19+
JSON.stringify(genericVaccineContentAPIResponse),
20+
);
21+
22+
expect(pageCopyForCovid19Vaccine.overview).toBeDefined();
23+
expect(pageCopyForCovid19Vaccine.whatVaccineIsFor).toBeDefined();
24+
expect(pageCopyForCovid19Vaccine.whoVaccineIsFor).toBeDefined();
25+
expect(pageCopyForCovid19Vaccine.howToGetVaccine).toBeDefined();
26+
expect(pageCopyForCovid19Vaccine.vaccineSideEffects).toBeDefined();
27+
expect(pageCopyForCovid19Vaccine.webpageLink).toBeDefined();
28+
29+
// Additional COVID-19 vaccine content
30+
expect(pageCopyForCovid19Vaccine.callout?.heading).toEqual("Booking service closed");
31+
expect(pageCopyForCovid19Vaccine.recommendation?.heading).toEqual("The COVID-19 vaccine is recommended if you:");
32+
});
33+
34+
it("should return a callout when no campaign is active", async () => {
35+
// Given
36+
jest.setSystemTime(new Date("2025-10-01"));
37+
38+
const expected = {
39+
callout: {
40+
heading: "Booking service closed",
41+
content:
42+
"You can no longer book a COVID-19 vaccination using this online service\n\n" +
43+
"Bookings can also no longer be made through the 119 service.\n\n" +
44+
"COVID-19 vaccinations will be available again in spring.",
45+
contentType: "markdown",
46+
},
47+
};
48+
49+
// When
50+
const pageCopy = await buildFilteredContentForCovid19Vaccine(JSON.stringify(genericVaccineContentAPIResponse));
51+
52+
// Then
53+
expect(pageCopy).toEqual(expect.objectContaining(expected));
54+
});
55+
56+
it("should not return a callout when no campaign is active", async () => {
57+
// Given
58+
jest.useFakeTimers().setSystemTime(new Date("2025-12-01"));
59+
60+
// When
61+
const pageCopy = await buildFilteredContentForCovid19Vaccine(JSON.stringify(genericVaccineContentAPIResponse));
62+
63+
// Then
64+
expect(pageCopy.callout).toBeUndefined();
65+
});
66+
});
Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1+
import { VaccineType } from "@src/models/vaccine";
12
import { buildFilteredContentForStandardVaccine } from "@src/services/content-api/parsers/content-filter-service";
23
import { HeadingWithContent, HeadingWithTypedContent, VaccinePageContent } from "@src/services/content-api/types";
4+
import config from "@src/utils/config";
5+
import { logger } from "@src/utils/logger";
6+
import { Logger } from "pino";
37

4-
export const buildFilteredContentForCovid19Vaccine = (apiContent: string): VaccinePageContent => {
5-
const standardVaccineContent = buildFilteredContentForStandardVaccine(apiContent);
6-
const additionalCovid19VaccineContent = getAdditionalContentForCovid19Vaccine();
8+
const log: Logger = logger.child({ module: "covid-19" });
79

8-
return { ...standardVaccineContent, ...additionalCovid19VaccineContent };
9-
};
10+
export const buildFilteredContentForCovid19Vaccine = async (apiContent: string): Promise<VaccinePageContent> => {
11+
const campaigns = await config.CAMPAIGNS;
1012

11-
function getAdditionalContentForCovid19Vaccine() {
12-
const callout: HeadingWithTypedContent = {
13-
heading: "Booking service closed",
14-
content: [
15-
"You can no longer book a COVID-19 vaccination using this online service",
16-
"Bookings can also no longer be made through the 119 service.",
17-
"COVID-19 vaccinations will be available again in spring.",
18-
].join("\n\n"),
19-
contentType: "markdown",
20-
};
13+
const standardFilteredContent = buildFilteredContentForStandardVaccine(apiContent);
14+
15+
let callout: HeadingWithTypedContent | undefined;
16+
if (campaigns.isActive(VaccineType.COVID_19)) {
17+
log.info("Campaign active");
18+
callout = undefined;
19+
} else {
20+
log.info("No campaign active");
21+
callout = {
22+
heading: "Booking service closed",
23+
content: [
24+
"You can no longer book a COVID-19 vaccination using this online service",
25+
"Bookings can also no longer be made through the 119 service.",
26+
"COVID-19 vaccinations will be available again in spring.",
27+
].join("\n\n"),
28+
contentType: "markdown",
29+
};
30+
}
2131
const recommendation: HeadingWithContent = {
2232
heading: "The COVID-19 vaccine is recommended if you:",
2333
content: [
@@ -26,8 +36,6 @@ function getAdditionalContentForCovid19Vaccine() {
2636
"* live in a care home for older adults",
2737
].join("\n"),
2838
};
29-
return {
30-
callout,
31-
recommendation,
32-
};
33-
}
39+
40+
return { ...standardFilteredContent, callout, recommendation };
41+
};

src/services/content-api/parsers/custom/flu-for-children.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { buildFilteredContentForFluForChildrenVaccine } from "@src/services/content-api/parsers/custom/flu-for-children";
22
import { genericVaccineContentAPIResponse } from "@test-data/content-api/data";
33

4+
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
5+
46
describe("getFilteredContentForFluVaccine", () => {
57
it("should return overview text from lead paragraph mainEntityOfPage object", async () => {
68
const expectedOverview = {

src/services/content-api/parsers/custom/flu-for-school-aged-children.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { buildFilteredContentForFluForSchoolAgedChildrenVaccine } from "@src/ser
22
import { genericVaccineContentAPIResponse } from "@test-data/content-api/data";
33
import { cloneDeep } from "es-toolkit";
44

5+
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
6+
57
const childFluVaccineContentAPIResponse = cloneDeep(genericVaccineContentAPIResponse);
68

79
const expanderGroup = [

src/services/content-api/parsers/custom/flu-vaccine.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { buildFilteredContentForFluVaccine } from "@src/services/content-api/parsers/custom/flu-vaccine";
22
import { genericVaccineContentAPIResponse } from "@test-data/content-api/data";
33

4+
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
5+
46
describe("getFilteredContentForFluVaccine", () => {
57
it("should return overview text from lead paragraph mainEntityOfPage object", async () => {
68
const expectedOverview = {

0 commit comments

Comments
 (0)