|
| 1 | +import { Breadcrumb, matchBreadcrumb } from "./Breadcrumb"; |
| 2 | +import { HealthTopicContent } from "./HealthTopicContent"; |
| 3 | +import { LinkRole, matchRelatedLink } from "./LinkRole"; |
| 4 | +import { matchWebPageElement, WebPageElement } from "./WebPageElement"; |
| 5 | +import { dateMatcher } from "../Matchers"; |
| 6 | + |
| 7 | +export type ContentAPIResponse = { |
| 8 | + "@context": "http://schema.org"; |
| 9 | + "@type": "MedicalWebPage"; |
| 10 | + "name": "RSV vaccine"; |
| 11 | + "copyrightHolder": { |
| 12 | + "@type": "Organization"; |
| 13 | + "name": "Crown Copyright"; |
| 14 | + } |
| 15 | + "license": "https://developer.api.nhs.uk/terms"; |
| 16 | + "author": { |
| 17 | + "url": "https://www.nhs.uk"; |
| 18 | + "logo": "https://assets.nhs.uk/nhsuk-cms/images/nhs-attribution.width-510.png"; |
| 19 | + |
| 20 | + "@type": "Organization"; |
| 21 | + "name": "NHS website"; |
| 22 | + } |
| 23 | + "about": { |
| 24 | + "name": "RSV vaccine"; |
| 25 | + "@type": "WebPage"; |
| 26 | + "alternatename": ["Respiratory syncytial virus (RSV) vaccine"]; |
| 27 | + } |
| 28 | + "description": string; |
| 29 | + "url": string |
| 30 | + "genre": ["Vaccine"]; |
| 31 | + "keywords": ""; |
| 32 | + "dateModified": string; |
| 33 | + "lastReviewed": string[]; |
| 34 | + "breadcrumb": Breadcrumb; |
| 35 | + "hasPart": HealthTopicContent[]; |
| 36 | + "relatedLink": LinkRole[]; |
| 37 | + "contentSubTypes": []; |
| 38 | + "mainEntityOfPage": WebPageElement[] |
| 39 | +} |
| 40 | + |
| 41 | +export const matchMainEntityOfPage = (actual: WebPageElement[]) => { |
| 42 | + let outer; |
| 43 | + expect(actual.length).toBeGreaterThanOrEqual(1); |
| 44 | + for (let i = 0; i < actual.length; i++) { |
| 45 | + outer = actual[i]; |
| 46 | + matchWebPageElement(outer, i); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +export const matchParts = (actual: HealthTopicContent[]) => { |
| 51 | + expect(actual.length).not.toBe(0); |
| 52 | + let outer, inner; |
| 53 | + for (let i = 0; i < actual.length; i++) { |
| 54 | + outer = actual[i]; |
| 55 | + expect(outer["@type"]).toBe("HealthTopicContent"); |
| 56 | + expect(actual[i].hasPart.length).not.toBe(0); |
| 57 | + for (let j = 0; j < outer["hasPart"].length; j++) { |
| 58 | + inner = outer["hasPart"][j]; |
| 59 | + expect(inner["@type"]).toBe("WebPageElement"); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +export const matchLastReviewed = (actual: string[]) => { |
| 65 | + expect(actual.length).not.toBe(0); |
| 66 | + for (const dateString in actual) dateMatcher(dateString); |
| 67 | +} |
| 68 | + |
| 69 | +export const matchContentAPIResponse = (actual: ContentAPIResponse) => { |
| 70 | + dateMatcher(actual["dateModified"]); |
| 71 | + matchBreadcrumb(actual["breadcrumb"]); |
| 72 | + matchLastReviewed(actual["lastReviewed"]); |
| 73 | + matchParts(actual["hasPart"]); |
| 74 | + matchRelatedLink(actual.relatedLink) |
| 75 | + matchMainEntityOfPage(actual["mainEntityOfPage"]); |
| 76 | +} |
0 commit comments