feat: implement home winners selection logic with fallback handling and add integration tests

This commit is contained in:
syntaxbullet
2026-07-13 15:19:37 +02:00
parent b7c499dd35
commit ee7e891a7d
3 changed files with 61 additions and 16 deletions

View File

@@ -0,0 +1,32 @@
import { describe, expect, it } from 'vitest'
import type { CmsRouteDoc } from '@/spa/cmsRoute'
import { resolveHomeWinners } from '@/spa/homeWinnerSelection'
const selected2026Winners: CmsRouteDoc[] = Array.from({ length: 16 }, (_, index) => ({
id: 65 + index,
title: `Winner ${65 + index}`,
year: 2026,
}))
const published2025Winners: CmsRouteDoc[] = Array.from({ length: 9 }, (_, index) => ({
id: 12 + index,
title: `Winner ${12 + index}`,
year: 2025,
}))
describe('home winner selection', () => {
it('uses a non-empty CMS selection without appending winners from the fallback year', () => {
const featured = selected2026Winners.map(({ id }) => id)
const winners = resolveHomeWinners(featured, [...selected2026Winners, ...published2025Winners], [])
expect(winners).toEqual(selected2026Winners)
expect(winners.some((winner) => winner.year === 2025)).toBe(false)
})
it('falls back to at most eight 2025 winners when the CMS selection is empty', () => {
const winners = resolveHomeWinners([], published2025Winners, [])
expect(winners).toEqual(published2025Winners.slice(0, 8))
})
})