26 lines
1.2 KiB
TypeScript
26 lines
1.2 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' }] }
|
|
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({ _status: 'published', slug: 'nowa-oferta' })
|
|
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({ _status: 'draft', slug: 'tajny-projekt' })
|
|
expect(await resolveRedirect({ config, locale: 'pl', payload, segments: ['oferta'] })).toBeNull()
|
|
})
|
|
|
|
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')
|
|
})
|
|
})
|