- Q3: the integration status (emailStatus, turnstileStatus) is written alone through the database adapter (writeGlobalFields, exported): a visitor's form submit no longer puts back an admin's SMTP or Turnstile change saved at the same moment. addToCookieList reads the list again right before writing and works the change out again when an editor's save changed it (up to 5 times). Both races reproduced exactly in test/statusWrites.test.ts, on the three adapters. - Q4: cookieScanner.access and the doctor's access go through accessAllowed: any truthy answer still allows, an answer that is not a boolean is reported once per option; strict (only true) is announced for 1.19.0. - Q5: related documents that are drafts are left out of what the public helpers answer (resolveRoute, getSettings, getArchiveEntries, the 404 page, llms-full; Markdown and MCP through resolveRoute): null alone, removed from a list, value null in a polymorphic one. A preview keeps them; draftRelations: 'keep' keeps the old behaviour. withoutDraftRelations, applyDraftRelations exported. - Docs: content.md, frontend.md, integrations.md, cookie-scanner.md, security.md, AGENT.md; iapl-nav and iapl-doctor skills. Co-Authored-By: Claude Opus 5.5 <[email protected]>
106 lines
5.7 KiB
TypeScript
106 lines
5.7 KiB
TypeScript
/**
|
|
* Drafts as related documents (owner's decision Q5, 1.18.0): a block, a menu or a System pages link that points at a
|
|
* page never published no longer brings that page's title, slug and text into what the public helpers answer.
|
|
* `draftRelations: 'keep'` and a preview (`draft: true`) keep the old behaviour.
|
|
* Real database; SQLite by default, Postgres / MongoDB with IPAL_TEST_POSTGRES_URI / IPAL_TEST_MONGO_URI.
|
|
*/
|
|
import type { Payload } from 'payload'
|
|
|
|
import { lexicalEditor } from '@payloadcms/richtext-lexical'
|
|
import os from 'os'
|
|
import path from 'path'
|
|
import { getPayload } from 'payload'
|
|
import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest'
|
|
|
|
import { withoutDraftRelations } from '../src/modules/content/draftRelations.js'
|
|
import { getArchiveEntries } from '../src/modules/content/getArchiveEntries.js'
|
|
import { resolveRoute } from '../src/modules/content/resolveRoute.js'
|
|
import { iapl } from '../src/plugin.js'
|
|
import { buildTestConfig } from './helpers.js'
|
|
import { testDatabase } from './http/db.js'
|
|
|
|
vi.mock('server-only', () => ({}))
|
|
|
|
describe('withoutDraftRelations', () => {
|
|
const draft = { id: 2, _status: 'draft', title: 'Secret' }
|
|
const live = { id: 1, _status: 'published', title: 'Live' }
|
|
|
|
test('drops a draft related document: null alone, removed from a list, value null in a polymorphic one', () => {
|
|
const doc = { id: 9, _status: 'published', layout: [{ blockType: 'cards', items: [live, draft], one: draft, poly: { relationTo: 'pages', value: draft } }] }
|
|
expect(withoutDraftRelations(doc)).toEqual({ id: 9, _status: 'published', layout: [{ blockType: 'cards', items: [live], one: null, poly: { relationTo: 'pages', value: null } }] })
|
|
})
|
|
|
|
test('the document itself, ids, uploads and documents without _status are left alone; nothing is mutated', () => {
|
|
const doc = { id: 3, _status: 'draft', image: { id: 5, url: '/m.png' }, page: 2, pages: [1, 2] }
|
|
expect(withoutDraftRelations(doc)).toBe(doc)
|
|
const nested = { a: { b: draft } }
|
|
const out = withoutDraftRelations(nested)
|
|
expect(out).toEqual({ a: { b: null } })
|
|
expect(nested.a.b).toBe(draft)
|
|
})
|
|
})
|
|
|
|
describe('the public helpers on a real database', () => {
|
|
let payload: Payload
|
|
beforeAll(async () => {
|
|
const config = buildTestConfig({
|
|
collections: [
|
|
{
|
|
slug: 'pages',
|
|
access: { read: () => true },
|
|
fields: [
|
|
{ name: 'title', type: 'text' },
|
|
{ name: 'slug', type: 'text', localized: true },
|
|
{ name: 'related', type: 'relationship', relationTo: 'pages' },
|
|
{ name: 'list', type: 'relationship', hasMany: true, relationTo: 'pages' },
|
|
{ name: 'layout', type: 'blocks', blocks: [{ slug: 'link', fields: [{ name: 'page', type: 'relationship', relationTo: ['pages', 'posts'] }] }] },
|
|
],
|
|
versions: { drafts: true },
|
|
},
|
|
{ slug: 'posts', fields: [{ name: 'title', type: 'text' }, { name: 'slug', type: 'text', localized: true }, { name: 'see', type: 'relationship', relationTo: 'pages' }], versions: { drafts: true } },
|
|
{ slug: 'media', fields: [], upload: { staticDir: path.join(os.tmpdir(), 'iapl-draft-relations') } },
|
|
],
|
|
db: testDatabase('draft_relations'),
|
|
editor: lexicalEditor(),
|
|
plugins: [iapl({ access: { authCollection: 'users' }, content: { collections: [{ slug: 'posts' }] }, i18n: { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }] }, mail: { relay: false }, pages: { slug: 'pages' }, twoFactor: false })],
|
|
secret: 'draft-relations-0123456789-0123456789',
|
|
telemetry: false,
|
|
})
|
|
payload = await getPayload({ config })
|
|
const secret = await payload.create({ collection: 'pages' as never, data: { slug: 'tajna', _status: 'draft', title: 'Secret price list' } as never, draft: true })
|
|
const live = await payload.create({ collection: 'pages' as never, data: { slug: 'o-nas', _status: 'published', title: 'About' } as never })
|
|
await payload.create({
|
|
collection: 'pages' as never,
|
|
data: { slug: 'start', _status: 'published', layout: [{ blockType: 'link', page: { relationTo: 'pages', value: secret.id } }], list: [live.id, secret.id], related: secret.id, title: 'Start' } as never,
|
|
})
|
|
await payload.create({ collection: 'posts' as never, data: { slug: 'wpis', _status: 'published', see: secret.id, title: 'Post' } as never })
|
|
}, 120_000)
|
|
|
|
afterAll(async () => {
|
|
await payload?.destroy?.()
|
|
})
|
|
|
|
const start = async (options: Record<string, unknown> = {}) => (await resolveRoute({ locale: 'pl', payload, segments: ['start'], ...options }))?.doc as Record<string, unknown>
|
|
|
|
test('resolveRoute: the page answers without the draft it points at (single, list, polymorphic block)', async () => {
|
|
const doc = await start()
|
|
expect(doc.related).toBeNull()
|
|
expect((doc.list as { title: string }[]).map((p) => p.title)).toEqual(['About'])
|
|
expect((doc.layout as { page: { value: unknown } }[])[0].page.value).toBeNull()
|
|
expect(JSON.stringify(doc)).not.toContain('Secret price list')
|
|
})
|
|
|
|
test("draftRelations: 'keep' and a preview answer them as before", async () => {
|
|
for (const options of [{ draftRelations: 'keep' }, { draft: true }]) {
|
|
expect(JSON.stringify(await start(options))).toContain('Secret price list')
|
|
}
|
|
})
|
|
|
|
test('getArchiveEntries: an entry without the draft it points at; keep as before', async () => {
|
|
const hidden = await getArchiveEntries({ collection: 'posts', locale: 'pl', payload })
|
|
expect((hidden.docs[0] as { see: unknown }).see).toBeNull()
|
|
const kept = await getArchiveEntries({ collection: 'posts', draftRelations: 'keep', locale: 'pl', payload })
|
|
expect(JSON.stringify(kept.docs)).toContain('Secret price list')
|
|
})
|
|
})
|