teqo-backup/src/utilities/socialFeed/excludedItems.ts
Francisco Solla 7259193060 S2-FOLLOWUP (#775) — validate do itemId YouTube deixa de ser código morto
O validate de itemId em social-feed-settings lia data.platform (doc inteiro,
sempre undefined) e nunca validava ID de vídeo em produção. Agora lê
siblingData.platform via helper validateExcludedItemId. Stub YouTube ganha
ids de 11 chars e o spec acompanha, destravando o e2e do describe
'Campaign home content section'. Sem migration.
2026-08-24 23:46:57 -03:00

19 lines
843 B
TypeScript

/**
* Validation for `socialFeedSettings.excludedItems[].itemId` (the campaign home
* content board's manual exclusion list). The field is an array row: Payload
* passes the row's own siblings through `siblingData`, NOT the document, so the
* validate must read the platform from `siblingData` (the previous
* `validate` read `data.platform`, which is the whole document and therefore
* always `undefined` — dead code that never validated anything in production).
*/
export const YOUTUBE_VIDEO_ID_PATTERN = /^[A-Za-z0-9_-]{11}$/
export const validateExcludedItemId = (
value: string | null | undefined,
siblingData?: { platform?: string },
): true | string => {
if (siblingData?.platform === 'youtube' && value && !YOUTUBE_VIDEO_ID_PATTERN.test(value)) {
return 'Informe o ID do vídeo (11 caracteres)'
}
return true
}