Files
bmp-website-2026/tests/int/cms-route-relationship.int.spec.ts
2026-07-31 14:10:44 +02:00

41 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { resolveCmsRelationship, resolveCmsRelationships, 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('rejects an embedded relationship when it is absent from the hydrated collection', () => {
const relationship = { id: 20, image: { id: 55, url: '/api/media/file/image%20(1).png' } }
expect(resolveCmsRelationship(relationship, [])).toBeUndefined()
})
it('preserves relationship selection order while omitting unavailable documents', () => {
const first = { id: 1, title: 'First' }
const second = { id: 2, title: 'Second' }
const third = { id: 3, title: 'Third' }
expect(resolveCmsRelationships([third, { id: 2, stale: true }, first], [first, third])).toEqual(
[third, first],
)
expect(resolveCmsRelationships([third, second, first], [first, second, third])).toEqual([
third,
second,
first,
])
})
})