feat: testing with real database
Some checks failed
TrafficCue Server CI / check (push) Failing after 21s
Some checks failed
TrafficCue Server CI / check (push) Failing after 21s
This commit is contained in:
@ -16,12 +16,13 @@ process.env.REVIEWS_ENABLED = "true";
|
|||||||
const app = await import("../src/main").then(m => m.default);
|
const app = await import("../src/main").then(m => m.default);
|
||||||
|
|
||||||
const PGSQL_IMAGE = "postgres:latest";
|
const PGSQL_IMAGE = "postgres:latest";
|
||||||
let postgresContainer: StartedTestContainer;
|
let postgresContainer: StartedTestContainer | null = null;
|
||||||
let jwk: JWK;
|
let jwk: JWK;
|
||||||
let privateKey: string;
|
let privateKey: string;
|
||||||
|
|
||||||
// Spin up a temporary Postgres container for testing
|
// Spin up a temporary Postgres container for testing
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
if(!process.env.DATABASE_URL) {
|
||||||
postgresContainer = await new GenericContainer(PGSQL_IMAGE)
|
postgresContainer = await new GenericContainer(PGSQL_IMAGE)
|
||||||
.withEnvironment({
|
.withEnvironment({
|
||||||
POSTGRES_USER: "tc",
|
POSTGRES_USER: "tc",
|
||||||
@ -39,13 +40,18 @@ beforeAll(async () => {
|
|||||||
.start();
|
.start();
|
||||||
|
|
||||||
process.env.DATABASE_URL = `postgres://tc:tc@localhost:${postgresContainer.getMappedPort(5432)}/tc`;
|
process.env.DATABASE_URL = `postgres://tc:tc@localhost:${postgresContainer.getMappedPort(5432)}/tc`;
|
||||||
|
}
|
||||||
|
|
||||||
getDb(true);
|
getDb(true);
|
||||||
await initDb();
|
await initDb();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await postgresContainer.stop();
|
// Nuke the entire database after tests
|
||||||
|
const db = getDb();
|
||||||
|
await db.dropDatabase();
|
||||||
|
await db.destroy();
|
||||||
|
if(postgresContainer) await postgresContainer.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Override JWKS URL to prevent external calls during tests
|
// Override JWKS URL to prevent external calls during tests
|
||||||
|
|||||||
Reference in New Issue
Block a user