buildR2Storage registered nothing without R2_* env, so `pnpm dev` / generate:importmap in dev
wrote an importMap.js without S3ClientUploadHandler — committed, the production admin (R2 on)
rendered a blank page with no console error (hit vanstev.pl). The injected s3Storage is now
always registered (enabled: false without R2 → local disk); storage-s3 still adds its client
handler, so the import map is identical in every environment. ipal-audit flags an import map
without the handler.
R2_PUBLIC_URL alone (absolute, outside production) = read-only media: URLs from the media
domain, upload/delete refused with 403 — local dev against a production database without
bucket keys. ipalEnvRules allows it in development.
Cookie Settings (MongoDB): the 1.11.1 rename buttons.save → savePreferences lost the texts on
the first save; onInit copies the old value (all locales) when the new field is missing.
getConsentTexts read the old field as a string, Mongo returns the raw { pl, en } map.
Also: context.ipalSkipAutoFill (SKIP_AUTO_FILL) — save without meta / aiSummary auto-fill;
createPageRoute redirects the homepage under its own slug (homeAlias, default 'redirect');
ipal-audit: multi-line tsconfig exclude, numeronyms (a11y) not "numbered fields",
`${prefix}/${slug}` links and slugs typed into links detected, clearer panel-language message.
Docs: fallback-on-save in i18n.md, `pnpm up --latest` and the stale-token 401 in PROGRAMISTA §1.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
50 lines
2.4 KiB
TypeScript
50 lines
2.4 KiB
TypeScript
import type { BasePayload } from 'payload'
|
|
|
|
import { describe, expect, test, vi } from 'vitest'
|
|
|
|
import { migrateCookieSettingsSaveButton } from '../src/globals/CookieSettings/migrateSaveButton.js'
|
|
import { getConsentTexts } from '../src/modules/consent/getConsentTexts.js'
|
|
|
|
function payloadWith(db: Record<string, unknown>, cookieSettings: Record<string, unknown> = {}) {
|
|
return {
|
|
db,
|
|
findGlobal: vi.fn(async () => cookieSettings),
|
|
logger: { error: vi.fn(), info: vi.fn(), warn: vi.fn() },
|
|
} as unknown as BasePayload
|
|
}
|
|
|
|
describe('Cookie Settings buttons.save → savePreferences (1.12.2)', () => {
|
|
test('MongoDB: copies the old value for every locale, only when the new field is missing', async () => {
|
|
const updateOne = vi.fn(async () => ({ modifiedCount: 1 }))
|
|
const payload = payloadWith({ name: 'mongoose', globals: { collection: { updateOne } } })
|
|
await migrateCookieSettingsSaveButton(payload)
|
|
expect(updateOne).toHaveBeenCalledWith(
|
|
{ 'buttons.save': { $exists: true }, 'buttons.savePreferences': { $exists: false }, globalType: 'cookie-settings' },
|
|
[{ $set: { 'buttons.savePreferences': '$buttons.save' } }],
|
|
)
|
|
expect(payload.logger.info).toHaveBeenCalled()
|
|
})
|
|
|
|
test('other adapters: nothing (the SQL migration renames the column)', async () => {
|
|
const updateOne = vi.fn()
|
|
await migrateCookieSettingsSaveButton(payloadWith({ name: 'sqlite', globals: { collection: { updateOne } } }))
|
|
expect(updateOne).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('a failing update is logged, start continues', async () => {
|
|
const payload = payloadWith({
|
|
name: 'mongoose',
|
|
globals: { collection: { updateOne: vi.fn(async () => { throw new Error('no rights') }) } },
|
|
})
|
|
await expect(migrateCookieSettingsSaveButton(payload)).resolves.toBeUndefined()
|
|
expect(payload.logger.error).toHaveBeenCalled()
|
|
})
|
|
|
|
test('getConsentTexts: old field as the raw locale map (Mongo, not in the schema) → this locale', async () => {
|
|
const payload = payloadWith({}, { buttons: { save: { de: 'Einstellungen speichern', pl: 'Zapisz ustawienia' } } })
|
|
const config = { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'PL' }, { code: 'de', label: 'DE' }] } as const
|
|
const texts = await getConsentTexts({ config, locale: 'de', payload, privacyPolicy: false })
|
|
expect(texts.buttons.save).toBe('Einstellungen speichern')
|
|
})
|
|
})
|