Files
ipal-kit/test/env.test.ts
T
Radosław SmolińskiandClaude Opus 5.5 f809526f1d Page-filled form fields, links to entries, entry JSON-LD, R2-optional dev
Forms: `values` on RenderForm / BuilderForm / useBuilderForm fills fields the
page knows (chosen product variant, category) — read-only <output>, in the
SSR HTML, sent and validated like any field. prepareBuilderForm (/rsc) is the
server half of RenderForm for client components whose values change in the
browser; publicForm is exported so projects stop copying it.

Links: buildLinkField({ relationTo: ['pages', 'categories', …] }) — a
polymorphic relation; resolveLinkHref builds /{locale}/{archive}/{entry} from
`archives`, which getLinkOptions in createContentHelpers fills from Site
Settings.

SEO: pageJsonLd.entries — the main JSON-LD node per content collection
instead of BlogPosting; buildProductJsonLd emits an Offer only for a real
price from the panel.

Pages: createPageRoute / createNotFoundPage pass isFirst to blocks, so the
first section carries the page's only h1.

Fixes: ipalEnvRules({ storage: true }) requires R2_* in production only
(development: optional, all or none); buildImagesConfig allows the app's own
media on localhost outside production.

Docs, CHANGELOG, PROGRAMISTA §6 (34–37), ipal-form and ipal-upgrade skills.
Tests: builderForm, links, drafts (entries + archives), seo, media, env.

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

37 lines
1.3 KiB
TypeScript

import { afterEach, describe, expect, test, vi } from 'vitest'
import { assertEnv } from '../src/modules/env/assertEnv.js'
import { ipalEnvRules } from '../src/modules/env/ipalEnvRules.js'
const base = { DATABASE_URI: 'mongodb://db/x', NEXT_PUBLIC_SERVER_URL: 'http://localhost:3000', PAYLOAD_SECRET: 's' }
const r2 = {
R2_ACCESS_KEY_ID: 'k',
R2_BUCKET: 'b',
R2_ENDPOINT: 'https://acc.r2.cloudflarestorage.com',
R2_PUBLIC_URL: 'https://media.acme.pl',
R2_SECRET_ACCESS_KEY: 's',
}
function check(env: Record<string, string>) {
vi.unstubAllEnvs()
for (const [k, v] of Object.entries(env)) {vi.stubEnv(k, v)}
return () => assertEnv(ipalEnvRules({ storage: true }), { env })
}
afterEach(() => vi.unstubAllEnvs())
describe('ipalEnvRules({ storage })', () => {
test('production: every R2_* is required', () => {
expect(check({ ...base, NODE_ENV: 'production' })).toThrow(/R2_BUCKET is required/)
expect(check({ ...base, ...r2, NODE_ENV: 'production' })).not.toThrow()
})
test('development: no R2 at all is fine (local disk)', () => {
expect(check({ ...base, NODE_ENV: 'development' })).not.toThrow()
})
test('development: a partial R2 set is an error (all or nothing)', () => {
expect(check({ ...base, NODE_ENV: 'development', R2_BUCKET: 'b' })).toThrow(/R2_ACCESS_KEY_ID is required/)
})
})