cookieScanner.crawl (opt-in) adds "Crawl site" to the Cookie review box. The
site asks the shared scanner service (services/cookie-crawler: Node +
Playwright, Dockerfile, deployed once on Coolify) to crawl its sitemap pages
twice, with no consent and after "Accept all". The service posts cookies,
storage keys and third-party hosts back to POST /api/ipal/cookie-crawl/results
(bearer token, running job only). No browser in the site.
Findings land as drafts through the same merge rules. Anything stored before
consent that is not necessary, and tracker requests before consent, are
violations, flagged on the review entries from the latest crawl only. The
cookie-crawl global keeps the latest result (no history). A dashboard warning
(CookieCrawlAlert) and an opt-in e-mail through the project's mail adapter
follow a crawl with violations or new unknown cookies. Scheduled crawls: a
Coolify scheduled task with the token. ipalEnvRules({ cookieCrawl: true }).
Also: the six older real-Payload tests no longer leave an orphaned
payload generate:types process (typescript.autoGenerate: false).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
94 lines
4.0 KiB
TypeScript
94 lines
4.0 KiB
TypeScript
/** Site Settings must stay shallow on every request; the rendered page is re-fetched at page depth. */
|
|
import type { Payload } from 'payload'
|
|
|
|
import { sqliteAdapter } from '@payloadcms/db-sqlite'
|
|
import { lexicalEditor } from '@payloadcms/richtext-lexical'
|
|
import os from 'os'
|
|
import path from 'path'
|
|
import { buildConfig, getPayload } from 'payload'
|
|
import { afterAll, beforeAll, describe, expect, test } from 'vitest'
|
|
|
|
import { resolveRoute } from '../src/modules/content/resolveRoute.js'
|
|
import { createContentHelpers } from '../src/modules/frontend/createContentHelpers.js'
|
|
import { ipalKit } from '../src/plugin.js'
|
|
|
|
let payload: Payload
|
|
let configPromise: ReturnType<typeof buildConfig>
|
|
let mediaId: number | string
|
|
|
|
beforeAll(async () => {
|
|
configPromise = buildConfig({
|
|
collections: [
|
|
{
|
|
slug: 'pages',
|
|
fields: [
|
|
{ name: 'title', type: 'text' },
|
|
{ name: 'slug', type: 'text', localized: true },
|
|
{ name: 'hero', type: 'upload', relationTo: 'media' },
|
|
],
|
|
},
|
|
{ slug: 'posts', fields: [{ name: 'title', type: 'text' }, { name: 'slug', type: 'text', localized: true }] },
|
|
{ slug: 'media', fields: [{ name: 'alt', type: 'text' }], upload: { staticDir: path.join(os.tmpdir(), 'ipal-test-media') } },
|
|
],
|
|
db: sqliteAdapter({ client: { url: 'file::memory:' }, push: true }),
|
|
editor: lexicalEditor(),
|
|
plugins: [
|
|
ipalKit({
|
|
access: { authCollection: 'users' },
|
|
content: { collections: [{ slug: 'posts' }] },
|
|
i18n: { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }] },
|
|
pages: { slug: 'pages' },
|
|
// a project field, e.g. a menu linking pages — not capped by maxDepth
|
|
siteSettingsFields: [{ name: 'featured', type: 'relationship', relationTo: 'pages' }],
|
|
twoFactor: false,
|
|
}),
|
|
],
|
|
secret: 'depth-test',
|
|
telemetry: false,
|
|
typescript: { autoGenerate: false }, // no orphaned `payload generate:types` child
|
|
})
|
|
payload = await getPayload({ config: configPromise })
|
|
const png = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==', 'base64')
|
|
const media = await payload.create({
|
|
collection: 'media' as never,
|
|
data: { alt: 'hero' } as never,
|
|
file: { name: 'hero.png', data: png, mimetype: 'image/png', size: png.length },
|
|
})
|
|
mediaId = media.id
|
|
const home = await payload.create({ collection: 'pages' as never, data: { slug: 'home', hero: mediaId, title: 'Home' } as never })
|
|
const blog = await payload.create({ collection: 'pages' as never, data: { slug: 'blog', hero: mediaId, title: 'Blog' } as never })
|
|
await payload.updateGlobal({ slug: 'site-settings' as never, data: { featured: home.id, homepage: home.id, postsArchive: blog.id, siteName: 'Acme' } as never })
|
|
}, 60_000)
|
|
|
|
afterAll(async () => {
|
|
await payload?.destroy()
|
|
})
|
|
|
|
describe('Site Settings depth', () => {
|
|
test('getSettings populates related pages one level only (their media stays an id)', async () => {
|
|
const { getSettings } = createContentHelpers({ config: configPromise })
|
|
const settings = (await getSettings('pl')) as { featured: { hero: unknown; slug: string } }
|
|
expect(settings.featured.slug).toBe('home')
|
|
expect(settings.featured.hero).toBe(mediaId)
|
|
})
|
|
|
|
test('the archive page is re-fetched at page depth, so its blocks and media render', async () => {
|
|
const route = await resolveRoute({
|
|
content: { collections: [{ slug: 'posts' }] },
|
|
locale: 'pl',
|
|
payload,
|
|
segments: ['blog'],
|
|
})
|
|
expect(route?.type).toBe('archive')
|
|
expect((route?.doc as { hero: { alt?: string } }).hero).toMatchObject({ alt: 'hero' })
|
|
})
|
|
})
|
|
|
|
describe('settingsDepth option', () => {
|
|
test('a project that needs deeper settings can raise the depth', async () => {
|
|
const { getSettings } = createContentHelpers({ config: configPromise, settingsDepth: 2 })
|
|
const settings = (await getSettings('pl')) as { featured: { hero: { alt?: string } } }
|
|
expect(settings.featured.hero).toMatchObject({ alt: 'hero' })
|
|
})
|
|
})
|