Files
ipal-kit/test/plugin.test.ts
T
radoslaw.smolinskiandClaude Opus 5.5 ab854ef37a MCP site tools, Turnstile key alert, required 2FA injection, a11y, more tests
- MCP: new get_site_info and list_pages tools (public by design, published
  and indexable content only); search results collapse the homepage to root.
  New listContent() helper shared with searchContent.
- Dashboard alert when Turnstile is half-configured (it is silently off then).
- twoFactor.plugin is now required; the dynamic-import fallback (which never
  worked under Next and caused a Turbopack warning) is gone.
- a11y: cookie category checkboxes are labelled, buttons have type, test-email
  input is labelled; tab labels keep localized collection labels.
- IPAL_IP_HEADER: one-time production warning when unset, opt-in
  ipalEnvRules({ ipHeader: true }).
- Tests: SEO/robots/sitemap/hreflang, CSP, Markdown, consent, MCP, and a real
  Payload + SQLite integration test for forms and the roles guard (74 total).
- Drop unused mongodb-memory-server; dev .env.example for SQLite.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-16 01:15:19 +02:00

57 lines
2.0 KiB
TypeScript

import type { Config } from 'payload'
import { describe, expect, test, vi } from 'vitest'
import type { I18nConfig } from '../src/modules/i18n/types.js'
import { ipalKit } from '../src/plugin.js'
const i18n: I18nConfig = {
defaultLocale: 'pl',
locales: [
{ code: 'pl', label: 'Polski' },
{ code: 'en', label: 'English' },
],
}
const base = (): Config =>
({
collections: [{ slug: 'users', auth: true, fields: [] }],
secret: 'test',
}) as unknown as Config
describe('ipalKit — config transform', () => {
test('adds globals, endpoint, localization and roles', async () => {
const config = await ipalKit({ access: { authCollection: 'users' }, i18n, twoFactor: false })(base())
expect(config.globals?.map((g) => g.slug)).toEqual(
expect.arrayContaining(['site-settings', 'site-integrations']),
)
expect(config.endpoints?.some((e) => e.path === '/ipal/test-email')).toBe(true)
expect(config.localization && config.localization.defaultLocale).toBe('pl')
const users = config.collections?.find((c) => c.slug === 'users')
expect(users?.fields.some((f) => 'name' in f && f.name === 'roles')).toBe(true)
})
test('enforces 2FA unless explicitly disabled', async () => {
await expect(ipalKit({ i18n } as never)(base())).rejects.toThrow(/twoFactor\.issuer is required/)
await expect(ipalKit({ i18n, twoFactor: { issuer: 'Acme' } } as never)(base())).rejects.toThrow(
/no 2FA plugin was injected/,
)
const totp = vi.fn(() => (c: Config) => c)
await ipalKit({ i18n, twoFactor: { issuer: 'Acme', plugin: totp as never } })(base())
expect(totp).toHaveBeenCalledWith(expect.objectContaining({ forceSetup: true, totp: { issuer: 'Acme' } }))
})
test('enabled: false leaves the config untouched', async () => {
const config = base()
expect(await ipalKit({ enabled: false, i18n, twoFactor: false })(config)).toBe(config)
})
test('invalid i18n fails fast', () => {
expect(() => ipalKit({ i18n: { defaultLocale: 'de', locales: i18n.locales }, twoFactor: false })).toThrow()
})
})