Files
ipal-kit/test/redirectDrafts.test.ts
Radosław SmolińskiandClaude Opus 5.5 0fd57c1d6a Opt-outs for the secure defaults; isPathVisibleIn in construction/logic
- setUnknownIpFactor (0 = old free pass), UNKNOWN_IP_FACTOR exported
- createContentHelpers({ settingsDepth }) and markdown/mcp isPathVisible overrides
- <RenderRichText safeLinks={false}>
- resolveRedirect({ draft: true }) for preview
- isPathVisibleIn(mode, path), pathOf, PathVisibility exported; page route uses it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-22 17:35:08 +02:00

31 lines
1.5 KiB
TypeScript

import type { BasePayload } from 'payload'
import { describe, expect, test, vi } from 'vitest'
import { resolveRedirect } from '../src/modules/content/resolveRedirect.js'
const config = { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'PL' }] } as const
const payloadWith = (doc: object) => ({ find: vi.fn(async () => ({ docs: [doc] })) }) as unknown as BasePayload
describe('old-slug redirects and drafts', () => {
test('a published page redirects from its old slug', async () => {
const payload = payloadWith({ slug: 'nowa-oferta', _status: 'published' })
expect(await resolveRedirect({ config, locale: 'pl', payload, segments: ['oferta'] })).toBe('/nowa-oferta')
})
test('a never-published draft does not redirect (its new slug stays private)', async () => {
const payload = payloadWith({ slug: 'tajny-projekt', _status: 'draft' })
expect(await resolveRedirect({ config, locale: 'pl', payload, segments: ['oferta'] })).toBeNull()
})
test('draft: true (preview) redirects drafts too', async () => {
const payload = payloadWith({ slug: 'tajny-projekt', _status: 'draft' })
expect(await resolveRedirect({ config, draft: true, locale: 'pl', payload, segments: ['oferta'] })).toBe('/tajny-projekt')
})
test('collections without drafts still redirect', async () => {
const payload = payloadWith({ slug: 'kontakt-2' })
expect(await resolveRedirect({ config, locale: 'pl', payload, segments: ['kontakt'] })).toBe('/kontakt-2')
})
})