Add Playwright e2e coverage + comment-level video upload workflow (#40)
All checks were successful
Build and Push Image / docker-build-and-push (push) Successful in 2m31s
All checks were successful
Build and Push Image / docker-build-and-push (push) Successful in 2m31s
## Summary - add Playwright e2e auth setup + seeded test DB flow - fix Playwright startup order so DB seed runs before web server uses SQLite - add full trip-planning e2e scenario (future trip, travellers, destination, flight, lodging, upcoming verification) - configure Auth.js custom sign-in page for base-path routing - add repo guidance in AGENTS.md / CLAUDE.md requiring e2e for user-facing changes - document and validate comment-level Gitea video attachment workflow (create comment, upload to comment assets endpoint) ## Validation - bunx playwright test e2e/auth.test.ts --project=chromium\n- bunx playwright test e2e/trip-planning.test.ts --project=chromium - PW_VIDEO_MODE=on PW_TRACE_MODE=off bunx playwright test e2e/trip-planning.test.ts --project=chromium ## Issue - relates to #38 Co-authored-by: AI Agent <ai-agent@campbellwireless.net> Reviewed-on: #40 Co-authored-by: Shaun Campbell <shaun@campbellwireless.net> Co-committed-by: Shaun Campbell <shaun@campbellwireless.net>
This commit was merged in pull request #40.
This commit is contained in:
77
e2e/setup/seed-db.ts
Normal file
77
e2e/setup/seed-db.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
// Bun script — runs with `bun run e2e/setup/seed-db.ts`.
|
||||
// Uses bun:sqlite and argon2 directly; must NOT be imported from Node context.
|
||||
import { Database as BunSqlite } from 'bun:sqlite';
|
||||
import { existsSync, unlinkSync } from 'fs';
|
||||
import { resolve } from 'path';
|
||||
import argon2 from 'argon2';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { config as dotenvConfig } from 'dotenv';
|
||||
import { TEST_USERS } from './test-users.js';
|
||||
|
||||
dotenvConfig({ path: resolve(process.cwd(), '.env.test'), override: true });
|
||||
|
||||
const DB_PATH = resolve(process.cwd(), 'trips.test.db');
|
||||
|
||||
// Delete any existing test DB so we start clean each run
|
||||
for (const ext of ['', '-shm', '-wal']) {
|
||||
const p = DB_PATH + ext;
|
||||
if (existsSync(p)) {
|
||||
unlinkSync(p);
|
||||
}
|
||||
}
|
||||
|
||||
const db = new BunSqlite(DB_PATH);
|
||||
db.exec('PRAGMA foreign_keys = ON');
|
||||
|
||||
// Wrap bun:sqlite to match the Database interface expected by runMigrations
|
||||
const dbWrapper = {
|
||||
run(sql: string, params: unknown[] = []) {
|
||||
db.query(sql).run(...(params as [unknown?, ...unknown[]]));
|
||||
},
|
||||
get<T = Record<string, unknown>>(sql: string, params: unknown[] = []): T | undefined {
|
||||
const row = db.query(sql).get(...(params as [unknown?, ...unknown[]]));
|
||||
return (row === null ? undefined : row) as T | undefined;
|
||||
},
|
||||
all<T = Record<string, unknown>>(sql: string, params: unknown[] = []): T[] {
|
||||
return db.query(sql).all(...(params as [unknown?, ...unknown[]])) as T[];
|
||||
},
|
||||
close() {
|
||||
db.close();
|
||||
}
|
||||
};
|
||||
|
||||
const { runMigrations } = await import('../../src/lib/server/db/migrations.js');
|
||||
runMigrations(dbWrapper);
|
||||
console.log('[e2e] Migrations complete.');
|
||||
|
||||
async function hashPassword(password: string): Promise<string> {
|
||||
return argon2.hash(password, {
|
||||
type: argon2.argon2id,
|
||||
memoryCost: 8192,
|
||||
timeCost: 2,
|
||||
parallelism: 1
|
||||
});
|
||||
}
|
||||
|
||||
const regularId = randomUUID();
|
||||
dbWrapper.run(
|
||||
`INSERT INTO users (id, username, full_name, email, auth_source) VALUES (?, ?, ?, ?, ?)`,
|
||||
[regularId, TEST_USERS.regular.username, TEST_USERS.regular.fullName, TEST_USERS.regular.email, 'Local']
|
||||
);
|
||||
dbWrapper.run(`INSERT INTO local_credentials (user_id, password_hash) VALUES (?, ?)`, [
|
||||
regularId,
|
||||
await hashPassword(TEST_USERS.regular.password)
|
||||
]);
|
||||
|
||||
const adminId = randomUUID();
|
||||
dbWrapper.run(
|
||||
`INSERT INTO users (id, username, full_name, email, auth_source) VALUES (?, ?, ?, ?, ?)`,
|
||||
[adminId, TEST_USERS.admin.username, TEST_USERS.admin.fullName, TEST_USERS.admin.email, 'Local']
|
||||
);
|
||||
dbWrapper.run(`INSERT INTO local_credentials (user_id, password_hash) VALUES (?, ?)`, [
|
||||
adminId,
|
||||
await hashPassword(TEST_USERS.admin.password)
|
||||
]);
|
||||
|
||||
db.close();
|
||||
console.log(`[e2e] Seeded users: ${TEST_USERS.regular.username}, ${TEST_USERS.admin.username}`);
|
||||
Reference in New Issue
Block a user