Skip to content

Commit 9e9ee75

Browse files
VIA-304 SB Use different getFilteredContentForVaccine implementation for Whooping Cough.
1 parent 3e54387 commit 9e9ee75

File tree

4 files changed

+58
-9
lines changed

4 files changed

+58
-9
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async function hydrateCacheForVaccine(
5252

5353
try {
5454
const content: string = await fetchContentForVaccine(vaccineType);
55-
const filteredContent: VaccinePageContent = getFilteredContentForVaccine(content);
55+
const filteredContent: VaccinePageContent = getFilteredContentForVaccine(vaccineType, content);
5656

5757
if (!approvalEnabled) {
5858
await checkContentPassesStylingAndWriteToCache(vaccineType, content, filteredContent);
@@ -80,7 +80,9 @@ async function hydrateCacheForVaccine(
8080
}
8181

8282
if (cacheStatus === "valid") {
83-
if (vitaContentChangedSinceLastApproved(filteredContent, getFilteredContentForVaccine(cacheContent))) {
83+
if (
84+
vitaContentChangedSinceLastApproved(filteredContent, getFilteredContentForVaccine(vaccineType, cacheContent))
85+
) {
8486
log.info(
8587
{ context: { vaccineType } },
8688
`Content changes detected for vaccine ${vaccineType}; invalidating cache`,

src/services/content-api/content-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const getContentForVaccine = async (vaccineType: VaccineType): Promise<GetConten
2929
const vaccineContent = await readContentFromCache(config.CONTENT_CACHE_PATH, vaccineCacheFilename, vaccineType);
3030

3131
// filter and style content
32-
const filteredContent: VaccinePageContent = getFilteredContentForVaccine(vaccineContent);
32+
const filteredContent: VaccinePageContent = getFilteredContentForVaccine(vaccineType, vaccineContent);
3333
const styledVaccineContent: StyledVaccineContent = await getStyledContentForVaccine(
3434
vaccineType,
3535
filteredContent,

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { VaccineType } from "@src/models/vaccine";
12
import {
23
_extractDescriptionForVaccine,
34
_extractHeadlineForAspect,
@@ -529,7 +530,10 @@ describe("Content Filter", () => {
529530
overview: "Generic Vaccine Lead Paragraph (overview)",
530531
};
531532

532-
const pageCopyForRsv = getFilteredContentForVaccine(JSON.stringify(genericVaccineContentAPIResponse));
533+
const pageCopyForRsv = getFilteredContentForVaccine(
534+
VaccineType.RSV,
535+
JSON.stringify(genericVaccineContentAPIResponse),
536+
);
533537

534538
expect(pageCopyForRsv).toEqual(expect.objectContaining(expectedOverview));
535539
});
@@ -549,7 +553,10 @@ describe("Content Filter", () => {
549553
},
550554
};
551555

552-
const pageCopyForRsv = getFilteredContentForVaccine(JSON.stringify(genericVaccineContentAPIResponse));
556+
const pageCopyForRsv = getFilteredContentForVaccine(
557+
VaccineType.RSV,
558+
JSON.stringify(genericVaccineContentAPIResponse),
559+
);
553560

554561
expect(pageCopyForRsv).toEqual(expect.objectContaining(expectedWhatVaccineIsFor));
555562
});
@@ -593,7 +600,10 @@ describe("Content Filter", () => {
593600
},
594601
};
595602

596-
const pageCopyForRsv = getFilteredContentForVaccine(JSON.stringify(genericVaccineContentAPIResponse));
603+
const pageCopyForRsv = getFilteredContentForVaccine(
604+
VaccineType.RSV,
605+
JSON.stringify(genericVaccineContentAPIResponse),
606+
);
597607

598608
expect(pageCopyForRsv).toEqual(expect.objectContaining(expectedWhoVaccineIsFor));
599609
});
@@ -619,7 +629,10 @@ describe("Content Filter", () => {
619629
},
620630
};
621631

622-
const pageCopyForRsv = getFilteredContentForVaccine(JSON.stringify(genericVaccineContentAPIResponse));
632+
const pageCopyForRsv = getFilteredContentForVaccine(
633+
VaccineType.RSV,
634+
JSON.stringify(genericVaccineContentAPIResponse),
635+
);
623636

624637
expect(pageCopyForRsv).toEqual(expect.objectContaining(expectedHowToGetVaccine));
625638
});
@@ -650,6 +663,7 @@ describe("Content Filter", () => {
650663
};
651664

652665
const pageCopyForRsv: VaccinePageContent = getFilteredContentForVaccine(
666+
VaccineType.RSV,
653667
JSON.stringify(genericVaccineContentAPIResponse),
654668
);
655669

@@ -661,7 +675,10 @@ describe("Content Filter", () => {
661675
webpageLink: new URL("https://www.nhs.uk/vaccinations/generic-vaccine/"),
662676
};
663677

664-
const pageCopyForRsv = getFilteredContentForVaccine(JSON.stringify(genericVaccineContentAPIResponse));
678+
const pageCopyForRsv = getFilteredContentForVaccine(
679+
VaccineType.RSV,
680+
JSON.stringify(genericVaccineContentAPIResponse),
681+
);
665682

666683
expect(pageCopyForRsv).toEqual(expect.objectContaining(expectedWebpageLink));
667684
});
@@ -670,6 +687,7 @@ describe("Content Filter", () => {
670687
const responseWithoutBenefitsHealthAspect = contentWithoutBenefitsHealthAspect();
671688

672689
const pageCopyForFlu: VaccinePageContent = getFilteredContentForVaccine(
690+
VaccineType.RSV,
673691
JSON.stringify(responseWithoutBenefitsHealthAspect),
674692
);
675693

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { VaccineType } from "@src/models/vaccine";
12
import {
23
ContentApiVaccineResponse,
34
HasPartSubsection,
@@ -166,8 +167,18 @@ function _extractHeadlineForContraindicationsAspect(content: ContentApiVaccineRe
166167
];
167168
}
168169

169-
const getFilteredContentForVaccine = (apiContent: string): VaccinePageContent => {
170+
const getFilteredContentForVaccine = (vaccineType: VaccineType, apiContent: string): VaccinePageContent => {
170171
const content: ContentApiVaccineResponse = JSON.parse(apiContent);
172+
173+
switch (vaccineType) {
174+
case VaccineType.WHOOPING_COUGH:
175+
return getFilteredContentForWhoopingCoughVaccine(content);
176+
default:
177+
return getFilteredContentForStandardVaccine(content);
178+
}
179+
};
180+
181+
const getFilteredContentForStandardVaccine = (content: ContentApiVaccineResponse): VaccinePageContent => {
171182
const overview: string = _extractDescriptionForVaccine(content, "lead paragraph");
172183

173184
let whatVaccineIsFor;
@@ -207,6 +218,24 @@ const getFilteredContentForVaccine = (apiContent: string): VaccinePageContent =>
207218
};
208219
};
209220

221+
const getFilteredContentForWhoopingCoughVaccine = (content: ContentApiVaccineResponse): VaccinePageContent => {
222+
const overview = "overview";
223+
const whatVaccineIsFor = undefined;
224+
const whoVaccineIsFor: VaccinePageSection = { headline: "", subsections: [] };
225+
const howToGetVaccine: VaccinePageSection = { headline: "", subsections: [] };
226+
const vaccineSideEffects: VaccinePageSection = { headline: "", subsections: [] };
227+
const webpageLink: URL = new URL(content.webpage);
228+
229+
return {
230+
overview: overview,
231+
whatVaccineIsFor: whatVaccineIsFor,
232+
whoVaccineIsFor,
233+
howToGetVaccine,
234+
vaccineSideEffects,
235+
webpageLink,
236+
};
237+
};
238+
210239
export {
211240
getFilteredContentForVaccine,
212241
_findAspect,

0 commit comments

Comments
 (0)