Files
ipal-kit/test/revalidateGlobals.test.ts
Radosław SmolińskiandClaude Fable 5.2 0a4f001797 IAPL rename, scripted: preferred names in src, bin, scripts, services, tests; bin files and skill folders moved
Replaced by an explicit list of forms only (ten exported names, runtime env names, project file
names and marks, commands, skill names, the log prefix, the brand in prose). Package name, import
paths, routes, CSS tokens, data attributes, custom keys, context flags, the cookie and kv keys are
not touched. package.json keeps the five old bin names beside the five new ones.
The old names stop working in this commit and come back as aliases in the next; docs follow.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-25 17:24:21 +01:00

35 lines
1.5 KiB
TypeScript

import type { Config, GlobalConfig } from 'payload'
import { afterEach, describe, expect, test, vi } from 'vitest'
import { buildGlobalRevalidateHook } from '../src/modules/hooks/buildRevalidateHook.js'
import { iapl } from '../src/plugin.js'
const i18n = { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }] } as const
const run = (g: GlobalConfig | undefined, context: object = {}) =>
g?.hooks?.afterChange?.forEach((h) => h({ context, doc: {}, global: g, previousDoc: {}, req: {} } as never))
describe('globals revalidate the site layout on save', () => {
afterEach(() => vi.unstubAllEnvs())
test('iapl({ revalidatePath }) wires every plugin global', async () => {
vi.stubEnv('NEXT_RUNTIME', 'nodejs')
const revalidatePath = vi.fn()
const config = await iapl({ i18n, revalidatePath, twoFactor: false })({ collections: [], secret: 'x' } as unknown as Config)
for (const slug of ['site-settings', 'site-integrations', 'cookie-settings', 'notifications']) {
revalidatePath.mockClear()
run(config.globals?.find((g) => g.slug === slug))
expect(revalidatePath, slug).toHaveBeenCalledWith('/', 'layout')
}
})
test('outside a Next server, or with disableRevalidate, nothing happens', () => {
const revalidatePath = vi.fn()
const hook = buildGlobalRevalidateHook({ revalidatePath })
hook({ context: {}, doc: {} } as never)
vi.stubEnv('NEXT_RUNTIME', 'nodejs')
hook({ context: { disableRevalidate: true }, doc: {} } as never)
expect(revalidatePath).not.toHaveBeenCalled()
})
})