fix: resolve selected winners from populated CMS data

This commit is contained in:
syntaxbullet
2026-07-13 12:19:02 +02:00
parent 818f283e10
commit b0aec7ba94
4 changed files with 38 additions and 21 deletions

View File

@@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest'
import { resolveCmsRelationship, type CmsRouteDoc } from '@/spa/cmsRoute'
const fullWinner: CmsRouteDoc = {
id: 20,
title: 'Adelholzener Alpenquellen GmbH',
image: { id: 55, url: '/api/media/file/image%20(1).png' },
}
describe('CMS relationship resolution', () => {
it('prefers the fully populated collection document over a shallow relationship object', () => {
expect(resolveCmsRelationship({ id: 20, image: 55 }, [fullWinner])).toBe(fullWinner)
})
it('resolves an ID-only relationship', () => {
expect(resolveCmsRelationship(20, [fullWinner])).toBe(fullWinner)
})
it('preserves a populated relationship when no list document is available', () => {
const relationship = { id: 20, image: { id: 55, url: '/api/media/file/image%20(1).png' } }
expect(resolveCmsRelationship(relationship, [])).toBe(relationship)
})
})