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:
20
e2e/setup/global-setup.ts
Normal file
20
e2e/setup/global-setup.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { FullConfig } from '@playwright/test';
|
||||
import { spawnSync } from 'child_process';
|
||||
import { resolve } from 'path';
|
||||
import { config as dotenvConfig } from 'dotenv';
|
||||
|
||||
dotenvConfig({ path: resolve(process.cwd(), '.env.test'), override: true });
|
||||
|
||||
async function globalSetup(_config: FullConfig): Promise<void> {
|
||||
console.log('[e2e] Seeding test database via Bun...');
|
||||
const result = spawnSync('bun', ['run', 'e2e/setup/seed-db.ts'], {
|
||||
env: { ...process.env },
|
||||
stdio: 'inherit',
|
||||
cwd: process.cwd()
|
||||
});
|
||||
if (result.status !== 0) {
|
||||
throw new Error(`[e2e] DB seed script failed with exit code ${result.status}`);
|
||||
}
|
||||
}
|
||||
|
||||
export default globalSetup;
|
||||
17
e2e/setup/global-teardown.ts
Normal file
17
e2e/setup/global-teardown.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import type { FullConfig } from '@playwright/test';
|
||||
import { existsSync, unlinkSync } from 'fs';
|
||||
import { resolve } from 'path';
|
||||
|
||||
const DB_PATH = resolve(process.cwd(), 'trips.test.db');
|
||||
|
||||
async function globalTeardown(_config: FullConfig): Promise<void> {
|
||||
for (const ext of ['', '-shm', '-wal']) {
|
||||
const p = DB_PATH + ext;
|
||||
if (existsSync(p)) {
|
||||
unlinkSync(p);
|
||||
}
|
||||
}
|
||||
console.log('[e2e] Removed trips.test.db');
|
||||
}
|
||||
|
||||
export default globalTeardown;
|
||||
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}`);
|
||||
15
e2e/setup/test-users.ts
Normal file
15
e2e/setup/test-users.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
// Shared test user definitions — no runtime deps, importable from both Node and Bun contexts.
|
||||
export const TEST_USERS = {
|
||||
regular: {
|
||||
username: 'e2e_user',
|
||||
fullName: 'E2E Regular User',
|
||||
email: 'e2e_user@test.local',
|
||||
password: 'e2e-regular-password123'
|
||||
},
|
||||
admin: {
|
||||
username: 'e2e_admin',
|
||||
fullName: 'E2E Admin User',
|
||||
email: 'e2e_admin@test.local',
|
||||
password: 'e2e-admin-password123'
|
||||
}
|
||||
} as const;
|
||||
Reference in New Issue
Block a user