Update paths in sync.sh, master/main.go, and CLAUDE.md to reflect the directory rename. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
// 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 };
|