Refactor & unit tests

This commit is contained in:
jd
2026-02-13 22:06:49 +00:00
parent eca7405974
commit 387a9a36f3
20 changed files with 423 additions and 148 deletions

35
src/tests/test-setup.ts Normal file
View File

@@ -0,0 +1,35 @@
import {beforeAll, afterAll} from 'bun:test';
import Bun from 'bun';
import {sql} from "bun";
beforeAll(async () => {
console.log(process.env.DATABASE_URL);
const scriptFile = await Bun.file('./scripts/dbCreate.sql').text();
// Drop the database in preparation for rebuild
await sql`DROP SCHEMA public CASCADE`;
await sql`CREATE SCHEMA public`;
// Run DB build script
await sql.unsafe(scriptFile);
// Populate initial data
await sql`SET search_path TO showfinder,public`;
await sql`INSERT INTO claims(name, is_default) VALUES ('ADMIN', false)`;
await sql`INSERT INTO claims(name, is_default) VALUES ('USERS_CREATE', false)`;
await sql`INSERT INTO claims(name, is_default) VALUES ('USERS_OTHER_UPDATE', false)`;
await sql`INSERT INTO claims(name, is_default) VALUES ('USERS_OTHER_DELETE', true)`;
await sql`INSERT INTO claims(name, is_default) VALUES ('USERS_SELF_READ', true)`;
await sql`INSERT INTO claims(name, is_default) VALUES ('USERS_SELF_UPDATE', true)`;
await sql`INSERT INTO claims(name, is_default) VALUES ('USERS_OTHER_READ', true)`;
await sql`INSERT INTO claims(name, is_default) VALUES ('USERS_SELF_DELETE', false)`;
});