Add test infrastructure for hydrators using node:test
- Add docker-compose.test.yml with isolated PostgreSQL on port 5433 - Add environment variable support for database connection config - Add test setup utilities and initial user hydrator tests - Add test and test:watch scripts to package.json Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
44
express/framework/hydrators/tests/setup.ts
Normal file
44
express/framework/hydrators/tests/setup.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
// Test setup for hydrator tests
|
||||
// Run: DB_PORT=5433 DB_USER=diachron_test DB_PASSWORD=diachron_test DB_NAME=diachron_test npx tsx --test tests/*.test.ts
|
||||
|
||||
import { Pool } from "pg";
|
||||
import { connectionConfig, migrate } from "../../../database";
|
||||
|
||||
const pool = new Pool(connectionConfig);
|
||||
|
||||
export async function setupTestDatabase(): Promise<void> {
|
||||
await migrate();
|
||||
}
|
||||
|
||||
export async function cleanupTables(): Promise<void> {
|
||||
// Clean in reverse dependency order
|
||||
await pool.query("DELETE FROM user_emails");
|
||||
await pool.query("DELETE FROM users");
|
||||
}
|
||||
|
||||
export async function teardownTestDatabase(): Promise<void> {
|
||||
await pool.end();
|
||||
}
|
||||
|
||||
export async function insertTestUser(data: {
|
||||
id: string;
|
||||
displayName: string;
|
||||
status: string;
|
||||
email: string;
|
||||
}): Promise<void> {
|
||||
const emailId = crypto.randomUUID();
|
||||
const normalizedEmail = data.email.toLowerCase().trim();
|
||||
|
||||
await pool.query(
|
||||
`INSERT INTO users (id, display_name, status) VALUES ($1, $2, $3)`,
|
||||
[data.id, data.displayName, data.status],
|
||||
);
|
||||
|
||||
await pool.query(
|
||||
`INSERT INTO user_emails (id, user_id, email, normalized_email, is_primary)
|
||||
VALUES ($1, $2, $3, $4, true)`,
|
||||
[emailId, data.id, data.email, normalizedEmail],
|
||||
);
|
||||
}
|
||||
|
||||
export { pool };
|
||||
Reference in New Issue
Block a user