import { mongooseAdapter } from '@payloadcms/db-mongodb' import { postgresAdapter } from '@payloadcms/db-postgres' import { sqliteAdapter } from '@payloadcms/db-sqlite' /** * The database of the HTTP security tests. SQLite in memory by default; `IPAL_TEST_POSTGRES_URI` points them at a * real Postgres (numeric ids, like SQLite — the adapters where an id of one auth collection can equal an id of * another): * docker run -d --rm -p 127.0.0.1:55432:5432 -e POSTGRES_PASSWORD=test postgres:17 * IPAL_TEST_POSTGRES_URI=postgres://postgres:test@127.0.0.1:55432/postgres pnpm vitest run test/securityHttp.test.ts * `IPAL_TEST_MONGO_URI` points them at MongoDB (what the client sites run): * docker run -d --rm -p 127.0.0.1:27217:27017 mongo:7 * IPAL_TEST_MONGO_URI=mongodb://127.0.0.1:27217 pnpm vitest run test/securityHttp.test.ts * Each test file gets its own schema / database (`name`), so the files can run one after another against one server. */ /** True on the adapters where ids are numbers counted per collection (an id can repeat across collections). */ export const numericIds = () => !process.env.IPAL_TEST_MONGO_URI export function testDatabase(name: string) { const mongo = process.env.IPAL_TEST_MONGO_URI if (mongo) {return mongooseAdapter({ url: `${mongo.replace(/\/$/, '')}/${name}_${Date.now()}` })} const uri = process.env.IPAL_TEST_POSTGRES_URI if (uri) {return postgresAdapter({ pool: { connectionString: uri }, push: true, schemaName: `${name}_${Date.now()}` })} return sqliteAdapter({ client: { url: 'file::memory:' }, push: true }) }