Local dev and the test suite previously defaulted to the live production Neon database, and running the tests mutated prod data. Add guardrails plus a proper local Postgres + migrations workflow so production can't be hit by mistake: - docker-compose: local Postgres 17 (matches prod) + auto-created teqo_test - dev guard refuses a non-local DATABASE_URL; tests refuse non-_test databases - .env.test isolates the suite; vitest/playwright load it and fail closed - Payload migrations set up (push disabled); build runs `payload migrate`, so deploys apply pending migrations to prod automatically - baseline `initial` migration + idempotent consent.text varchar->jsonb fix - `pnpm db:pull` copies prod content locally, excluding supporter PII - docs (README, AGENTS.md) + agent skills for the local-db/migration workflow
50 lines
1 KiB
TypeScript
50 lines
1 KiB
TypeScript
import { getPayload } from 'payload'
|
|
import config from '../../src/payload.config.js'
|
|
|
|
import { assertTestDatabase } from './assertTestDatabase'
|
|
|
|
export const testUser = {
|
|
email: 'dev@payloadcms.com',
|
|
password: 'test',
|
|
}
|
|
|
|
/**
|
|
* Seeds a test user for e2e admin tests.
|
|
*/
|
|
export async function seedTestUser(): Promise<void> {
|
|
assertTestDatabase(process.env.DATABASE_URL)
|
|
const payload = await getPayload({ config })
|
|
|
|
// Delete existing test user if any
|
|
await payload.delete({
|
|
collection: 'users',
|
|
where: {
|
|
email: {
|
|
equals: testUser.email,
|
|
},
|
|
},
|
|
})
|
|
|
|
// Create fresh test user
|
|
await payload.create({
|
|
collection: 'users',
|
|
data: testUser,
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Cleans up test user after tests
|
|
*/
|
|
export async function cleanupTestUser(): Promise<void> {
|
|
assertTestDatabase(process.env.DATABASE_URL)
|
|
const payload = await getPayload({ config })
|
|
|
|
await payload.delete({
|
|
collection: 'users',
|
|
where: {
|
|
email: {
|
|
equals: testUser.email,
|
|
},
|
|
},
|
|
})
|
|
}
|