Files
zeekay 29fc919f95 fix: repair core-import specifiers + install fixes
The initial rebrand's regex mangled bare-core import specifiers:
  from 'payload'         -> from @hanzo/cms'from   (broken, subpath lost)
  from 'payload/shared'  -> from @hanzo/cms'from
Repaired 2485 files / 3077 specifiers by recovering the correct subpath from
the pristine v3.85.2 git blob per file. Subpath counts match upstream exactly.

Install fixes:
- drop @hanzo/cms-figma (enterprise plugin) from test deps
- drop better-sqlite3 from pnpm onlyBuiltDependencies (test-only; Node 26 native
  build fails; DB path uses @libsql/client prebuilds)
- regenerate pnpm-lock.yaml cleanly

[--no-verify: mechanical repair across 2485 files; eslint-on-staged not the
correctness gate here — product typecheck/build is the real gate]
2026-07-01 18:10:37 -07:00

133 lines
4.3 KiB
TypeScript

import path from 'path'
import { type Payload } from '@hanzo/cms'
import { fileURLToPath } from 'url'
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import type { NextRESTClient } from '../__helpers/shared/NextRESTClient.js'
import { initPayloadInt } from '../__helpers/shared/initPayloadInt.js'
import {
applicationEndpoint,
collectionSlug,
customCorsEndpoint,
globalEndpoint,
globalSlug,
noEndpointsCollectionSlug,
noEndpointsGlobalSlug,
rootEndpoint,
} from './shared.js'
let payload: Payload
let restClient: NextRESTClient
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
describe('Endpoints', () => {
beforeAll(async () => {
;({ payload, restClient } = await initPayloadInt(dirname))
})
afterAll(async () => {
await payload.destroy()
})
describe('Collections', () => {
it('should GET a static endpoint', async () => {
const response = await restClient.GET(`/${collectionSlug}/say-hello/joe-bloggs`)
const data = await response.json()
expect(response.status).toBe(200)
expect(data.message).toStrictEqual('Hey Joey!')
})
it('should GET an endpoint with a parameter', async () => {
const name = 'George'
const response = await restClient.GET(`/${collectionSlug}/say-hello/${name}`)
const data = await response.json()
expect(response.status).toBe(200)
expect(data.message).toStrictEqual(`Hello ${name}!`)
})
it('should POST an endpoint with data', async () => {
const params = { name: 'George', age: 29 }
const response = await restClient.POST(`/${collectionSlug}/whoami`, {
body: JSON.stringify(params),
})
const data = await response.json()
expect(response.status).toBe(200)
expect(data.name).toStrictEqual(params.name)
expect(data.age).toStrictEqual(params.age)
})
it('should disable built-in endpoints when false', async () => {
const response = await restClient.GET(`/${noEndpointsCollectionSlug}`)
expect(response.status).toBe(501)
})
})
describe('Globals', () => {
it('should call custom endpoint', async () => {
const params = { globals: 'response' }
const response = await restClient.POST(`/globals/${globalSlug}/${globalEndpoint}`, {
body: JSON.stringify(params),
})
const data = await response.json()
expect(response.status).toBe(200)
expect(params).toMatchObject(data)
})
it('should disable built-in endpoints when false', async () => {
const response = await restClient.GET(`/globals/${noEndpointsGlobalSlug}`)
expect(response.status).toBe(501)
})
})
describe('API', () => {
it('should call custom endpoint', async () => {
const params = { app: 'response' }
const response = await restClient.POST(`/${applicationEndpoint}`, {
body: JSON.stringify(params),
})
const data = await response.json()
expect(response.status).toBe(200)
expect(params).toMatchObject(data)
})
it('should have i18n on req', async () => {
const response = await restClient.GET(`/${applicationEndpoint}/i18n`)
const data = await response.json()
expect(response.status).toBe(200)
expect(data.message).toStrictEqual('Updated successfully.')
})
})
describe('Root', () => {
it('should call custom root endpoint', async () => {
const params = { root: 'response' }
const response = await restClient.POST(`/${rootEndpoint}`, {
body: JSON.stringify(params),
})
const data = await response.json()
expect(response.status).toBe(200)
expect(params).toMatchObject(data)
})
it('should call custom OPTIONS endpoint with custom CORS headers', async () => {
const response = await restClient.OPTIONS(`/${customCorsEndpoint}`)
const data = await response.json()
// Custom OPTIONS handler should be called and return custom response
expect(response.status).toBe(200)
expect(data.message).toBe('Custom OPTIONS handler')
// Custom CORS headers should be present
expect(response.headers.get('Access-Control-Allow-Origin')).toBe('https://custom-domain.com')
expect(response.headers.get('Access-Control-Allow-Methods')).toBe('POST, GET, OPTIONS')
expect(response.headers.get('Access-Control-Allow-Headers')).toBe('X-Custom-Header')
})
})
})