Add backend unit/integration tests, Playwright e2e tests, README, cookie Secure fix
SonarQube Analysis / sonarqube (push) Successful in 4m20s

This commit is contained in:
2026-08-13 22:35:38 +00:00
parent 2adbf24b23
commit 921022c658
25 changed files with 6600 additions and 57 deletions
+11
View File
@@ -0,0 +1,11 @@
// Runs before the test framework loads, so app.ts's Postgres pool (created
// at import time) connects to the disposable test database instead of
// whatever PGHOST/PGUSER happen to be set in the shell environment.
process.env.NODE_ENV = 'test';
process.env.PGHOST = process.env.TEST_PGHOST || 'localhost';
process.env.PGPORT = process.env.TEST_PGPORT || '55432';
process.env.PGUSER = process.env.TEST_PGUSER || 'redefined_test';
process.env.PGPASSWORD = process.env.TEST_PGPASSWORD || 'redefined_test';
process.env.PGDATABASE = process.env.TEST_PGDATABASE || 'redefined_test';
process.env.DEMO_MODE = 'true';
process.env.UPLOADS_DIR = '/tmp/redefined-test-uploads';
+31
View File
@@ -0,0 +1,31 @@
import { Client } from 'pg';
async function waitForDb(retries = 20): Promise<void> {
const config = {
host: process.env.TEST_PGHOST || 'localhost',
port: parseInt(process.env.TEST_PGPORT || '55432', 10),
user: process.env.TEST_PGUSER || 'redefined_test',
password: process.env.TEST_PGPASSWORD || 'redefined_test',
database: process.env.TEST_PGDATABASE || 'redefined_test'
};
for (let i = 0; i < retries; i++) {
const client = new Client(config);
try {
await client.connect();
await client.end();
return;
} catch {
await new Promise(r => setTimeout(r, 1000));
}
}
throw new Error(
'Could not reach the test database on port 55432. Run `npm run db:test:up` before `npm run test:integration`.'
);
}
export default async function globalSetup(): Promise<void> {
await waitForDb();
const { migrate, closeDb } = await import('./testDb');
await migrate();
await closeDb();
}
+27
View File
@@ -0,0 +1,27 @@
import { Pool } from 'pg';
import fs from 'fs';
import path from 'path';
export const testPool = new Pool({
host: process.env.TEST_PGHOST || 'localhost',
port: parseInt(process.env.TEST_PGPORT || '55432', 10),
user: process.env.TEST_PGUSER || 'redefined_test',
password: process.env.TEST_PGPASSWORD || 'redefined_test',
database: process.env.TEST_PGDATABASE || 'redefined_test'
});
export async function migrate(): Promise<void> {
const sql = fs.readFileSync(path.join(__dirname, '..', '..', '..', 'init.sql'), 'utf-8');
await testPool.query(sql);
}
export async function resetDb(): Promise<void> {
await testPool.query(`
TRUNCATE TABLE orders, customer_tokens, customer_sessions, customers, item_images, items
RESTART IDENTITY CASCADE
`);
}
export async function closeDb(): Promise<void> {
await testPool.end();
}