GEO / SEO
- collectSiteIndex: one list of public docs per locale (pages + archive
entries) on sitemap rules; llms.txt/llms-full and MCP list_pages now include
blog/content entries and every language. Fixes hard-coded "## Strony" heading
and homepage not collapsing to the locale root in llms.txt.
- Markdown frontmatter: canonical url + updated date.
- Metadata: X/Twitter card, OG image width/height/alt, og:type article with
published/modified times for entries.
- Fix: Site Settings "defaultShareImage" was never used — now the OG fallback.
- getPageJsonLd (createContentHelpers): WebPage/CollectionPage/BlogPosting,
BreadcrumbList from the real route, FAQPage via a project mapper.
- IndexNow (opt-in ipalKit({ indexNow: true })): submit published URLs in all
languages, key generated in Site Integrations or INDEXNOW_KEY, key route.
- sameAs profiles in Site Settings + sameAsUrls(); sitemap <image:image>.
From project reports
- Fix: package exports were missing ./env and ./fluid.css although the docs
import them (TS2307); regression test checks every documented subpath.
- Fix: plugins run before Payload adds its default users collection, so roles
and 2FA had nothing to attach to — ipalKit injects an auth collection when
the project has none (project's own one wins). Audit no longer errors on it.
- createMarkdownRoute, createSubmitAction (/server, headers injected).
- formatOpeningHours (PL/EN/DE text → schema.org), used by
buildLocalBusinessJsonLd, which also takes a schema.org `type`.
- buildNavigationJsonLd straight from the header global.
- buildCsp googleMaps: full Maps JS API domain set; values de-duplicated.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
177 lines
6.9 KiB
TypeScript
177 lines
6.9 KiB
TypeScript
/**
|
|
* End-to-end through a REAL Payload (SQLite in memory): plugin config → form
|
|
* built in the "panel" (Local API) → submitForm → stored submission. Catches
|
|
* what unit tests with a fake payload can't: schema, access control, hooks.
|
|
*/
|
|
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 { submitForm } from '../src/modules/forms/submitForm.js'
|
|
import { createContentHelpers } from '../src/modules/frontend/createContentHelpers.js'
|
|
import { ipalKit } from '../src/plugin.js'
|
|
|
|
vi.mock('server-only', () => ({}))
|
|
|
|
let payload: Payload
|
|
let configPromise: Parameters<typeof getPayload>[0]['config']
|
|
let formId: string
|
|
|
|
beforeAll(async () => {
|
|
const config = buildConfig({
|
|
collections: [
|
|
// Open sign-up, the risky setup the roles field guard exists for.
|
|
{ slug: 'users', access: { create: () => true }, auth: true, fields: [] },
|
|
{
|
|
slug: 'pages',
|
|
fields: [
|
|
{ name: 'title', type: 'text' },
|
|
{ name: 'slug', type: 'text', index: true, localized: true },
|
|
],
|
|
},
|
|
// SiteSettings' logo/favicon upload fields point here.
|
|
{ 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' },
|
|
forms: {},
|
|
i18n: { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }] },
|
|
twoFactor: false,
|
|
}),
|
|
],
|
|
secret: 'integration-test-secret',
|
|
telemetry: false,
|
|
})
|
|
configPromise = config
|
|
payload = await getPayload({ config })
|
|
|
|
const form = await payload.create({
|
|
collection: 'forms' as never,
|
|
data: {
|
|
confirmationMessage: {
|
|
root: {
|
|
type: 'root',
|
|
children: [
|
|
{
|
|
type: 'paragraph',
|
|
children: [{ type: 'text', detail: 0, format: 0, mode: 'normal', style: '', text: 'Dziękujemy', version: 1 }],
|
|
direction: null,
|
|
format: '',
|
|
indent: 0,
|
|
version: 1,
|
|
},
|
|
],
|
|
direction: null,
|
|
format: '',
|
|
indent: 0,
|
|
version: 1,
|
|
},
|
|
},
|
|
fields: [
|
|
{ name: 'name', blockType: 'text', label: 'Imię', required: true },
|
|
{ name: 'consent', blockType: 'checkbox', label: 'Zgoda' },
|
|
],
|
|
title: 'Kontakt',
|
|
} as never,
|
|
})
|
|
formId = String(form.id)
|
|
}, 60_000)
|
|
|
|
afterAll(async () => {
|
|
await payload?.destroy()
|
|
})
|
|
|
|
describe('forms against a real Payload', () => {
|
|
test('a valid submission is stored with only the form fields', async () => {
|
|
const result = await submitForm({ data: { name: 'Ala', consent: true }, formId, ip: '10.7.0.1', payload })
|
|
expect(result.success).toBe(true)
|
|
if (!result.success) {return}
|
|
|
|
const stored = (await payload.findByID({
|
|
id: result.submissionId,
|
|
collection: 'form-submissions' as never,
|
|
depth: 0,
|
|
})) as unknown as { form: number | string; submissionData: { field: string; value: string }[] }
|
|
expect(String(stored.form)).toBe(formId)
|
|
expect(stored.submissionData.map(({ field, value }) => ({ field, value }))).toEqual([
|
|
{ field: 'name', value: 'Ala' },
|
|
{ field: 'consent', value: 'true' },
|
|
])
|
|
})
|
|
|
|
test('the gates hold: consent, required, unknown keys', async () => {
|
|
const send = (data: Record<string, unknown>) => submitForm({ data, formId, ip: '10.7.0.2', maxPerMinute: 0, payload })
|
|
expect(await send({ name: 'Ala', consent: false })).toMatchObject({ reason: 'consent' })
|
|
expect(await send({ consent: true })).toMatchObject({ field: 'name', reason: 'validation' })
|
|
expect(await send({ name: 'Ala', consent: true, role: 'admin' })).toMatchObject({ kind: 'unknown_fields' })
|
|
})
|
|
|
|
test('REST/anonymous creation of submissions is closed (only submitForm writes)', async () => {
|
|
await expect(
|
|
payload.create({
|
|
collection: 'form-submissions' as never,
|
|
data: { form: formId, submissionData: [] } as never,
|
|
overrideAccess: false,
|
|
}),
|
|
).rejects.toThrow()
|
|
})
|
|
|
|
test('open sign-up cannot self-assign admin — roles fall back to the default', async () => {
|
|
const user = (await payload.create({
|
|
collection: 'users',
|
|
data: { email: '[email protected]', password: 'Passw0rd!x', roles: ['admin'] } as never,
|
|
overrideAccess: false,
|
|
})) as unknown as { roles: string[] }
|
|
expect(user.roles).toEqual(['user'])
|
|
})
|
|
|
|
test('seed / Local API with overrideAccess can still create an admin', async () => {
|
|
const admin = (await payload.create({
|
|
collection: 'users',
|
|
data: { email: '[email protected]', password: 'Passw0rd!x', roles: ['admin'] } as never,
|
|
})) as unknown as { roles: string[] }
|
|
expect(admin.roles).toEqual(['admin'])
|
|
})
|
|
})
|
|
|
|
describe('generatePageMetadata — markdownAlternate', () => {
|
|
const i18n = { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }] } as const
|
|
|
|
test('advertises the Markdown version of an indexable page', async () => {
|
|
await payload.create({ collection: 'pages' as never, data: { slug: 'o-nas', title: 'O nas' } as never })
|
|
const on = createContentHelpers({ baseUrl: 'https://acme.pl', config: configPromise, i18n, markdownAlternate: true })
|
|
const meta = await on.generatePageMetadata('pl', ['o-nas'])
|
|
expect(meta.alternates?.canonical).toBe('https://acme.pl/o-nas')
|
|
expect(meta.alternates?.types).toEqual({ 'text/markdown': '/md/o-nas' })
|
|
|
|
const off = createContentHelpers({ baseUrl: 'https://acme.pl', config: configPromise, i18n })
|
|
expect((await off.generatePageMetadata('pl', ['o-nas'])).alternates?.types).toBeUndefined()
|
|
})
|
|
})
|
|
|
|
describe('getPageJsonLd', () => {
|
|
const i18n = { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }] } as const
|
|
|
|
test('WebPage + breadcrumbs from the real route, FAQ when mapped, no @context per node', async () => {
|
|
await payload.create({ collection: 'pages' as never, data: { slug: 'kontakt', title: 'Kontakt' } as never })
|
|
const h = createContentHelpers({ baseUrl: 'https://acme.pl', config: configPromise, i18n })
|
|
const nodes = await h.getPageJsonLd('pl', ['kontakt'], {
|
|
faq: () => [{ answer: 'Tak.', question: 'Czy dojeżdżacie?' }, { answer: '', question: 'puste' }],
|
|
pageType: () => 'ContactPage',
|
|
})
|
|
expect(nodes.map((n) => n['@type'])).toEqual(['ContactPage', 'BreadcrumbList', 'FAQPage'])
|
|
expect(nodes[0]).toMatchObject({ name: 'Kontakt', '@id': 'https://acme.pl/kontakt', inLanguage: 'pl' })
|
|
expect(nodes.every((n) => !('@context' in n))).toBe(true)
|
|
expect((nodes[2] as { mainEntity: unknown[] }).mainEntity).toHaveLength(1)
|
|
expect(await h.getPageJsonLd('pl', ['nie-ma'])).toEqual([])
|
|
})
|
|
})
|