Files
payloadcms/test/plugin-redirects/int.spec.ts
Alessio Gravili 7c05c775cb docs: improve jobs autorun docs, adds e2e test (#12196)
This clarifies that jobs.autoRun only *runs* already-queued jobs. It does not queue the jobs for you.

Also adds an e2e test as this functionality had no e2e coverage
2025-06-05 09:19:19 -07:00

82 lines
1.8 KiB
TypeScript

import type { Payload } from 'payload'
import path from 'path'
import { fileURLToPath } from 'url'
import type { Page } from './payload-types.js'
import { initPayloadInt } from '../helpers/initPayloadInt.js'
import { pagesSlug } from './shared.js'
let payload: Payload
let page: Page
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
describe('@payloadcms/plugin-redirects', () => {
beforeAll(async () => {
;({ payload } = await initPayloadInt(dirname))
page = await payload.create({
collection: 'pages',
data: {
title: 'Test',
},
})
})
afterAll(async () => {
await payload.destroy()
})
it('should add a redirects collection', async () => {
const redirect = await payload.find({
collection: 'redirects',
depth: 0,
limit: 1,
})
expect(redirect).toBeTruthy()
})
it('should add a redirect with to internal page', async () => {
const redirect = await payload.create({
collection: 'redirects',
data: {
from: '/test',
to: {
type: 'reference',
reference: {
relationTo: pagesSlug,
value: page.id,
},
},
type: '301',
},
})
expect(redirect).toBeTruthy()
expect(redirect.from).toBe('/test')
expect(redirect.to.reference.value).toMatchObject(page)
})
it('should add a redirect with to custom url', async () => {
const redirect = await payload.create({
collection: 'redirects',
data: {
from: '/test2',
to: {
type: 'custom',
url: '/test',
},
type: '301',
},
})
expect(redirect).toBeTruthy()
expect(redirect.from).toBe('/test2')
expect(redirect.to.url).toBe('/test')
})
})