Refactor & unit tests
This commit is contained in:
35
src/tests/test-setup.ts
Normal file
35
src/tests/test-setup.ts
Normal 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)`;
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user