Files
payloadcms/test/auth/custom-strategy/int.spec.ts
Dan Ribbens d193c677c7 chore: attach mongoMemoryServer to db and destroy in tests (#5326)
* chore: attach mongoMemoryServer to db and destroy in tests

* bump mongodb-memory-server to 9.x

---------

Co-authored-by: Paul Popus <paul@nouance.io>
2024-03-14 15:41:20 -04:00

57 lines
1.4 KiB
TypeScript

import type { Payload } from '../../../packages/payload/src/index.js'
import { getPayload } from '../../../packages/payload/src/index.js'
import { NextRESTClient } from '../../helpers/NextRESTClient.js'
import { startMemoryDB } from '../../startMemoryDB.js'
import configPromise from './config.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',
}
describe('AuthStrategies', () => {
beforeAll(async () => {
const config = await startMemoryDB(configPromise)
payload = await getPayload({ config })
restClient = new NextRESTClient(payload.config)
})
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.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(response.status).toBe(200)
expect(data.user.name).toBe(name)
})
})
})