Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 07b6f1e347 | |||
| c5018d9ced | |||
| 367b0b2357 | |||
| e0ac451372 | |||
| ae5d5b64ac | |||
| 7be13737d5 | |||
| 32052ab1c9 | |||
| ce807391c6 | |||
| 182342aab0 | |||
| d32758b310 | |||
| f26b2b044f | |||
| af2562ef2b | |||
| f739f94403 | |||
| f66de20dad |
+21
-25
@@ -20,27 +20,15 @@ jobs:
|
||||
with:
|
||||
deno-version: v2.x
|
||||
|
||||
- name: Install dependencies
|
||||
run: deno install
|
||||
|
||||
- name: Run unit tests
|
||||
run: deno task test:unit
|
||||
|
||||
integration:
|
||||
name: "Integration tests"
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16
|
||||
env:
|
||||
POSTGRES_DB: polympr_test
|
||||
POSTGRES_USER: test
|
||||
POSTGRES_PASSWORD: test
|
||||
ports:
|
||||
- 5432:5432
|
||||
options: >-
|
||||
--health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
@@ -52,21 +40,29 @@ jobs:
|
||||
with:
|
||||
deno-version: v2.x
|
||||
|
||||
- name: Install drizzle-kit
|
||||
run: npm install --ignore-scripts
|
||||
- name: Start postgres
|
||||
run: |
|
||||
sudo apt-get update -qq && sudo apt-get install -y -qq postgresql > /dev/null
|
||||
PG_VER=$(ls /etc/postgresql/)
|
||||
sudo sed -i "s/^#*listen_addresses\s*=.*/listen_addresses = '127.0.0.1'/" /etc/postgresql/$PG_VER/main/postgresql.conf
|
||||
echo "host all all 127.0.0.1/32 md5" | sudo tee -a /etc/postgresql/$PG_VER/main/pg_hba.conf
|
||||
sudo pg_ctlcluster $PG_VER main restart
|
||||
until sudo -u postgres pg_isready -h 127.0.0.1; do sleep 1; done
|
||||
sudo -u postgres psql -c "CREATE USER test WITH PASSWORD 'test';"
|
||||
sudo -u postgres psql -c "CREATE DATABASE polympr_test OWNER test;"
|
||||
sudo -u postgres psql -d polympr_test -c "GRANT ALL ON SCHEMA public TO test;"
|
||||
|
||||
- name: Apply migrations
|
||||
env:
|
||||
POSTGRES_HOST: localhost
|
||||
POSTGRES_PORT: 5432
|
||||
POSTGRES_USER: test
|
||||
POSTGRES_PASS: test
|
||||
POSTGRES_DB: polympr_test
|
||||
run: deno task migrate
|
||||
run: |
|
||||
sed 's/--> statement-breakpoint/;/g' databases/migrations/0000_square_jetstream.sql | \
|
||||
PGPASSWORD=test psql -h 127.0.0.1 -U test -d polympr_test
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install --ignore-scripts && deno install
|
||||
|
||||
- name: Run integration tests
|
||||
env:
|
||||
POSTGRES_HOST: localhost
|
||||
POSTGRES_HOST: 127.0.0.1
|
||||
POSTGRES_PORT: 5432
|
||||
POSTGRES_USER: test
|
||||
POSTGRES_PASS: test
|
||||
|
||||
+5
-5
@@ -1,15 +1,15 @@
|
||||
import { defineConfig } from "drizzle-kit";
|
||||
import process from "node:process";
|
||||
|
||||
const url = process.env.DATABASE_URL ??
|
||||
`postgresql://${process.env.POSTGRES_USER}:${process.env.POSTGRES_PASS}@${process.env.POSTGRES_HOST ?? "localhost"}:${process.env.POSTGRES_PORT ?? 5432}/${process.env.POSTGRES_DB}`;
|
||||
|
||||
export default defineConfig({
|
||||
dialect: "postgresql",
|
||||
schema: "./databases/schema.kit.ts",
|
||||
out: "./databases/migrations",
|
||||
dbCredentials: {
|
||||
host: process.env.POSTGRES_HOST!,
|
||||
port: Number(process.env.POSTGRES_PORT ?? 5432),
|
||||
user: process.env.POSTGRES_USER!,
|
||||
password: process.env.POSTGRES_PASS!,
|
||||
database: process.env.POSTGRES_DB!,
|
||||
url,
|
||||
ssl: false,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -18,29 +18,15 @@ function createTestPool(): pg.Pool {
|
||||
user: Deno.env.get("POSTGRES_USER") ?? "test",
|
||||
password: Deno.env.get("POSTGRES_PASS") ?? "test",
|
||||
database: Deno.env.get("POSTGRES_DB") ?? "polympr_test",
|
||||
ssl: false,
|
||||
});
|
||||
}
|
||||
|
||||
export const testPool = createTestPool();
|
||||
export const testDb = drizzle(testPool, { schema });
|
||||
|
||||
// Ordre de truncate respectant les FK (enfants avant parents)
|
||||
const TRUNCATE_ORDER = [
|
||||
"mobility",
|
||||
"ajustements",
|
||||
"notes",
|
||||
"ue_modules",
|
||||
"enseignements",
|
||||
"role_permissions",
|
||||
"students",
|
||||
"ue_modules",
|
||||
"users",
|
||||
"modules",
|
||||
"ues",
|
||||
"promotions",
|
||||
"permissions",
|
||||
"roles",
|
||||
] as const;
|
||||
const ALL_TABLES =
|
||||
'"mobility","ajustements","notes","ue_modules","enseignements","role_permissions","students","users","modules","ues","promotions","permissions","roles"';
|
||||
|
||||
/**
|
||||
* Vide toutes les tables dans le bon ordre.
|
||||
@@ -49,12 +35,9 @@ const TRUNCATE_ORDER = [
|
||||
export async function truncateAll(): Promise<void> {
|
||||
const client = await testPool.connect();
|
||||
try {
|
||||
// Désactiver les FK temporairement pour simplifier
|
||||
await client.query("SET session_replication_role = replica");
|
||||
for (const table of TRUNCATE_ORDER) {
|
||||
await client.query(`TRUNCATE TABLE "${table}" RESTART IDENTITY CASCADE`);
|
||||
}
|
||||
await client.query("SET session_replication_role = DEFAULT");
|
||||
await client.query(
|
||||
`TRUNCATE TABLE ${ALL_TABLES} RESTART IDENTITY CASCADE`,
|
||||
);
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user