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
76 lines
1.8 KiB
TypeScript
76 lines
1.8 KiB
TypeScript
import type { Payload } from 'payload'
|
|
|
|
import path from 'path'
|
|
import { fileURLToPath } from 'url'
|
|
|
|
import type { NextRESTClient } from '../helpers/NextRESTClient.js'
|
|
|
|
import { devUser } from '../credentials.js'
|
|
import { initPayloadInt } from '../helpers/initPayloadInt.js'
|
|
import { postsSlug } from './collections/Posts/index.js'
|
|
|
|
let payload: Payload
|
|
let token: string
|
|
let restClient: NextRESTClient
|
|
|
|
const { email, password } = devUser
|
|
const filename = fileURLToPath(import.meta.url)
|
|
const dirname = path.dirname(filename)
|
|
|
|
describe('_Community Tests', () => {
|
|
// --__--__--__--__--__--__--__--__--__
|
|
// Boilerplate test setup/teardown
|
|
// --__--__--__--__--__--__--__--__--__
|
|
beforeAll(async () => {
|
|
const initialized = await initPayloadInt(dirname)
|
|
;({ payload, restClient } = initialized)
|
|
|
|
const data = await restClient
|
|
.POST('/users/login', {
|
|
body: JSON.stringify({
|
|
email,
|
|
password,
|
|
}),
|
|
})
|
|
.then((res) => res.json())
|
|
|
|
token = data.token
|
|
})
|
|
|
|
afterAll(async () => {
|
|
await payload.destroy()
|
|
})
|
|
|
|
// --__--__--__--__--__--__--__--__--__
|
|
// You can run tests against the local API or the REST API
|
|
// use the tests below as a guide
|
|
// --__--__--__--__--__--__--__--__--__
|
|
|
|
it('local API example', async () => {
|
|
const newPost = await payload.create({
|
|
collection: postsSlug,
|
|
data: {
|
|
title: 'LOCAL API EXAMPLE',
|
|
},
|
|
context: {},
|
|
})
|
|
|
|
expect(newPost.title).toEqual('LOCAL API EXAMPLE')
|
|
})
|
|
|
|
it('rest API example', async () => {
|
|
const data = await restClient
|
|
.POST(`/${postsSlug}`, {
|
|
body: JSON.stringify({
|
|
title: 'REST API EXAMPLE',
|
|
}),
|
|
headers: {
|
|
Authorization: `JWT ${token}`,
|
|
},
|
|
})
|
|
.then((res) => res.json())
|
|
|
|
expect(data.doc.title).toEqual('REST API EXAMPLE')
|
|
})
|
|
})
|