### What? 1. Adds logic to automatically update the `importMap.js` file with the project name provided by the user. 2. Adds an updated version of the `README.md` file that we had when this template existed outside of the monorepo ([here](https://github.com/payloadcms/plugin-template/blob/main/README.md)) to provide clear instructions of required steps. ### Why? 1. The plugin template when installed via `npx create-payload-app` asks the user for a project name, however the exports from `importMap.js` do not get updated to the provided name. This throws errors when running the project and prevents it from building. 2. The `/dev` folder requires the `.env.example` to be copied and renamed to `.env` - the project will not run until this is done. The template lacks instructions that this is a required step. ### How? 1. Updates `packages/create-payload-app/src/lib/configure-plugin-project.ts` to read the `importMap.js` file and replace the placeholder plugin name with the name provided by the users. Adds a test to `packages/create-payload-app/src/lib/create-project.spec.ts` to verify that this file gets updated correctly. 2. Adds instructions on using this template to the `README.md` file, ensuring key steps (like adding the `.env` file) are clearly stated. Additional housekeeping updates: - Removed Jest and replaced it with Vitest for testing - Updated the base test approach to use Vitest instead of Jest - Removed `NextRESTClient` in favor of directly creating Request objects - Abstracted `getCustomEndpointHandler` function - Added ensureIndexes: true to the mongooseAdapter configuration - Removed the custom server from the dev folder - Updated the pnpm dev script to "dev": "next dev dev --turbo" - Removed `admin.autoLogin` Fixes #12198
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import type { Payload } from 'payload'
|
|
|
|
import config from '@payload-config'
|
|
import { createPayloadRequest, getPayload } from 'payload'
|
|
import { afterAll, beforeAll, describe, expect, test } from 'vitest'
|
|
|
|
import { customEndpointHandler } from '../src/endpoints/customEndpointHandler.js'
|
|
|
|
let payload: Payload
|
|
|
|
afterAll(async () => {
|
|
if (payload.db.destroy) {
|
|
await payload.db.destroy()
|
|
}
|
|
})
|
|
|
|
beforeAll(async () => {
|
|
payload = await getPayload({ config })
|
|
})
|
|
|
|
describe('Plugin integration tests', () => {
|
|
test('should query custom endpoint added by plugin', async () => {
|
|
const request = new Request('http://localhost:3000/api/my-plugin-endpoint', {
|
|
method: 'GET',
|
|
})
|
|
|
|
const payloadRequest = await createPayloadRequest({ config, request })
|
|
const response = await customEndpointHandler(payloadRequest)
|
|
expect(response.status).toBe(200)
|
|
|
|
const data = await response.json()
|
|
expect(data).toMatchObject({
|
|
message: 'Hello from custom endpoint',
|
|
})
|
|
})
|
|
|
|
test('can create post with custom text field added by plugin', async () => {
|
|
const post = await payload.create({
|
|
collection: 'posts',
|
|
data: {
|
|
addedByPlugin: 'added by plugin',
|
|
},
|
|
})
|
|
expect(post.addedByPlugin).toBe('added by plugin')
|
|
})
|
|
|
|
test('plugin creates and seeds plugin-collection', async () => {
|
|
expect(payload.collections['plugin-collection']).toBeDefined()
|
|
|
|
const { docs } = await payload.find({ collection: 'plugin-collection' })
|
|
|
|
expect(docs).toHaveLength(1)
|
|
})
|
|
})
|