fix(cms): filter unpublished relationships
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { resolveCmsRelationship, type CmsRouteDoc } from '@/spa/cmsRoute'
|
||||
import { resolveCmsRelationship, resolveCmsRelationships, type CmsRouteDoc } from '@/spa/cmsRoute'
|
||||
|
||||
const fullWinner: CmsRouteDoc = {
|
||||
id: 20,
|
||||
@@ -17,9 +17,24 @@ describe('CMS relationship resolution', () => {
|
||||
expect(resolveCmsRelationship(20, [fullWinner])).toBe(fullWinner)
|
||||
})
|
||||
|
||||
it('preserves a populated relationship when no list document is available', () => {
|
||||
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, [])).toBe(relationship)
|
||||
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,
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user