@@ -15,13 +15,15 @@ import footballMatchListPageSchema from '../frontend/schemas/feFootballMatchList
1515import footballMatchPageSchema from '../frontend/schemas/feFootballMatchPage.json' ;
1616import footballTablesPageSchema from '../frontend/schemas/feFootballTablesPage.json' ;
1717import frontSchema from '../frontend/schemas/feFront.json' ;
18+ import hostedContentSchema from '../frontend/schemas/feHostedContent.json' ;
1819import tagPageSchema from '../frontend/schemas/feTagPage.json' ;
1920import type { Block } from '../types/blocks' ;
2021import type { FEEditionsCrosswords } from '../types/editionsCrossword' ;
2122import type { FENewslettersPageType } from '../types/newslettersPage' ;
2223import blockSchema from './block-schema.json' ;
2324import editionsCrosswordSchema from './editions-crossword-schema.json' ;
2425import newslettersPageSchema from './newsletter-page-schema.json' ;
26+ import { FEHostedContent } from 'src/frontend/feHostedContent' ;
2527
2628const options : Options = {
2729 verbose : false ,
@@ -56,6 +58,7 @@ const validateCricketMatchPage = ajv.compile<FECricketMatchPage>(
5658const validateFootballMatchPage = ajv . compile < FEFootballMatchPage > (
5759 footballMatchPageSchema ,
5860) ;
61+ const validateHostedContent = ajv . compile < FEHostedContent > ( hostedContentSchema ) ;
5962
6063export const validateAsFEArticle = ( data : unknown ) : FEArticle => {
6164 if ( validateArticle ( data ) ) return data ;
@@ -186,3 +189,15 @@ export const validateAsFootballMatchPageType = (
186189 ${ JSON . stringify ( validateFootballMatchPage . errors , null , 2 ) } ` ,
187190 ) ;
188191} ;
192+
193+ export const validateAsHostedContent = ( data : unknown ) : FEHostedContent => {
194+ if ( validateHostedContent ( data ) ) return data ;
195+
196+ const url =
197+ isObject ( data ) && isString ( data . webURL ) ? data . webURL : 'unknown url' ;
198+
199+ throw new TypeError (
200+ `Unable to validate request body for url ${ url } .\n
201+ ${ JSON . stringify ( validateArticle . errors , null , 2 ) } ` ,
202+ ) ;
203+ } ;
0 commit comments