apps/api gains Prisma (instance_settings as the first model) with the initial migration applied automatically at startup via prisma migrate deploy, a lazy-connecting PrismaService, and GET /api/v1/readyz reporting named checks (database reachable, migrations applied) with 200/503. DATABASE_URL joins the validated environment schema; MIGRATE_ON_START=false skips deploys for tests and tooling. An idempotent seed script and a Compose dev overlay with PostgreSQL (host port 5434 — 5433 is taken locally) complete the loop. Closes #3 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
29 lines
962 B
TypeScript
29 lines
962 B
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { apiEnvSchema, parseEnv } from './env';
|
|
|
|
const MINIMAL_ENV = { DATABASE_URL: 'postgresql://user:pass@localhost:5432/db' };
|
|
|
|
describe('parseEnv', () => {
|
|
it('applies defaults for a minimal environment', () => {
|
|
const env = parseEnv(apiEnvSchema, MINIMAL_ENV);
|
|
expect(env.PORT).toBe(3000);
|
|
expect(env.NODE_ENV).toBe('development');
|
|
expect(env.MIGRATE_ON_START).toBe(true);
|
|
});
|
|
|
|
it('requires DATABASE_URL', () => {
|
|
expect(() => parseEnv(apiEnvSchema, {})).toThrowError(/DATABASE_URL/);
|
|
});
|
|
|
|
it('rejects non-postgres connection strings', () => {
|
|
expect(() => parseEnv(apiEnvSchema, { DATABASE_URL: 'mysql://x' })).toThrowError(/postgresql/);
|
|
});
|
|
|
|
it('fails with a message naming every invalid variable', () => {
|
|
expect(() =>
|
|
parseEnv(apiEnvSchema, { ...MINIMAL_ENV, PORT: 'not-a-port', LOG_LEVEL: 'loud' }),
|
|
).toThrowError(/PORT.*\n.*LOG_LEVEL/s);
|
|
});
|
|
});
|