Skip to content

Commit ca54e52

Browse files
VIA-627 SB, EO, MD & DB Add horrific test for overviewConclusion from buildFilteredContentForFluForSchoolAgedChildrenVaccine.
1 parent 4eceb27 commit ca54e52

File tree

3 files changed

+54
-19
lines changed

3 files changed

+54
-19
lines changed

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
11
import { buildFilteredContentForFluForSchoolAgedChildrenVaccine } from "@src/services/content-api/parsers/custom/flu-for-school-aged-children";
22
import { genericVaccineContentAPIResponse } from "@test-data/content-api/data";
3+
import { cloneDeep } from "es-toolkit";
34

4-
describe("getFilteredContentForFluVaccine", () => {
5+
const childFluVaccineContentAPIResponse = cloneDeep(genericVaccineContentAPIResponse);
6+
7+
const expanderGroup = [
8+
{
9+
"@type": "WebPageElement",
10+
position: 1,
11+
name: "Expander Group",
12+
identifier: "20",
13+
mainEntity: [
14+
{
15+
position: 1,
16+
"@type": "WebPageElement",
17+
name: "Expander",
18+
subjectOf: "School-aged children (Reception to Year 11)",
19+
identifier: "18",
20+
mainEntity: "<p>School age how-to-get</p>",
21+
},
22+
],
23+
},
24+
];
25+
childFluVaccineContentAPIResponse.mainEntityOfPage.unshift({
26+
"@type": "WebPageElement",
27+
position: 1,
28+
identifier: "20",
29+
name: "Expander Group",
30+
hasHealthAspect: "http://schema.org/GettingAccessHealthAspect",
31+
headline: "How to get the children's flu vaccine",
32+
mainEntityOfPage: expanderGroup,
33+
hasPart: expanderGroup,
34+
});
35+
36+
describe("buildFilteredContentForFluForSchoolAgedChildrenVaccine", () => {
537
it("should return overview text from lead paragraph mainEntityOfPage object", async () => {
638
const expectedOverview = {
739
overview: { content: "Generic Vaccine Lead Paragraph (overview)", containsHtml: false },
@@ -40,4 +72,16 @@ describe("getFilteredContentForFluVaccine", () => {
4072

4173
expect(pageCopy).toEqual(expect.objectContaining(expected));
4274
});
75+
76+
it("should return overviewConclusion", () => {
77+
const expected = {
78+
overviewConclusion: { content: "<p>School age how-to-get</p>", containsHtml: true },
79+
};
80+
81+
const pageCopy = buildFilteredContentForFluForSchoolAgedChildrenVaccine(
82+
JSON.stringify(childFluVaccineContentAPIResponse),
83+
);
84+
85+
expect(pageCopy).toEqual(expect.objectContaining(expected));
86+
});
4387
});
Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
import { buildFilteredContentForStandardVaccine } from "@src/services/content-api/parsers/content-filter-service";
2-
import {
3-
ExpanderSubsection,
4-
HeadingWithContent,
5-
VaccinePageContent,
6-
VaccinePageSubsection,
7-
} from "@src/services/content-api/types";
2+
import { ExpanderSubsection, HeadingWithContent, VaccinePageContent } from "@src/services/content-api/types";
83

94
export const buildFilteredContentForFluForSchoolAgedChildrenVaccine = (apiContent: string): VaccinePageContent => {
105
const standardFilteredContent = buildFilteredContentForStandardVaccine(apiContent);
116

12-
const overviewConclusion: VaccinePageSubsection | undefined =
13-
standardFilteredContent.howToGetVaccine.subsections.find((subsection: VaccinePageSubsection) => {
14-
return subsection.type == "expanderElement" && subsection.headline.startsWith("School");
15-
}) as ExpanderSubsection | undefined;
7+
const schoolAgeHowToGet = standardFilteredContent.howToGetVaccine.subsections.find(
8+
(subsection) => subsection.type == "expanderElement" && subsection.headline.startsWith("School"),
9+
) as ExpanderSubsection | undefined;
10+
const overviewConclusion = schoolAgeHowToGet?.mainEntity
11+
? { content: schoolAgeHowToGet.mainEntity, containsHtml: true }
12+
: undefined;
1613

1714
const recommendation: HeadingWithContent = {
1815
heading: "The flu vaccine is recommended for children who:",
1916
content: ["* are of school age (Reception to Year 1)"].join("\n"),
2017
};
21-
22-
return {
23-
...standardFilteredContent,
24-
recommendation,
25-
overviewConclusion: overviewConclusion?.mainEntity
26-
? { content: overviewConclusion.mainEntity, containsHtml: true }
27-
: undefined,
28-
};
18+
return { ...standardFilteredContent, recommendation, overviewConclusion };
2919
};

src/services/content-api/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export type MainEntityOfPage = {
4848
hasPart?: HasPartSubsection[];
4949
mainEntityOfPage?: MainEntityOfPage[];
5050
description?: string;
51+
mainEntity?: string | MainEntity[];
5152
};
5253

5354
export type ContentApiVaccineResponse = {

0 commit comments

Comments
 (0)