Cookie scanner, phase 1: declarations, database lookup, review list
ipalKit({ cookieScanner }) (opt-in) adds the cookie-review collection, a
"Scan cookies" box above its list and GET/POST /api/ipal/cookie-scan. A scan
lists the cookies of every integration the project switches on (consent,
admin login, locale, stats, GA4, GTM, Meta Pixel, Clarity, LinkedIn, TikTok,
Turnstile), the project's own declarations, and extra names looked up in the
bundled Open Cookie Database, as drafts. Editors accept (→ Cookie Settings →
Cookies, every locale, only empty text filled), edit or reject. A rescan never
deletes, never changes status and never overwrites edited text.
Everything is overridable (access, collectionOverrides, integrations,
declarations, databaseCategories, labels, syncAccepted) and the building
blocks are exported. Admin labels in en + pl. Docs: cookie-scanner.md,
consent.md, AGENT.md, ipal-reference, ipal-consent-check.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ab45cf48be
commit
a0545b6716
@@ -0,0 +1,212 @@
|
||||
import type { BasePayload, Config } from 'payload'
|
||||
|
||||
import { describe, expect, test, vi } from 'vitest'
|
||||
|
||||
import type { CookieScanContext } from '../src/modules/consent/scanner/types.js'
|
||||
|
||||
import { indexCookieDatabase, loadCookieDatabase, lookupCookie } from '../src/modules/consent/scanner/cookieDatabase.js'
|
||||
import { OPEN_COOKIE_DATABASE_SOURCE } from '../src/modules/consent/scanner/data/openCookieDatabase.js'
|
||||
import { cookieNameMatches, DEFAULT_COOKIE_INTEGRATIONS } from '../src/modules/consent/scanner/integrations.js'
|
||||
import { COOKIE_SCAN_LABELS, labelFor, labelRecord, mergeCookieScanLabels } from '../src/modules/consent/scanner/labels.js'
|
||||
import { mergeCookieReview, suggestionFor, textFor } from '../src/modules/consent/scanner/merge.js'
|
||||
import { collectCookieFindings, parseCookieNames } from '../src/modules/consent/scanner/scan.js'
|
||||
import { ipalKit } from '../src/plugin.js'
|
||||
|
||||
vi.mock('server-only', () => ({}))
|
||||
|
||||
const ctx = (integrations: Record<string, unknown> = {}, plugin: Partial<CookieScanContext['plugin']> = {}): CookieScanContext => ({
|
||||
integrations,
|
||||
payload: {
|
||||
config: { cookiePrefix: 'payload' },
|
||||
findGlobal: vi.fn(async () => integrations),
|
||||
logger: { error: vi.fn(), info: vi.fn(), warn: vi.fn() },
|
||||
} as unknown as BasePayload,
|
||||
plugin: { localeCount: 1, stats: false, ...plugin },
|
||||
})
|
||||
|
||||
describe('cookie scanner — names', () => {
|
||||
test('a trailing * is a prefix, anything else exact', () => {
|
||||
expect(cookieNameMatches('_ga_*', '_ga_ABC123')).toBe(true)
|
||||
expect(cookieNameMatches('_ga_*', '_ga')).toBe(false)
|
||||
expect(cookieNameMatches('_ga', '_ga')).toBe(true)
|
||||
expect(cookieNameMatches('_ga', '_gat')).toBe(false)
|
||||
})
|
||||
|
||||
test('names from the panel: trimmed, unique, invalid dropped, capped', () => {
|
||||
expect(parseCookieNames(' _ga \n\n_fbp\n_ga\nbad name\na;b\nx=y')).toEqual(['_ga', '_fbp'])
|
||||
expect(parseCookieNames(['a', 1, null, 'b'])).toEqual(['a', 'b'])
|
||||
expect(parseCookieNames(undefined)).toEqual([])
|
||||
expect(parseCookieNames(Array.from({ length: 500 }, (_, i) => `c${i}`))).toHaveLength(200)
|
||||
})
|
||||
})
|
||||
|
||||
describe('cookie scanner — Open Cookie Database', () => {
|
||||
test('the bundled copy names its source, license and commit', () => {
|
||||
expect(OPEN_COOKIE_DATABASE_SOURCE.license).toBe('Apache-2.0')
|
||||
expect(OPEN_COOKIE_DATABASE_SOURCE.commit).toMatch(/^[0-9a-f]{40}$/)
|
||||
})
|
||||
|
||||
test('exact names, wildcard prefixes, third-party domains', async () => {
|
||||
const db = await loadCookieDatabase()
|
||||
expect(lookupCookie(db, '_ga')).toMatchObject({ name: '_ga', category: 'analytics', source: 'database', vendor: 'Google' })
|
||||
const gac = lookupCookie(db, '_gac_UA-123')
|
||||
expect(gac?.name).toBe('_gac_*') // one entry per pattern, not per site-specific suffix
|
||||
expect(lookupCookie(db, '_fbp')).toMatchObject({ category: 'marketing', domain: 'facebook.com' })
|
||||
expect(lookupCookie(db, 'no-such-cookie-xyz')).toBeNull()
|
||||
})
|
||||
|
||||
test('categories map to consent categories, and the map is overridable', () => {
|
||||
const db = indexCookieDatabase([
|
||||
['sess', 'App', 'Functional', '', 'Session', 'session', 'Acme', 0],
|
||||
['pref', 'App', 'Personalization', '', 'Prefs', '1 year', 'Acme', 0],
|
||||
['pre_', 'App', 'Security', '', 'Guard', '1 day', 'Acme', 1],
|
||||
['pre_long_', 'App', 'Marketing', '', 'Ads', '1 day', 'Acme', 1],
|
||||
])
|
||||
// Functional is never mapped to necessary by default — an unchecked lookup must not skip consent
|
||||
expect(lookupCookie(db, 'sess')?.category).toBe('functional')
|
||||
expect(lookupCookie(db, 'pref')?.category).toBe('functional')
|
||||
expect(lookupCookie(db, 'sess', { Functional: 'necessary' })?.category).toBe('necessary')
|
||||
// the longest prefix wins
|
||||
expect(lookupCookie(db, 'pre_long_1')?.category).toBe('marketing')
|
||||
expect(lookupCookie(db, 'pre_1')?.category).toBe('necessary')
|
||||
})
|
||||
})
|
||||
|
||||
describe('cookie scanner — findings', () => {
|
||||
test('only integrations the project switches on', async () => {
|
||||
const { enabled, findings } = await collectCookieFindings({ ctx: ctx({ ga4MeasurementId: 'G-ABC123DEF4' }), database: false })
|
||||
expect(enabled.map((i) => i.key)).toEqual(['consent', 'admin', 'ga4'])
|
||||
expect(findings.map((f) => f.name)).toEqual(['cookie-consent', 'payload-token', '_ga', '_ga_*'])
|
||||
expect(findings.every((f) => f.source === 'integration')).toBe(true)
|
||||
})
|
||||
|
||||
test('stats, languages, pixels and Turnstile follow the project config', async () => {
|
||||
const on = await collectCookieFindings({
|
||||
ctx: ctx(
|
||||
{ clarityProjectId: 'abcdefghij', metaPixelId: '1234567890123456', turnstileSecretKey: 's', turnstileSiteKey: 'k' },
|
||||
{ localeCount: 2, stats: true },
|
||||
),
|
||||
database: false,
|
||||
})
|
||||
const names = on.findings.map((f) => f.name)
|
||||
for (const n of ['ipal_vid', 'NEXT_LOCALE', '_fbp', '_fbc', '_clck', 'cf_clearance']) {expect(names).toContain(n)}
|
||||
expect(names).not.toContain('_ttp')
|
||||
// an invalid ID counts as off
|
||||
const bad = await collectCookieFindings({ ctx: ctx({ metaPixelId: 'nope' }), database: false })
|
||||
expect(bad.findings.map((f) => f.name)).not.toContain('_fbp')
|
||||
})
|
||||
|
||||
test('every built-in declaration has text in English and Polish and a sane category', () => {
|
||||
for (const integration of DEFAULT_COOKIE_INTEGRATIONS) {
|
||||
const list = typeof integration.declarations === 'function' ? integration.declarations(ctx()) : integration.declarations
|
||||
for (const d of list) {
|
||||
expect(typeof d.purpose === 'object' && d.purpose.en && d.purpose.pl, `${d.name} purpose`).toBeTruthy()
|
||||
expect(typeof d.retention === 'object' && d.retention.en && d.retention.pl, `${d.name} retention`).toBeTruthy()
|
||||
// only necessary cookies may be set before consent
|
||||
if (d.setBeforeConsent) {expect(d.category, d.name).toBe('necessary')}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test('project declarations, then built-ins, then the database, then unknown', async () => {
|
||||
const { findings } = await collectCookieFindings({
|
||||
ctx: ctx(),
|
||||
declarations: [{ name: 'yt-*', category: 'marketing', purpose: 'YouTube embed', retention: '6 months', setBeforeConsent: false, vendor: 'Google' }],
|
||||
names: ['yt-player', '_fbp', '_hjSessionUser_123', 'totally_unknown', 'cookie-consent'],
|
||||
})
|
||||
const by = Object.fromEntries(findings.map((f) => [f.name, f]))
|
||||
expect(by['yt-*'].source).toBe('project')
|
||||
expect(by['yt-player']).toBeUndefined() // covered by the project's pattern
|
||||
expect(by._fbp).toMatchObject({ source: 'integration', sourceDetail: 'Meta Pixel' }) // built-in text even with the pixel off
|
||||
expect(by['_hjSessionUser_*']).toMatchObject({ category: 'functional', source: 'database' }) // filed as Functional upstream — asks for consent
|
||||
expect(by.totally_unknown).toEqual({ name: 'totally_unknown', source: 'unknown', storage: 'cookie' })
|
||||
expect(findings.filter((f) => f.name === 'cookie-consent')).toHaveLength(1)
|
||||
})
|
||||
|
||||
test('a failing isEnabled counts as off and is logged', async () => {
|
||||
const c = ctx()
|
||||
const { enabled } = await collectCookieFindings({
|
||||
ctx: c,
|
||||
database: false,
|
||||
integrations: [{ declarations: [], isEnabled: () => { throw new Error('boom') }, key: 'x', label: 'X' }],
|
||||
})
|
||||
expect(enabled).toEqual([])
|
||||
expect(c.payload.logger.warn).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('cookie scanner — merging a rescan', () => {
|
||||
const next = suggestionFor(
|
||||
{ name: '_ga', category: 'analytics', purpose: { en: 'New EN', pl: 'Nowy PL' }, retention: '2 years', source: 'integration', storage: 'cookie', vendor: 'Google' },
|
||||
['pl', 'en'],
|
||||
)
|
||||
|
||||
test('text per locale: own language, English, first', () => {
|
||||
expect(textFor({ en: 'E', pl: 'P' }, 'pl')).toBe('P')
|
||||
expect(textFor({ en: 'E', pl: 'P' }, 'de')).toBe('E')
|
||||
expect(textFor({ fr: 'F' }, 'de')).toBe('F')
|
||||
expect(textFor('same', 'pl')).toBe('same')
|
||||
expect(next.retention).toEqual({ en: '2 years', pl: '2 years' })
|
||||
})
|
||||
|
||||
test('empty and untouched values follow the scan', () => {
|
||||
const previous = { category: 'analytics' as const, purpose: { en: 'Old EN', pl: 'Stary PL' }, vendor: 'Google' }
|
||||
const { changed, values } = mergeCookieReview({ ...previous, retention: {} }, previous, next)
|
||||
expect(changed).toBe(true)
|
||||
expect(values.purpose).toEqual({ en: 'New EN', pl: 'Nowy PL' })
|
||||
expect(values.retention).toEqual({ en: '2 years', pl: '2 years' })
|
||||
})
|
||||
|
||||
test('text an editor changed is never overwritten — per locale and per field', () => {
|
||||
const previous = { category: 'analytics' as const, purpose: { en: 'Old EN', pl: 'Stary PL' }, vendor: 'Google' }
|
||||
const current = { category: 'marketing' as const, purpose: { en: 'Old EN', pl: 'Mój tekst' }, vendor: 'Google LLC' }
|
||||
const { values } = mergeCookieReview(current, previous, next)
|
||||
expect(values.purpose).toEqual({ en: 'New EN', pl: 'Mój tekst' })
|
||||
expect(values.vendor).toBe('Google LLC')
|
||||
expect(values.category).toBe('marketing')
|
||||
})
|
||||
|
||||
test('same suggestion again → nothing changes', () => {
|
||||
expect(mergeCookieReview(next, next, next).changed).toBe(false)
|
||||
})
|
||||
|
||||
test('a missing suggestion never clears a value', () => {
|
||||
const { changed, values } = mergeCookieReview({ vendor: 'Mine' }, undefined, {})
|
||||
expect(changed).toBe(false)
|
||||
expect(values.vendor).toBe('Mine')
|
||||
})
|
||||
})
|
||||
|
||||
describe('cookie scanner — labels and config', () => {
|
||||
test('English and Polish for every label; projects add languages and change text', () => {
|
||||
expect(Object.keys(COOKIE_SCAN_LABELS.pl).sort()).toEqual(Object.keys(COOKIE_SCAN_LABELS.en).sort())
|
||||
const labels = mergeCookieScanLabels({ de: { scanButton: 'Cookies scannen' }, pl: { scanButton: 'Skanuj' } })
|
||||
expect(labelRecord(labels, 'scanButton')).toEqual({ de: 'Cookies scannen', en: 'Scan cookies', pl: 'Skanuj' })
|
||||
expect(labels.de.status).toBe('Status') // missing keys fall back to English
|
||||
expect(labelFor(labels, 'fr', 'scanButton')).toBe('Scan cookies')
|
||||
})
|
||||
|
||||
const run = async (cookieScanner?: unknown) =>
|
||||
ipalKit({
|
||||
cookieScanner: cookieScanner as never,
|
||||
i18n: { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }] },
|
||||
twoFactor: false,
|
||||
})({ collections: [{ slug: 'users', auth: true, fields: [] }] } as unknown as Config)
|
||||
|
||||
test('off by default: no collection, no endpoint', async () => {
|
||||
const config = await run()
|
||||
expect(config.collections?.some((c) => c.slug === 'cookie-review')).toBe(false)
|
||||
expect(config.endpoints?.some((e) => e.path === '/ipal/cookie-scan')).toBe(false)
|
||||
})
|
||||
|
||||
test('on: collection with the scan button, GET + POST endpoint; overrides win', async () => {
|
||||
const config = await run({ collectionOverrides: { admin: { group: 'Privacy' } }, syncAccepted: false })
|
||||
const review = config.collections?.find((c) => c.slug === 'cookie-review')
|
||||
expect(review?.admin?.group).toBe('Privacy')
|
||||
expect(review?.admin?.components?.beforeListTable).toEqual([
|
||||
expect.objectContaining({ path: '@intecion/ipal-kit/admin#CookieScanButton' }),
|
||||
])
|
||||
expect(review?.hooks?.afterChange).toEqual([])
|
||||
expect(config.endpoints?.filter((e) => e.path === '/ipal/cookie-scan').map((e) => e.method).sort()).toEqual(['get', 'post'])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,174 @@
|
||||
/**
|
||||
* Cookie scanner through a REAL Payload (SQLite in memory, two locales): scan →
|
||||
* drafts → editor edits → rescan keeps the edits → accept → Cookie Settings.
|
||||
*/
|
||||
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, vi } from 'vitest'
|
||||
|
||||
import { buildCookieScanEndpoints } from '../src/modules/consent/scanner/endpoint.js'
|
||||
import { runCookieScan } from '../src/modules/consent/scanner/scan.js'
|
||||
import { ipalKit } from '../src/plugin.js'
|
||||
|
||||
vi.mock('server-only', () => ({}))
|
||||
|
||||
const SLUG = 'cookie-review' as never
|
||||
const plugin = { localeCount: 2, stats: true }
|
||||
const declarations = [
|
||||
{ name: 'yt-*', category: 'marketing' as const, purpose: { en: 'YouTube embed', pl: 'Film YouTube' }, retention: '6 months', setBeforeConsent: false, vendor: 'Google' },
|
||||
]
|
||||
|
||||
type Entry = {
|
||||
category?: string
|
||||
id: number
|
||||
key: string
|
||||
listed?: boolean
|
||||
name: string
|
||||
purpose?: Record<string, string> | string
|
||||
source: string
|
||||
status: string
|
||||
vendor?: string
|
||||
}
|
||||
|
||||
let payload: Payload
|
||||
|
||||
const all = async () => (await payload.find({ collection: SLUG, depth: 0, limit: 100, locale: 'all' as never })).docs as unknown as Entry[]
|
||||
const byName = async (name: string) => (await all()).find((e) => e.name === name)!
|
||||
const cookieList = async (locale: string) =>
|
||||
((await payload.findGlobal({ slug: 'cookie-settings' as never, fallbackLocale: false as never, locale: locale as never })) as {
|
||||
cookies?: { category: string; duration?: null | string; name: string; provider?: null | string; purpose?: null | string }[]
|
||||
}).cookies ?? []
|
||||
|
||||
beforeAll(async () => {
|
||||
const config = buildConfig({
|
||||
collections: [
|
||||
{ slug: 'users', auth: true, fields: [] },
|
||||
{ slug: 'media', fields: [], upload: { staticDir: path.join(os.tmpdir(), 'ipal-test-media') } },
|
||||
],
|
||||
db: sqliteAdapter({ client: { url: 'file::memory:' }, push: true }),
|
||||
editor: lexicalEditor(),
|
||||
plugins: [
|
||||
ipalKit({
|
||||
access: { authCollection: 'users' },
|
||||
cookieScanner: { declarations },
|
||||
i18n: {
|
||||
defaultLocale: 'pl',
|
||||
locales: [
|
||||
{ code: 'pl', label: 'Polski' },
|
||||
{ code: 'en', label: 'English' },
|
||||
],
|
||||
},
|
||||
stats: true,
|
||||
twoFactor: false,
|
||||
}),
|
||||
],
|
||||
secret: 'cookie-scanner-test-secret',
|
||||
telemetry: false,
|
||||
})
|
||||
payload = await getPayload({ config })
|
||||
await payload.updateGlobal({ slug: 'site-integrations' as never, data: { ga4MeasurementId: 'G-ABC123DEF4' } as never })
|
||||
// An editor's own row, already published before the first scan.
|
||||
await payload.updateGlobal({
|
||||
slug: 'cookie-settings' as never,
|
||||
data: { cookies: [{ name: '_ga', category: 'analytics', provider: 'Google', purpose: 'Tekst redaktora' }] } as never,
|
||||
locale: 'pl' as never,
|
||||
})
|
||||
}, 60_000)
|
||||
|
||||
afterAll(async () => {
|
||||
await payload?.destroy()
|
||||
})
|
||||
|
||||
describe('cookie scanner against a real Payload', () => {
|
||||
test('a scan writes drafts in every locale and publishes nothing', async () => {
|
||||
const { enabled, summary } = await runCookieScan({ names: ['_hjSessionUser_42', 'mystery'], options: { declarations }, payload, plugin })
|
||||
expect(enabled.map((i) => i.key)).toEqual(['consent', 'admin', 'locale', 'stats', 'ga4'])
|
||||
expect(summary).toMatchObject({ unknown: 1, updated: 0 })
|
||||
|
||||
const entries = await all()
|
||||
expect(entries.every((e) => e.status === 'draft')).toBe(true)
|
||||
expect(entries.map((e) => e.name).sort()).toEqual(
|
||||
['NEXT_LOCALE', '_ga', '_ga_*', '_hjSessionUser_*', 'cookie-consent', 'ipal_vid', 'mystery', 'payload-token', 'yt-*'].sort(),
|
||||
)
|
||||
expect((await byName('ipal_vid')).purpose).toMatchObject({ en: expect.stringContaining('Built-in statistics'), pl: expect.stringContaining('Wbudowane') })
|
||||
expect(await byName('_ga')).toMatchObject({ listed: true, source: 'integration' })
|
||||
expect(await byName('mystery')).toMatchObject({ source: 'unknown' })
|
||||
expect((await cookieList('pl')).map((c) => c.name)).toEqual(['_ga']) // nothing published
|
||||
})
|
||||
|
||||
test('a rescan keeps what an editor changed, adds nothing twice, deletes nothing', async () => {
|
||||
const vid = await byName('ipal_vid')
|
||||
await payload.update({ id: vid.id, collection: SLUG, data: { purpose: 'Mój opis', vendor: 'Nasza strona' } as never, locale: 'pl' as never })
|
||||
const before = (await all()).length
|
||||
|
||||
const { summary } = await runCookieScan({ options: { declarations }, payload, plugin })
|
||||
expect(summary.created).toBe(0)
|
||||
const after = await byName('ipal_vid')
|
||||
expect(after.purpose).toMatchObject({ en: expect.stringContaining('Built-in statistics'), pl: 'Mój opis' })
|
||||
expect(after.vendor).toBe('Nasza strona')
|
||||
expect((await all()).length).toBe(before) // names not passed again are kept
|
||||
})
|
||||
|
||||
test('accepting adds the cookie to Cookie Settings in every locale', async () => {
|
||||
const vid = await byName('ipal_vid')
|
||||
const saved = (await payload.update({ id: vid.id, collection: SLUG, data: { status: 'accepted' } as never, locale: 'pl' as never })) as unknown as Entry
|
||||
expect(saved.purpose).toBe('Mój opis') // the editor's save still answers in their locale
|
||||
const pl = (await cookieList('pl')).find((c) => c.name === 'ipal_vid')
|
||||
const en = (await cookieList('en')).find((c) => c.name === 'ipal_vid')
|
||||
expect(pl).toMatchObject({ category: 'analytics', duration: '6 mies.', provider: 'Nasza strona', purpose: 'Mój opis' })
|
||||
expect(en?.purpose).toContain('Built-in statistics')
|
||||
expect((await byName('ipal_vid')).listed).toBe(true)
|
||||
})
|
||||
|
||||
test('accepting an existing row fills only empty text, never the editor’s', async () => {
|
||||
const ga = await byName('_ga')
|
||||
await payload.update({ id: ga.id, collection: SLUG, data: { status: 'accepted' } as never, locale: 'pl' as never })
|
||||
const pl = (await cookieList('pl')).filter((c) => c.name === '_ga')
|
||||
expect(pl).toHaveLength(1)
|
||||
expect(pl[0]).toMatchObject({ duration: '2 lata', provider: 'Google', purpose: 'Tekst redaktora' })
|
||||
expect((await cookieList('en')).find((c) => c.name === '_ga')?.purpose).toContain('Google Analytics')
|
||||
})
|
||||
|
||||
test('an entry without a category cannot be accepted', async () => {
|
||||
const mystery = await byName('mystery')
|
||||
await expect(
|
||||
payload.update({ id: mystery.id, collection: SLUG, data: { status: 'accepted' } as never, locale: 'pl' as never }),
|
||||
).rejects.toThrow()
|
||||
})
|
||||
|
||||
test('rejecting keeps the entry; a rescan never changes its status', async () => {
|
||||
const yt = await byName('yt-*')
|
||||
await payload.update({ id: yt.id, collection: SLUG, data: { status: 'rejected' } as never, locale: 'pl' as never })
|
||||
await runCookieScan({ options: { declarations }, payload, plugin })
|
||||
expect((await byName('yt-*')).status).toBe('rejected')
|
||||
expect((await byName('ipal_vid')).status).toBe('accepted')
|
||||
expect((await cookieList('pl')).some((c) => c.name === 'yt-*')).toBe(false)
|
||||
})
|
||||
|
||||
test('the endpoint: editors scan, visitors and plain users get 403', async () => {
|
||||
const [get, post] = buildCookieScanEndpoints({ declarations }, plugin)
|
||||
const call = (endpoint: typeof get, user: unknown, body: unknown = {}) =>
|
||||
endpoint.handler({ json: async () => body, payload, user } as never) as Promise<Response>
|
||||
|
||||
expect((await call(post, null)).status).toBe(403)
|
||||
expect((await call(post, { collection: 'users', roles: ['user'] })).status).toBe(403)
|
||||
const editor = { collection: 'users', roles: ['editor'] }
|
||||
const listed = (await (await call(get, editor)).json()) as { integrations: { key: string }[] }
|
||||
expect(listed.integrations.map((i) => i.key)).toContain('ga4')
|
||||
const res = await call(post, editor, { names: ['_fbp'] })
|
||||
expect(res.status).toBe(200)
|
||||
expect(((await res.json()) as { summary: { created: number } }).summary.created).toBe(1)
|
||||
expect(await byName('_fbp')).toMatchObject({ source: 'integration', status: 'draft' })
|
||||
})
|
||||
|
||||
test('custom access option replaces the editor check', async () => {
|
||||
const [, post] = buildCookieScanEndpoints({ access: () => false }, plugin)
|
||||
const res = (await post.handler({ json: async () => ({}), payload, user: { collection: 'users', roles: ['admin'] } } as never))
|
||||
expect(res.status).toBe(403)
|
||||
})
|
||||
})
|
||||
@@ -236,6 +236,7 @@ describe('agent guide covers the whole plugin', () => {
|
||||
...typeKeys('src/modules/access/types.ts', 'AccessOption'),
|
||||
...typeKeys('src/modules/content/types.ts', 'ContentCollectionOption'),
|
||||
...typeKeys('src/modules/content/types.ts', 'ContentOption'),
|
||||
...typeKeys('src/modules/consent/scanner/types.ts', 'CookieScannerOptions'),
|
||||
...typeKeys('src/modules/forms/types.ts', 'FormsOption'),
|
||||
...typeKeys('src/modules/i18n/types.ts', 'I18nConfig'),
|
||||
...typeKeys('src/modules/i18n/types.ts', 'LocaleDefinition'),
|
||||
|
||||
Reference in New Issue
Block a user