Skip to content

Commit c185a45

Browse files
VIA-618 SB Add content API derived content to flu-in-pregnancy page.
1 parent d842858 commit c185a45

File tree

4 files changed

+158
-1
lines changed

4 files changed

+158
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { VaccineType } from "@src/models/vaccine";
2+
import { getFilteredContentForFluInPregnancyVaccine } from "@src/services/content-api/parsers/custom/flu-in-pregnancy";
23
import { getFilteredContentForWhoopingCoughVaccine } from "@src/services/content-api/parsers/custom/whooping-cough";
34
import {
45
ContentApiVaccineResponse,
@@ -213,6 +214,8 @@ const getFilteredContentForVaccine = (vaccineType: VaccineType, apiContent: stri
213214
switch (vaccineType) {
214215
case VaccineType.WHOOPING_COUGH:
215216
return getFilteredContentForWhoopingCoughVaccine(apiContent);
217+
case VaccineType.FLU_IN_PREGNANCY:
218+
return getFilteredContentForFluInPregnancyVaccine(apiContent);
216219
default:
217220
return getFilteredContentForStandardVaccine(apiContent);
218221
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { VaccineInfo, VaccineType } from "@src/models/vaccine";
2+
import { getFilteredContentForFluInPregnancyVaccine } from "@src/services/content-api/parsers/custom/flu-in-pregnancy";
3+
4+
const apiResponse = JSON.stringify({
5+
mainEntityOfPage: [
6+
{ hasPart: [{ text: "Flu in Pregnancy Vaccine Lead Paragraph (overview)" }] },
7+
{ hasPart: [{ text: "<p>Why pregnant women are offered the vaccine paragraph</p>" }] },
8+
{ hasPart: [{ text: "<p>Is the vaccine safe in pregnancy paragraph</p>" }] },
9+
{ hasPart: [{ text: "<p>When should I have the vaccine paragraph</p>" }] },
10+
{ hasPart: [{ text: "<p>How to get the vaccine paragraph</p>" }] },
11+
{ hasPart: [{ text: "paragraph 5" }] },
12+
],
13+
});
14+
15+
describe("getFilteredContentForFluInPregnancyVaccine", () => {
16+
it("should return overview text from lead paragraph mainEntityOfPage object", async () => {
17+
const expected = {
18+
overview: { content: "Flu in Pregnancy Vaccine Lead Paragraph (overview)", containsHtml: true },
19+
};
20+
21+
const pageCopy = getFilteredContentForFluInPregnancyVaccine(apiResponse);
22+
23+
expect(pageCopy).toEqual(expect.objectContaining(expected));
24+
});
25+
26+
it("should return all parts for whatVaccineIsFor section", () => {
27+
const expected = {
28+
whatVaccineIsFor: {
29+
headline: "Why pregnant women are offered the vaccine",
30+
subsections: [
31+
{
32+
type: "simpleElement",
33+
headline: "",
34+
name: "markdown",
35+
text: "<p>Why pregnant women are offered the vaccine paragraph</p>",
36+
},
37+
],
38+
},
39+
};
40+
41+
const pageCopy = getFilteredContentForFluInPregnancyVaccine(apiResponse);
42+
43+
expect(pageCopy).toEqual(expect.objectContaining(expected));
44+
});
45+
46+
it("should return all parts for whoVaccineIsFor section", () => {
47+
const expected = {
48+
whoVaccineIsFor: {
49+
headline: "Is the vaccine safe in pregnancy?",
50+
subsections: [
51+
{
52+
type: "simpleElement",
53+
headline: "",
54+
name: "markdown",
55+
text: "<p>Is the vaccine safe in pregnancy paragraph</p>",
56+
},
57+
],
58+
},
59+
};
60+
61+
const pageCopy = getFilteredContentForFluInPregnancyVaccine(apiResponse);
62+
63+
expect(pageCopy).toEqual(expect.objectContaining(expected));
64+
});
65+
66+
it("should return all parts for howToGetVaccine section", () => {
67+
const expected = {
68+
howToGetVaccine: {
69+
headline: "How to get the vaccine",
70+
subsections: [
71+
{
72+
type: "simpleElement",
73+
headline: "",
74+
name: "markdown",
75+
text: "<p>How to get the vaccine paragraph</p>",
76+
},
77+
],
78+
},
79+
};
80+
81+
const pageCopy = getFilteredContentForFluInPregnancyVaccine(apiResponse);
82+
83+
expect(pageCopy).toEqual(expect.objectContaining(expected));
84+
});
85+
86+
it("should return all parts for vaccineSideEffects section", () => {
87+
const expected = {
88+
vaccineSideEffects: {
89+
headline: "When should I have the vaccine?",
90+
subsections: [
91+
{
92+
type: "simpleElement",
93+
headline: "",
94+
name: "markdown",
95+
text: "<p>When should I have the vaccine paragraph</p>",
96+
},
97+
],
98+
},
99+
};
100+
101+
const pageCopy = getFilteredContentForFluInPregnancyVaccine(apiResponse);
102+
103+
expect(pageCopy).toEqual(expect.objectContaining(expected));
104+
});
105+
106+
it("should include nhs webpage link to vaccine info", () => {
107+
const expected = {
108+
webpageLink: VaccineInfo[VaccineType.WHOOPING_COUGH].nhsWebpageLink,
109+
};
110+
111+
const pageCopy = getFilteredContentForFluInPregnancyVaccine(apiResponse);
112+
113+
expect(pageCopy).toEqual(expect.objectContaining(expected));
114+
});
115+
});
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 getFilteredContentForFluInPregnancyVaccine = (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 = { content: paragraphs[0], containsHtml: true };
13+
const whyOffered: VaccinePageSection = {
14+
headline: "Why pregnant women are offered the vaccine",
15+
subsections: [{ type: "simpleElement", headline: "", text: paragraphs[1], name: "markdown" }],
16+
};
17+
const isItSafe: VaccinePageSection = {
18+
headline: "Is the vaccine safe in pregnancy?",
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[4], name: "markdown" }],
24+
};
25+
const whenToGet: VaccinePageSection = {
26+
headline: "When should I have the vaccine?",
27+
subsections: [{ type: "simpleElement", headline: "", text: paragraphs[3], name: "markdown" }],
28+
};
29+
const webpageLink: URL = VaccineInfo[VaccineType.WHOOPING_COUGH].nhsWebpageLink;
30+
31+
return {
32+
overview,
33+
whatVaccineIsFor: whyOffered,
34+
whoVaccineIsFor: isItSafe,
35+
howToGetVaccine,
36+
vaccineSideEffects: whenToGet,
37+
webpageLink,
38+
};
39+
};

src/services/content-api/parsers/custom/whooping-cough.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const apiResponse = JSON.stringify({
2222
],
2323
});
2424

25-
describe("getFilteredContentForVaccine", () => {
25+
describe("getFilteredContentForWhoopingCoughVaccine", () => {
2626
it("should return overview text from lead paragraph mainEntityOfPage object", async () => {
2727
const expected = { overview: { content: "Whooping Cough Vaccine Lead Paragraph (overview)", containsHtml: true } };
2828

0 commit comments

Comments
 (0)