diff --git a/dotcom-rendering/src/types/article.ts b/dotcom-rendering/src/types/article.ts index a15e90c839..b1b5698071 100644 --- a/dotcom-rendering/src/types/article.ts +++ b/dotcom-rendering/src/types/article.ts @@ -1,9 +1,5 @@ -import { randomUUID } from 'node:crypto'; -import { - ArticleDesign, - type ArticleFormat, - decideFormat, -} from '../lib/articleFormat'; +import { isUndefined } from '@guardian/libs'; +import { type ArticleFormat, decideFormat } from '../lib/articleFormat'; import type { ImageForAppsLightbox } from '../model/appsLightboxImages'; import { appsLightboxImages } from '../model/appsLightboxImages'; import { buildLightboxImages } from '../model/buildLightboxImages'; @@ -36,37 +32,37 @@ export type Article = { }; export const enhanceCrossword = (article: Article): Article => { - if (article.frontendData.crossword) { - const element = { - _type: 'model.dotcomrendering.pageElements.CrosswordElement' as const, - crossword: article.frontendData.crossword, - }; - return { - ...article, - format: { ...article.format, design: ArticleDesign.Crossword }, - frontendData: { - ...article.frontendData, - blocks: [ - { - id: randomUUID(), - elements: [element], - attributes: { - pinned: false, - keyEvent: false, - summary: false, - }, - primaryDateLine: - article.frontendData.webPublicationDateDisplay, - secondaryDateLine: - article.frontendData - .webPublicationSecondaryDateDisplay, - }, - ], - }, - }; + if (isUndefined(article.frontendData.crossword)) { + throw new TypeError('article does not contain a crossword'); } - throw new TypeError('article did not contain a crossword'); + const element = { + _type: 'model.dotcomrendering.pageElements.CrosswordElement' as const, + crossword: article.frontendData.crossword, + }; + + return { + ...article, + format: { ...article.format }, + frontendData: { + ...article.frontendData, + blocks: [ + { + id: article.frontendData.crossword.id, + elements: [element], + attributes: { + pinned: false, + keyEvent: false, + summary: false, + }, + primaryDateLine: + article.frontendData.webPublicationDateDisplay, + secondaryDateLine: + article.frontendData.webPublicationSecondaryDateDisplay, + }, + ], + }, + }; }; export const enhanceArticleType = (