Fixes from the reference site: 404 page unlisted, own-origin media, fillGlobal defaults, switcher docs
- sitemap, llms.txt and the site index leave out the page assigned as the 404 page (unlistedPageIds, exported); it stays when it is also the homepage - buildImagesConfig: in production with R2_PUBLIC_URL empty, allow the site's own /api/media/file/** so next/image no longer answers 400 - fillGlobal: a choice field (select, radio, checkbox, number, date) still at its defaultValue counts as empty; text is never overwritten - docs: LanguageSwitcher renderLabel needs a 'use client' wrapper (i18n.md, ipal-site, ipal-setup, api.md) Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d992d131a2
commit
3645e61f7d
@@ -79,6 +79,14 @@ describe('buildImagesConfig', () => {
|
||||
expect(config.dangerouslyAllowLocalIP).toBe(true)
|
||||
expect(buildImagesConfig({ production: false, serverUrl: 'https://staging.acme.pl' }).dangerouslyAllowLocalIP).toBeUndefined()
|
||||
})
|
||||
|
||||
test('production without R2 (the documented default): the site\'s own media are allowed', () => {
|
||||
const config = buildImagesConfig({ production: true, publicUrl: '', serverUrl: 'https://acme.pl' })
|
||||
expect(config.remotePatterns).toEqual([{ hostname: 'acme.pl', pathname: '/api/media/file/**', protocol: 'https' }])
|
||||
expect(config.dangerouslyAllowLocalIP).toBeUndefined()
|
||||
// A local production build (CI, `next start` on localhost) still never opens private IPs.
|
||||
expect(buildImagesConfig({ production: true, serverUrl: 'http://localhost:3000' }).dangerouslyAllowLocalIP).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildMediaPlaceholderHook', () => {
|
||||
|
||||
@@ -108,6 +108,14 @@ describe('createSeeder', () => {
|
||||
db: sqliteAdapter({ client: { url: 'file::memory:' }, push: true }),
|
||||
editor: lexicalEditor(),
|
||||
globals: [
|
||||
{
|
||||
slug: 'look',
|
||||
fields: [
|
||||
{ name: 'mode', type: 'select', defaultValue: 'light', options: ['light', 'dark', 'system'] },
|
||||
{ name: 'toggle', type: 'checkbox', defaultValue: true },
|
||||
{ name: 'greeting', type: 'text', defaultValue: 'Hello' },
|
||||
],
|
||||
},
|
||||
{
|
||||
slug: 'header',
|
||||
fields: [
|
||||
@@ -241,6 +249,19 @@ describe('createSeeder', () => {
|
||||
expect((await seeder().fillGlobal('header', { tagline: { pl: 'Inne' } })).status).toBe('skip (exists)')
|
||||
})
|
||||
|
||||
test('fillGlobal: a choice still at its default counts as unset; text is never overwritten', async () => {
|
||||
await payload.updateGlobal({ slug: 'look' as never, data: {} as never }) // first save stores the defaults
|
||||
const first = await seeder().fillGlobal('look', { greeting: 'Hi', mode: 'system', toggle: false })
|
||||
expect(first).toMatchObject({ status: 'create' })
|
||||
expect(first.note).toBe('empty fields filled: mode, toggle')
|
||||
const look = (await payload.findGlobal({ slug: 'look' as never })) as { greeting: string; mode: string; toggle: boolean }
|
||||
expect(look).toMatchObject({ greeting: 'Hello', mode: 'system', toggle: false })
|
||||
// An editor's choice that differs from the default stays.
|
||||
await payload.updateGlobal({ slug: 'look' as never, data: { mode: 'dark' } as never })
|
||||
await seeder().fillGlobal('look', { mode: 'system' })
|
||||
expect(((await payload.findGlobal({ slug: 'look' as never })) as { mode: string }).mode).toBe('dark')
|
||||
})
|
||||
|
||||
test('production guard: update refused on production or a non-local database unless IPAL_SEED_ALLOW_PROD_UPDATE=1', () => {
|
||||
vi.stubEnv('NODE_ENV', 'production')
|
||||
const only = ['pages:kontakt']
|
||||
|
||||
@@ -251,6 +251,33 @@ describe('sitemap route: split, cache, errors', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('system pages without a URL of their own', () => {
|
||||
const settings = { homepage: { id: 1, slug: { en: 'home', pl: 'start' } }, notFound: { id: 2, slug: { en: 'not-found-page', pl: 'nie-znaleziono' } } }
|
||||
const pages = [
|
||||
{ id: 1, slug: { en: 'home', pl: 'start' }, _status: 'published', title: 'Home' },
|
||||
{ id: 2, slug: { en: 'not-found-page', pl: 'nie-znaleziono' }, _status: 'published', title: 'Not found' },
|
||||
{ id: 3, slug: { en: 'contact', pl: 'kontakt' }, _status: 'published', title: 'Contact' },
|
||||
]
|
||||
|
||||
test('the assigned 404 page is left out of the sitemap, the site index and llms.txt', async () => {
|
||||
const payload = fakePayload({ pages })
|
||||
payload.findGlobal.mockResolvedValue(settings)
|
||||
const sitemap = await buildSitemapEntries({ baseUrl: 'https://acme.pl', config, payload: payload as never })
|
||||
expect(sitemap.map((e) => e.url)).toEqual(['https://acme.pl/pl', 'https://acme.pl/en', 'https://acme.pl/pl/kontakt', 'https://acme.pl/en/contact'])
|
||||
|
||||
const flat = fakePayload({ pages: pages.map((p) => ({ ...p, slug: p.slug.pl })) })
|
||||
flat.findGlobal.mockResolvedValue(settings)
|
||||
expect((await collectSiteIndex({ config: single, payload: flat as never })).map((e) => e.path)).toEqual(['/', '/kontakt'])
|
||||
expect(await buildLlmsTxt({ baseUrl: 'https://acme.pl', config: single, payload: flat as never })).not.toContain('nie-znaleziono')
|
||||
})
|
||||
|
||||
test('a 404 page that is also the homepage stays listed', async () => {
|
||||
const payload = fakePayload({ pages: pages.slice(0, 1) })
|
||||
payload.findGlobal.mockResolvedValue({ homepage: { id: 1 }, notFound: 1 })
|
||||
expect(await buildSitemapEntries({ baseUrl: 'https://acme.pl', config, payload: payload as never })).toHaveLength(2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('collectSiteIndex and llms.txt', () => {
|
||||
const pages = Array.from({ length: 1205 }, (_, i) => ({ id: i, slug: `p${i}`, title: `Page ${i}` }))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user