Files
payloadcms/test/auth/custom-strategy/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

61 lines
1.4 KiB
TypeScript

import type { Payload } from 'payload'
import path from 'path'
import { fileURLToPath } from 'url'
import type { NextRESTClient } from '../../helpers/NextRESTClient.js'
import { initPayloadInt } from '../../helpers/initPayloadInt.js'
import { usersSlug } from './shared.js'
let payload: Payload
let restClient: NextRESTClient
const [code, secret, name] = ['test', 'strategy', 'Tester']
const headers = {
'Content-Type': 'application/json',
}
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
describe('AuthStrategies', () => {
beforeAll(async () => {
;({ payload, restClient } = await initPayloadInt(dirname, 'auth/custom-strategy'))
})
afterAll(async () => {
await payload.destroy()
})
describe('create user', () => {
beforeAll(async () => {
await restClient.POST(`/${usersSlug}`, {
body: JSON.stringify({
name,
code,
secret,
}),
headers,
})
})
it('should return a logged in user from /me', async () => {
const response = await restClient.GET(`/${usersSlug}/me`, {
headers: {
code,
secret,
},
})
const data = await response.json()
// Expect that the auth strategy should be able to return headers
expect(response.headers.has('Smile-For-Me')).toBeTruthy()
expect(response.status).toBe(200)
expect(data.user.name).toBe(name)
})
})
})