26 lines
902 B
TypeScript
26 lines
902 B
TypeScript
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)
|
|
})
|
|
})
|