feat: correctly subs out ability to boot REST API within same process

This commit is contained in:
Jarrod Flesch
2024-02-01 14:07:13 -05:00
parent e96c7bf987
commit 24feace60b
16 changed files with 2551 additions and 2714 deletions

View File

@@ -1,9 +1,9 @@
import { GraphQLClient } from 'graphql-request'
import jwtDecode from 'jwt-decode'
import type { Payload } from '../../packages/payload/src'
import type { User } from '../../packages/payload/src/auth'
import payload from '../../packages/payload/src'
import configPromise from '../collections-graphql/config'
import { devUser } from '../credentials'
import { initPayloadTest } from '../helpers/configHelpers'
@@ -13,6 +13,7 @@ require('isomorphic-fetch')
let apiUrl
let client: GraphQLClient
let payload: Payload
const headers = {
'Content-Type': 'application/json',
@@ -22,7 +23,11 @@ const { email, password } = devUser
describe('Auth', () => {
beforeAll(async () => {
const { serverURL } = await initPayloadTest({ __dirname, init: { local: false } })
const { serverURL, payload: payloadClient } = await initPayloadTest({
__dirname,
init: { local: false },
})
payload = payloadClient
apiUrl = `${serverURL}/api`
const config = await configPromise
const url = `${serverURL}${config.routes.api}${config.routes.graphQL}`
@@ -653,6 +658,14 @@ describe('Auth', () => {
})
})
describe('REST API', () => {
it('should respond from route handlers', async () => {
const test = await fetch(`${apiUrl}/api/test`)
expect(test.status).toStrictEqual(200)
})
})
describe('API Key', () => {
it('should authenticate via the correct API key user', async () => {
const usersQuery = await payload.find({