|
| 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 | +}); |
0 commit comments