test(api): Infra (health/db/schema/seed/env/migrate) — fill gaps + lifecycle test
Drives all infra src files to 100% (env.ts, db/client.ts, db/ensure-dir.ts, db/migrate.ts, db/seed.ts, routes/health.ts). - env.test.ts: dev defaults when unset, overrides when set (PORT coerced), CORS_ORIGINS parsing (trim + drop empties) and empty-fallback. - db.test.ts: runMigrations idempotency; ensureDbDir no-op for non-file URLs and bare filenames (branch coverage). - seed.test.ts: production guard — no dev users seeded when NODE_ENV=production. - c8-ignore the migrate.ts/seed.ts CLI direct-run blocks (unreachable under vitest). No lifecycle test (infra domain, per plan). No bugs found — infra code correct; only coverage gaps. All 112 API tests green; typecheck + oxlint clean.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { db } from '../src/db/client';
|
||||
import { user } from '../src/db/schema';
|
||||
import { runMigrations } from '../src/db/migrate';
|
||||
import { ensureDbDir } from '../src/db/ensure-dir';
|
||||
|
||||
describe('database', () => {
|
||||
it('can query the migrated user table (empty)', async () => {
|
||||
@@ -8,3 +10,21 @@ describe('database', () => {
|
||||
expect(rows).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('runMigrations', () => {
|
||||
it('is idempotent — running again on an already-migrated DB does not throw', async () => {
|
||||
// setup.ts already migrated the test DB once; re-running must be a no-op.
|
||||
await expect(runMigrations()).resolves.toBeUndefined();
|
||||
await expect(runMigrations()).resolves.toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('ensureDbDir', () => {
|
||||
it('is a no-op for a non-file: URL', () => {
|
||||
expect(() => ensureDbDir('libsql://remote.example')).not.toThrow();
|
||||
});
|
||||
|
||||
it('does not create a directory for a bare filename in the current dir', () => {
|
||||
expect(() => ensureDbDir('file:app.db')).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user