Skip to content

Commit 2d72eef

Browse files
VIA-304 SB Filter content for Whooping Cough vaccine.
1 parent 9e9ee75 commit 2d72eef

File tree

3 files changed

+168
-23
lines changed

3 files changed

+168
-23
lines changed

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

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { VaccineType } from "@src/models/vaccine";
2+
import { getFilteredContentForWhoopingCoughVaccine } from "@src/services/content-api/parsers/custom/whooping-cough";
23
import {
34
ContentApiVaccineResponse,
45
HasPartSubsection,
@@ -168,17 +169,17 @@ function _extractHeadlineForContraindicationsAspect(content: ContentApiVaccineRe
168169
}
169170

170171
const getFilteredContentForVaccine = (vaccineType: VaccineType, apiContent: string): VaccinePageContent => {
171-
const content: ContentApiVaccineResponse = JSON.parse(apiContent);
172-
173172
switch (vaccineType) {
174173
case VaccineType.WHOOPING_COUGH:
175-
return getFilteredContentForWhoopingCoughVaccine(content);
174+
return getFilteredContentForWhoopingCoughVaccine(apiContent);
176175
default:
177-
return getFilteredContentForStandardVaccine(content);
176+
return getFilteredContentForStandardVaccine(apiContent);
178177
}
179178
};
180179

181-
const getFilteredContentForStandardVaccine = (content: ContentApiVaccineResponse): VaccinePageContent => {
180+
const getFilteredContentForStandardVaccine = (apiContent: string): VaccinePageContent => {
181+
const content: ContentApiVaccineResponse = JSON.parse(apiContent);
182+
182183
const overview: string = _extractDescriptionForVaccine(content, "lead paragraph");
183184

184185
let whatVaccineIsFor;
@@ -218,24 +219,6 @@ const getFilteredContentForStandardVaccine = (content: ContentApiVaccineResponse
218219
};
219220
};
220221

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-
239222
export {
240223
getFilteredContentForVaccine,
241224
_findAspect,
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { VaccineInfo, VaccineType } from "@src/models/vaccine";
2+
import { getFilteredContentForWhoopingCoughVaccine } from "@src/services/content-api/parsers/custom/whooping-cough";
3+
4+
const apiResponse = JSON.stringify({
5+
mainEntityOfPage: [
6+
{ hasPart: [{ text: "Whooping Cough Vaccine Lead Paragraph (overview)" }] },
7+
{ hasPart: [{ text: "<p>What the vaccine is for paragraph</p>" }] },
8+
{ hasPart: [{ text: "<p>Who the vaccine is for paragraph</p>" }] },
9+
{ hasPart: [{ text: "paragraph 3" }] },
10+
{ hasPart: [{ text: "paragraph 4" }] },
11+
{ hasPart: [{ text: "paragraph 5" }] },
12+
{ hasPart: [{ text: "<p>Side effects of the vaccine paragraph</p>" }] },
13+
{ hasPart: [{ text: "paragraph 7" }] },
14+
{ hasPart: [{ text: "paragraph 8" }] },
15+
{ hasPart: [{ text: "paragraph 9" }] },
16+
{ hasPart: [{ text: "paragraph 10" }] },
17+
{ hasPart: [{ text: "paragraph 11" }] },
18+
{ hasPart: [{ text: "paragraph 12" }] },
19+
{ hasPart: [{ text: "paragraph 13" }] },
20+
{ hasPart: [{ text: "<p>How to get the vaccine paragraph</p>" }] },
21+
{ hasPart: [{ text: "paragraph 15" }] },
22+
],
23+
});
24+
25+
describe("getFilteredContentForVaccine", () => {
26+
it("should return overview text from lead paragraph mainEntityOfPage object", async () => {
27+
const expected = { overview: "Whooping Cough Vaccine Lead Paragraph (overview)" };
28+
29+
const pageCopy = getFilteredContentForWhoopingCoughVaccine(apiResponse);
30+
31+
expect(pageCopy).toEqual(expect.objectContaining(expected));
32+
});
33+
34+
it("should return all parts for whatVaccineIsFor section", () => {
35+
const expected = {
36+
whatVaccineIsFor: {
37+
headline: "What the vaccine is for",
38+
subsections: [
39+
{
40+
type: "simpleElement",
41+
headline: "",
42+
name: "markdown",
43+
text: "<p>What the vaccine is for paragraph</p>",
44+
},
45+
],
46+
},
47+
};
48+
49+
const pageCopy = getFilteredContentForWhoopingCoughVaccine(apiResponse);
50+
51+
expect(pageCopy).toEqual(expect.objectContaining(expected));
52+
});
53+
54+
it("should return all parts for whoVaccineIsFor section", () => {
55+
const expected = {
56+
whoVaccineIsFor: {
57+
headline: "Who should have the vaccine",
58+
subsections: [
59+
{
60+
type: "simpleElement",
61+
headline: "",
62+
name: "markdown",
63+
text: "<p>Who the vaccine is for paragraph</p>",
64+
},
65+
],
66+
},
67+
};
68+
69+
const pageCopy = getFilteredContentForWhoopingCoughVaccine(apiResponse);
70+
71+
expect(pageCopy).toEqual(expect.objectContaining(expected));
72+
});
73+
74+
it("should return all parts for howToGetVaccine section", () => {
75+
const expected = {
76+
howToGetVaccine: {
77+
headline: "How to get the vaccine",
78+
subsections: [
79+
{
80+
type: "simpleElement",
81+
headline: "",
82+
name: "markdown",
83+
text: "<p>How to get the vaccine paragraph</p>",
84+
},
85+
],
86+
},
87+
};
88+
89+
const pageCopy = getFilteredContentForWhoopingCoughVaccine(apiResponse);
90+
91+
expect(pageCopy).toEqual(expect.objectContaining(expected));
92+
});
93+
94+
it("should return all parts for vaccineSideEffects section", () => {
95+
const expected = {
96+
vaccineSideEffects: {
97+
headline: "Side effects of the vaccine",
98+
subsections: [
99+
{
100+
type: "simpleElement",
101+
headline: "",
102+
name: "markdown",
103+
text: "<p>Side effects of the vaccine paragraph</p>",
104+
},
105+
],
106+
},
107+
};
108+
109+
const pageCopy = getFilteredContentForWhoopingCoughVaccine(apiResponse);
110+
111+
expect(pageCopy).toEqual(expect.objectContaining(expected));
112+
});
113+
114+
it("should include nhs webpage link to vaccine info", () => {
115+
const expected = {
116+
webpageLink: VaccineInfo[VaccineType.WHOOPING_COUGH].nhsWebpageLink,
117+
};
118+
119+
const pageCopy = getFilteredContentForWhoopingCoughVaccine(apiResponse);
120+
121+
expect(pageCopy).toEqual(expect.objectContaining(expected));
122+
});
123+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { VaccineInfo, VaccineType } from "@src/models/vaccine";
2+
import { ContentApiVaccineResponse, VaccinePageContent, VaccinePageSection } from "@src/services/content-api/types";
3+
4+
export const getFilteredContentForWhoopingCoughVaccine = (apiContent: string): VaccinePageContent => {
5+
const content: ContentApiVaccineResponse = JSON.parse(apiContent);
6+
7+
const paragraphs: string[] = content.mainEntityOfPage
8+
.flatMap((entity) => entity.hasPart ?? [])
9+
.map((part) => part?.text)
10+
.filter((text): text is string => !!text);
11+
12+
const overview = paragraphs[0];
13+
const whatVaccineIsFor: VaccinePageSection = {
14+
headline: "What the vaccine is for",
15+
subsections: [{ type: "simpleElement", headline: "", text: paragraphs[1], name: "markdown" }],
16+
};
17+
const whoVaccineIsFor: VaccinePageSection = {
18+
headline: "Who should have the vaccine",
19+
subsections: [{ type: "simpleElement", headline: "", text: paragraphs[2], name: "markdown" }],
20+
};
21+
const howToGetVaccine: VaccinePageSection = {
22+
headline: "How to get the vaccine",
23+
subsections: [{ type: "simpleElement", headline: "", text: paragraphs[14], name: "markdown" }],
24+
};
25+
const vaccineSideEffects: VaccinePageSection = {
26+
headline: "Side effects of the vaccine",
27+
subsections: [{ type: "simpleElement", headline: "", text: paragraphs[6], name: "markdown" }],
28+
};
29+
const webpageLink: URL = VaccineInfo[VaccineType.WHOOPING_COUGH].nhsWebpageLink;
30+
31+
return {
32+
overview,
33+
whatVaccineIsFor,
34+
whoVaccineIsFor,
35+
howToGetVaccine,
36+
vaccineSideEffects,
37+
webpageLink,
38+
};
39+
};

0 commit comments

Comments
 (0)