feat: implement home winners selection logic with fallback handling and add integration tests
This commit is contained in:
32
tests/int/home-winner-selection.int.spec.ts
Normal file
32
tests/int/home-winner-selection.int.spec.ts
Normal 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))
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user