fix(cms): remove unpublished content fallbacks

This commit is contained in:
syntaxbullet
2026-07-31 14:25:11 +02:00
parent b18bbbe36a
commit 8dc17c0fea
17 changed files with 358 additions and 273 deletions

View File

@@ -18,18 +18,14 @@ const published2025Winners: CmsRouteDoc[] = Array.from({ length: 9 }, (_, index)
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],
[],
)
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, [])
const winners = resolveHomeWinners([], published2025Winners)
expect(winners).toEqual(published2025Winners.slice(0, 8))
})
@@ -37,12 +33,8 @@ describe('home winner selection', () => {
it('omits an unpublished selected winner without changing the remaining page order', () => {
const [first, unpublished, third] = selected2026Winners
const selection = [third, { ...unpublished, image: { id: 99 } }, first]
const publicWinners = resolveHomeWinners(selection, [first, third], published2025Winners)
const previewWinners = resolveHomeWinners(
selection,
[first, unpublished, third],
published2025Winners,
)
const publicWinners = resolveHomeWinners(selection, [first, third])
const previewWinners = resolveHomeWinners(selection, [first, unpublished, third])
expect(publicWinners).toEqual([third, first])
expect(previewWinners).toEqual([third, unpublished, first])
@@ -51,8 +43,10 @@ describe('home winner selection', () => {
it('does not replace an entirely unpublished CMS selection with fallback winners', () => {
const [unpublished] = selected2026Winners
expect(
resolveHomeWinners([{ ...unpublished, image: { id: 99 } }], [], published2025Winners),
).toEqual([])
expect(resolveHomeWinners([{ ...unpublished, image: { id: 99 } }], [])).toEqual([])
})
it('does not resurrect static winners when the published collection is empty', () => {
expect(resolveHomeWinners([], [])).toEqual([])
})
})

View File

@@ -13,6 +13,7 @@ describe('Netzwerk jury members', () => {
expect(selectJuryDocs([3, { id: 1 }], docs).map((member) => member.id)).toEqual([3, 1])
expect(selectJuryDocs([], docs)).toEqual([])
expect(selectJuryDocs(undefined, docs)).toEqual(docs)
expect(selectJuryDocs(undefined, [])).toEqual([])
})
it('omits an unpublished selected member publicly and restores it in preview order', () => {

View File

@@ -0,0 +1,16 @@
import { describe, expect, it } from 'vitest'
import { pressEventsFromCms, pressNewsFromCms } from '@/spa/pressCollectionItems'
import { pressIndexContent } from '@/spa/pressIndexContent'
describe('press collection items', () => {
it('does not replace an empty published events collection with demo event rows', () => {
expect(
pressEventsFromCms([], '/images/event-placeholder.jpg', {}, pressIndexContent.events),
).toEqual([])
})
it('does not replace an empty published posts collection with demo news cards', () => {
expect(pressNewsFromCms([], '/images/news-placeholder.jpg', pressIndexContent.news)).toEqual([])
})
})

View File

@@ -202,11 +202,11 @@ describe('public route hydration', () => {
const publicDocs = await findFixtureDocs('preistraeger', ids, false)
const previewDocs = await findFixtureDocs('preistraeger', ids, true)
expect(resolveHomeWinners(selection, publicDocs, []).map((doc) => doc.id)).toEqual([
expect(resolveHomeWinners(selection, publicDocs).map((doc) => doc.id)).toEqual([
third.id,
first.id,
])
expect(resolveHomeWinners(selection, previewDocs, []).map((doc) => doc.id)).toEqual([
expect(resolveHomeWinners(selection, previewDocs).map((doc) => doc.id)).toEqual([
third.id,
unpublished.id,
first.id,
@@ -221,7 +221,7 @@ describe('public route hydration', () => {
})
const republishedDocs = await findFixtureDocs('preistraeger', ids, false)
expect(resolveHomeWinners(selection, republishedDocs, []).map((doc) => doc.id)).toEqual([
expect(resolveHomeWinners(selection, republishedDocs).map((doc) => doc.id)).toEqual([
third.id,
unpublished.id,
first.id,
@@ -297,6 +297,43 @@ describe('public route hydration', () => {
expect(previewDocs.map((doc) => doc.id)).toEqual([first.id, unpublished.id, third.id])
})
it('leaves no event row after the final /presse event is unpublished', async () => {
const event = await payload.create({
collection: 'events',
context: { disableRevalidate: true },
data: {
_status: 'published',
slug: `${fixtureKey}-event-final`,
title: `${fixtureKey} event final`,
},
draft: false,
})
cleanup.push(() =>
payload.delete({
collection: 'events',
context: { disableRevalidate: true },
id: event.id,
}),
)
expect((await findFixtureDocs('events', [event.id], false)).map((doc) => doc.id)).toEqual([
event.id,
])
await payload.update({
collection: 'events',
context: { disableRevalidate: true },
id: event.id,
data: { _status: 'draft' },
draft: false,
})
expect(await findFixtureDocs('events', [event.id], false)).toEqual([])
expect((await findFixtureDocs('events', [event.id], true)).map((doc) => doc.id)).toEqual([
event.id,
])
})
it('omits an unpublished event previously rendered on /presse', async () => {
const published = await payload.create({
collection: 'events',
@@ -341,6 +378,44 @@ describe('public route hydration', () => {
expect(previewDocs.map((doc) => doc.id).sort()).toEqual(ids.sort())
})
it('leaves no news card after the final /presse article is unpublished', async () => {
const post = await payload.create({
collection: 'posts',
context: { disableRevalidate: true },
data: {
_status: 'published',
content: lexicalDocument,
slug: `${fixtureKey}-post-final`,
title: `${fixtureKey} post final`,
},
draft: false,
})
cleanup.push(() =>
payload.delete({
collection: 'posts',
context: { disableRevalidate: true },
id: post.id,
}),
)
expect((await findFixtureDocs('posts', [post.id], false)).map((doc) => doc.id)).toEqual([
post.id,
])
await payload.update({
collection: 'posts',
context: { disableRevalidate: true },
id: post.id,
data: { _status: 'draft' },
draft: false,
})
expect(await findFixtureDocs('posts', [post.id], false)).toEqual([])
expect((await findFixtureDocs('posts', [post.id], true)).map((doc) => doc.id)).toEqual([
post.id,
])
})
it('omits an unpublished press article previously rendered on /presse', async () => {
const published = await payload.create({
collection: 'posts',