Skip to content

Commit b05ecd1

Browse files
VIA-629 SB Make buildFilteredContentForCovid19Vaccine async, so we can get config in there, plus fallout.
1 parent befaa77 commit b05ecd1

15 files changed

+99
-85
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async function hydrateCacheForVaccine(
6767
return delayMillis;
6868
},
6969
});
70-
const filteredContent: VaccinePageContent = getFilteredContentForVaccine(vaccineType, content);
70+
const filteredContent: VaccinePageContent = await getFilteredContentForVaccine(vaccineType, content);
7171

7272
if (!approvalEnabled) {
7373
await checkContentPassesStylingAndWriteToCache(vaccineType, content, filteredContent);
@@ -96,7 +96,10 @@ async function hydrateCacheForVaccine(
9696

9797
if (cacheStatus === "valid") {
9898
if (
99-
vitaContentChangedSinceLastApproved(filteredContent, getFilteredContentForVaccine(vaccineType, cacheContent))
99+
vitaContentChangedSinceLastApproved(
100+
filteredContent,
101+
await getFilteredContentForVaccine(vaccineType, cacheContent),
102+
)
100103
) {
101104
log.info(
102105
{ context: { vaccineType } },

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(cachePath, vaccineCacheFilename, vaccineType);
3030

3131
// filter and style content
32-
const filteredContent: VaccinePageContent = getFilteredContentForVaccine(vaccineType, vaccineContent);
32+
const filteredContent: VaccinePageContent = await 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: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -547,15 +547,15 @@ describe("Content Filter", () => {
547547
overview: { content: "Generic Vaccine Lead Paragraph (overview)", containsHtml: false },
548548
};
549549

550-
const pageCopyForRsv = getFilteredContentForVaccine(
550+
const pageCopyForRsv = await getFilteredContentForVaccine(
551551
VaccineType.RSV,
552552
JSON.stringify(genericVaccineContentAPIResponse),
553553
);
554554

555555
expect(pageCopyForRsv).toEqual(expect.objectContaining(expectedOverview));
556556
});
557557

558-
it("should return all parts for whatVaccineIsFor section", () => {
558+
it("should return all parts for whatVaccineIsFor section", async () => {
559559
const expectedWhatVaccineIsFor = {
560560
whatVaccineIsFor: {
561561
headline: "Benefits Health Aspect headline",
@@ -570,15 +570,15 @@ describe("Content Filter", () => {
570570
},
571571
};
572572

573-
const pageCopyForRsv = getFilteredContentForVaccine(
573+
const pageCopyForRsv = await getFilteredContentForVaccine(
574574
VaccineType.RSV,
575575
JSON.stringify(genericVaccineContentAPIResponse),
576576
);
577577

578578
expect(pageCopyForRsv).toEqual(expect.objectContaining(expectedWhatVaccineIsFor));
579579
});
580580

581-
it("should return all parts for whoVaccineIsFor section", () => {
581+
it("should return all parts for whoVaccineIsFor section", async () => {
582582
const expectedWhoVaccineIsFor = {
583583
whoVaccineIsFor: {
584584
headline: "Suitability Health Aspect headline",
@@ -617,15 +617,15 @@ describe("Content Filter", () => {
617617
},
618618
};
619619

620-
const pageCopyForRsv = getFilteredContentForVaccine(
620+
const pageCopyForRsv = await getFilteredContentForVaccine(
621621
VaccineType.RSV,
622622
JSON.stringify(genericVaccineContentAPIResponse),
623623
);
624624

625625
expect(pageCopyForRsv).toEqual(expect.objectContaining(expectedWhoVaccineIsFor));
626626
});
627627

628-
it("should return all parts for howToGetVaccine section", () => {
628+
it("should return all parts for howToGetVaccine section", async () => {
629629
const expectedHowToGetVaccine = {
630630
howToGetVaccine: {
631631
headline: "Getting Access Health Aspect headline",
@@ -646,15 +646,15 @@ describe("Content Filter", () => {
646646
},
647647
};
648648

649-
const pageCopyForRsv = getFilteredContentForVaccine(
649+
const pageCopyForRsv = await getFilteredContentForVaccine(
650650
VaccineType.RSV,
651651
JSON.stringify(genericVaccineContentAPIResponse),
652652
);
653653

654654
expect(pageCopyForRsv).toEqual(expect.objectContaining(expectedHowToGetVaccine));
655655
});
656656

657-
it("should return all parts for vaccineSideEffects section", () => {
657+
it("should return all parts for vaccineSideEffects section", async () => {
658658
const expectedVaccineSideEffects: VaccinePageSection = {
659659
headline: "Side effects of the generic vaccine",
660660
subsections: [
@@ -679,57 +679,57 @@ describe("Content Filter", () => {
679679
],
680680
};
681681

682-
const pageCopyForRsv: VaccinePageContent = getFilteredContentForVaccine(
682+
const pageCopyForRsv: VaccinePageContent = await getFilteredContentForVaccine(
683683
VaccineType.RSV,
684684
JSON.stringify(genericVaccineContentAPIResponse),
685685
);
686686

687687
expect(pageCopyForRsv.vaccineSideEffects).toEqual(expectedVaccineSideEffects);
688688
});
689689

690-
it("should include nhs webpage link to vaccine info", () => {
690+
it("should include nhs webpage link to vaccine info", async () => {
691691
const expectedWebpageLink = {
692692
webpageLink: new URL("https://www.nhs.uk/vaccinations/generic-vaccine/"),
693693
};
694694

695-
const pageCopyForRsv = getFilteredContentForVaccine(
695+
const pageCopyForRsv = await getFilteredContentForVaccine(
696696
VaccineType.RSV,
697697
JSON.stringify(genericVaccineContentAPIResponse),
698698
);
699699

700700
expect(pageCopyForRsv).toEqual(expect.objectContaining(expectedWebpageLink));
701701
});
702702

703-
it("should not return whatVaccineIsFor section when BenefitsHealthAspect is missing", () => {
703+
it("should not return whatVaccineIsFor section when BenefitsHealthAspect is missing", async () => {
704704
const responseWithoutBenefitsHealthAspect = contentWithoutBenefitsHealthAspect();
705705

706-
const pageCopyForFlu: VaccinePageContent = getFilteredContentForVaccine(
706+
const pageCopyForFlu: VaccinePageContent = await getFilteredContentForVaccine(
707707
VaccineType.RSV,
708708
JSON.stringify(responseWithoutBenefitsHealthAspect),
709709
);
710710

711711
expect(pageCopyForFlu.whatVaccineIsFor).toBeUndefined();
712712
});
713713

714-
it("should return all parts for callout section", () => {
714+
it("should return all parts for callout section", async () => {
715715
const expectedCallout: HeadingWithTypedContent = {
716716
heading: "Callout heading",
717717
content: "<p>Callout content</p>",
718718
contentType: "html",
719719
};
720720

721-
const pageCopyForRsv: VaccinePageContent = getFilteredContentForVaccine(
721+
const pageCopyForRsv: VaccinePageContent = await getFilteredContentForVaccine(
722722
VaccineType.RSV,
723723
JSON.stringify(genericVaccineContentAPIResponse),
724724
);
725725

726726
expect(pageCopyForRsv.callout).toEqual(expectedCallout);
727727
});
728728

729-
it("should not return callout section when Callout is missing", () => {
729+
it("should not return callout section when Callout is missing", async () => {
730730
const responseWithoutCallout = contentWithoutCallout();
731731

732-
const pageCopyForFlu: VaccinePageContent = getFilteredContentForVaccine(
732+
const pageCopyForFlu: VaccinePageContent = await getFilteredContentForVaccine(
733733
VaccineType.RSV,
734734
JSON.stringify(responseWithoutCallout),
735735
);
@@ -739,49 +739,49 @@ describe("Content Filter", () => {
739739
});
740740

741741
describe("for specific vaccines", () => {
742-
it("should call getFilteredContentForWhoopingCoughVaccine for whooping cough vaccine", () => {
742+
it("should call getFilteredContentForWhoopingCoughVaccine for whooping cough vaccine", async () => {
743743
const mockApiContent = "testContent";
744744

745-
getFilteredContentForVaccine(VaccineType.WHOOPING_COUGH, mockApiContent);
745+
await getFilteredContentForVaccine(VaccineType.WHOOPING_COUGH, mockApiContent);
746746

747747
expect(buildFilteredContentForWhoopingCoughVaccine).toHaveBeenCalledWith(mockApiContent);
748748
});
749749

750-
it("should call getFilteredContentForFluVaccine for flu vaccine", () => {
750+
it("should call getFilteredContentForFluVaccine for flu vaccine", async () => {
751751
const mockApiContent = "testContent";
752752

753-
getFilteredContentForVaccine(VaccineType.FLU_FOR_ADULTS, mockApiContent);
753+
await getFilteredContentForVaccine(VaccineType.FLU_FOR_ADULTS, mockApiContent);
754754

755755
expect(buildFilteredContentForFluVaccine).toHaveBeenCalledWith(mockApiContent);
756756
});
757757

758-
it("should call getFilteredContentForFluInPregnancyVaccine for flu in pregnancy vaccine", () => {
758+
it("should call getFilteredContentForFluInPregnancyVaccine for flu in pregnancy vaccine", async () => {
759759
const mockApiContent = "testContent";
760760

761-
getFilteredContentForVaccine(VaccineType.FLU_IN_PREGNANCY, mockApiContent);
761+
await getFilteredContentForVaccine(VaccineType.FLU_IN_PREGNANCY, mockApiContent);
762762

763763
expect(buildFilteredContentForFluInPregnancyVaccine).toHaveBeenCalledWith(mockApiContent);
764764
});
765765

766-
it("should call getFilteredContentForFluForChildrenVaccine for flu for children vaccine", () => {
766+
it("should call getFilteredContentForFluForChildrenVaccine for flu for children vaccine", async () => {
767767
const mockApiContent = "testContent";
768768

769-
getFilteredContentForVaccine(VaccineType.FLU_FOR_CHILDREN, mockApiContent);
769+
await getFilteredContentForVaccine(VaccineType.FLU_FOR_CHILDREN, mockApiContent);
770770

771771
expect(buildFilteredContentForFluForChildrenVaccine).toHaveBeenCalledWith(mockApiContent);
772772
});
773773

774-
it("should return standard vaccine content and recommendation for school aged children's flu vaccine", () => {
774+
it("should return standard vaccine content and recommendation for school aged children's flu vaccine", async () => {
775775
const mockApiContent = "testContent";
776776

777-
getFilteredContentForVaccine(VaccineType.FLU_FOR_SCHOOL_AGED_CHILDREN, mockApiContent);
777+
await getFilteredContentForVaccine(VaccineType.FLU_FOR_SCHOOL_AGED_CHILDREN, mockApiContent);
778778
expect(buildFilteredContentForFluForSchoolAgedChildrenVaccine).toHaveBeenCalledWith(mockApiContent);
779779
});
780780

781-
it("should call buildFilteredContentForCovid19Vaccine for flu in pregnancy vaccine", () => {
781+
it("should call buildFilteredContentForCovid19Vaccine for flu in pregnancy vaccine", async () => {
782782
const mockApiContent = "testContent";
783783

784-
getFilteredContentForVaccine(VaccineType.COVID_19, mockApiContent);
784+
await getFilteredContentForVaccine(VaccineType.COVID_19, mockApiContent);
785785

786786
expect(buildFilteredContentForCovid19Vaccine).toHaveBeenCalledWith(mockApiContent);
787787
});

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,10 @@ function _extractHeadlineForContraindicationsAspect(content: ContentApiVaccineRe
209209
];
210210
}
211211

212-
const getFilteredContentForVaccine = (vaccineType: VaccineType, apiContent: string): VaccinePageContent => {
212+
const getFilteredContentForVaccine = async (
213+
vaccineType: VaccineType,
214+
apiContent: string,
215+
): Promise<VaccinePageContent> => {
213216
const filteredContentBuilders = new Map([
214217
[VaccineType.WHOOPING_COUGH, buildFilteredContentForWhoopingCoughVaccine],
215218
[VaccineType.FLU_IN_PREGNANCY, buildFilteredContentForFluInPregnancyVaccine],
@@ -219,10 +222,10 @@ const getFilteredContentForVaccine = (vaccineType: VaccineType, apiContent: stri
219222
[VaccineType.COVID_19, buildFilteredContentForCovid19Vaccine],
220223
]);
221224
const filteredContentBuilder = filteredContentBuilders.get(vaccineType) || buildFilteredContentForStandardVaccine;
222-
return filteredContentBuilder(apiContent);
225+
return await filteredContentBuilder(apiContent);
223226
};
224227

225-
const buildFilteredContentForStandardVaccine = (apiContent: string): VaccinePageContent => {
228+
const buildFilteredContentForStandardVaccine = async (apiContent: string): Promise<VaccinePageContent> => {
226229
const content: ContentApiVaccineResponse = JSON.parse(apiContent);
227230

228231
const overview: Overview = { content: _extractDescriptionForVaccine(content, "lead paragraph"), containsHtml: false };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const log: Logger = logger.child({ module: "covid-19" });
1010
export const buildFilteredContentForCovid19Vaccine = async (apiContent: string): Promise<VaccinePageContent> => {
1111
const campaigns = await config.CAMPAIGNS;
1212

13-
const standardFilteredContent = buildFilteredContentForStandardVaccine(apiContent);
13+
const standardFilteredContent = await buildFilteredContentForStandardVaccine(apiContent);
1414

1515
let callout: HeadingWithTypedContent | undefined;
1616
if (campaigns.isActive(VaccineType.COVID_19)) {

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ describe("getFilteredContentForFluVaccine", () => {
99
overview: { content: "Generic Vaccine Lead Paragraph (overview)", containsHtml: false },
1010
};
1111

12-
const pageCopy = buildFilteredContentForFluForChildrenVaccine(JSON.stringify(genericVaccineContentAPIResponse));
12+
const pageCopy = await buildFilteredContentForFluForChildrenVaccine(
13+
JSON.stringify(genericVaccineContentAPIResponse),
14+
);
1315

1416
expect(pageCopy).toEqual(expect.objectContaining(expectedOverview));
1517
});
1618

17-
it("should return warning callout", () => {
19+
it("should return warning callout", async () => {
1820
const expected = {
1921
callout: {
2022
heading: "Booking service closed",
@@ -23,20 +25,24 @@ describe("getFilteredContentForFluVaccine", () => {
2325
},
2426
};
2527

26-
const pageCopy = buildFilteredContentForFluForChildrenVaccine(JSON.stringify(genericVaccineContentAPIResponse));
28+
const pageCopy = await buildFilteredContentForFluForChildrenVaccine(
29+
JSON.stringify(genericVaccineContentAPIResponse),
30+
);
2731

2832
expect(pageCopy).toEqual(expect.objectContaining(expected));
2933
});
3034

31-
it("should return recommendation", () => {
35+
it("should return recommendation", async () => {
3236
const expected = {
3337
recommendation: {
3438
heading: "The flu vaccine is recommended for children who:",
3539
content: "* are aged 2 or 3 years (born between September 2021 and 31 August 2023)",
3640
},
3741
};
3842

39-
const pageCopy = buildFilteredContentForFluForChildrenVaccine(JSON.stringify(genericVaccineContentAPIResponse));
43+
const pageCopy = await buildFilteredContentForFluForChildrenVaccine(
44+
JSON.stringify(genericVaccineContentAPIResponse),
45+
);
4046

4147
expect(pageCopy).toEqual(expect.objectContaining(expected));
4248
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { buildFilteredContentForStandardVaccine } from "@src/services/content-api/parsers/content-filter-service";
22
import { HeadingWithContent, HeadingWithTypedContent, VaccinePageContent } from "@src/services/content-api/types";
33

4-
export const buildFilteredContentForFluForChildrenVaccine = (apiContent: string): VaccinePageContent => {
5-
const standardFilteredContent = buildFilteredContentForStandardVaccine(apiContent);
4+
export const buildFilteredContentForFluForChildrenVaccine = async (apiContent: string): Promise<VaccinePageContent> => {
5+
const standardFilteredContent = await buildFilteredContentForStandardVaccine(apiContent);
66

77
const callout: HeadingWithTypedContent = {
88
heading: "Booking service closed",

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ describe("buildFilteredContentForFluForSchoolAgedChildrenVaccine", () => {
4141
overview: { content: "Generic Vaccine Lead Paragraph (overview)", containsHtml: false },
4242
};
4343

44-
const pageCopy = buildFilteredContentForFluForSchoolAgedChildrenVaccine(
44+
const pageCopy = await buildFilteredContentForFluForSchoolAgedChildrenVaccine(
4545
JSON.stringify(genericVaccineContentAPIResponse),
4646
);
4747

4848
expect(pageCopy).toEqual(expect.objectContaining(expectedOverview));
4949
});
5050

5151
it("should set the standard vaccine content", async () => {
52-
const pageCopy = buildFilteredContentForFluForSchoolAgedChildrenVaccine(
52+
const pageCopy = await buildFilteredContentForFluForSchoolAgedChildrenVaccine(
5353
JSON.stringify(genericVaccineContentAPIResponse),
5454
);
5555

@@ -60,30 +60,30 @@ describe("buildFilteredContentForFluForSchoolAgedChildrenVaccine", () => {
6060
expect(pageCopy.webpageLink).toBeDefined();
6161
});
6262

63-
it("should return recommendation", () => {
63+
it("should return recommendation", async () => {
6464
const expected = {
6565
recommendation: {
6666
heading: "The flu vaccine is recommended for children who:",
6767
content: "* are of school age (Reception to Year 1)",
6868
},
6969
};
7070

71-
const pageCopy = buildFilteredContentForFluForSchoolAgedChildrenVaccine(
71+
const pageCopy = await buildFilteredContentForFluForSchoolAgedChildrenVaccine(
7272
JSON.stringify(genericVaccineContentAPIResponse),
7373
);
7474

7575
expect(pageCopy).toEqual(expect.objectContaining(expected));
7676
});
7777

78-
it("should return overviewConclusion", () => {
78+
it("should return overviewConclusion", async () => {
7979
const expected = {
8080
overviewConclusion: {
8181
content: '<h2 class="nhsuk-heading-m">How to get the vaccine</h2><p>School age how-to-get</p>',
8282
containsHtml: true,
8383
},
8484
};
8585

86-
const pageCopy = buildFilteredContentForFluForSchoolAgedChildrenVaccine(
86+
const pageCopy = await buildFilteredContentForFluForSchoolAgedChildrenVaccine(
8787
JSON.stringify(childFluVaccineContentAPIResponse),
8888
);
8989

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { buildFilteredContentForStandardVaccine } from "@src/services/content-api/parsers/content-filter-service";
22
import { ExpanderSubsection, HeadingWithContent, VaccinePageContent } from "@src/services/content-api/types";
33

4-
export const buildFilteredContentForFluForSchoolAgedChildrenVaccine = (apiContent: string): VaccinePageContent => {
5-
const standardFilteredContent = buildFilteredContentForStandardVaccine(apiContent);
4+
export const buildFilteredContentForFluForSchoolAgedChildrenVaccine = async (
5+
apiContent: string,
6+
): Promise<VaccinePageContent> => {
7+
const standardFilteredContent = await buildFilteredContentForStandardVaccine(apiContent);
68

79
const schoolAgeHowToGet = standardFilteredContent.howToGetVaccine.subsections.find(
810
(subsection) => subsection.type == "expanderElement" && subsection.headline.startsWith("School"),

0 commit comments

Comments
 (0)