Linden Crandall 5075f5c5d8
Some checks are pending
Automatisch Backend Tests / test (push) Waiting to run
Automatisch CI / linter (push) Waiting to run
Automatisch CI / start-backend-server (push) Waiting to run
Automatisch CI / start-backend-worker (push) Waiting to run
Automatisch CI / build-web (push) Waiting to run
Automatisch UI Tests / test (push) Waiting to run
commit upstream files
2025-02-06 04:14:18 +09:00

36 lines
1.0 KiB
JavaScript

import { Model } from 'objection';
import { client as knex } from '../../src/config/database.js';
import logger from '../../src/helpers/logger.js';
import { vi } from 'vitest';
import './insert-assertions.js';
global.beforeAll(async () => {
global.knex = null;
logger.silent = true;
// Remove default roles and permissions before running the test suite
await knex.raw('TRUNCATE TABLE config CASCADE');
await knex.raw('TRUNCATE TABLE roles CASCADE');
await knex.raw('TRUNCATE TABLE permissions CASCADE');
});
global.beforeEach(async () => {
// It's assigned as global.knex for the convenience even though
// it's a transaction. It's rolled back after each test.
// by assigning to knex, we can use it as knex.table('example') in tests files.
global.knex = await knex.transaction();
Model.knex(global.knex);
});
global.afterEach(async () => {
await global.knex.rollback();
Model.knex(knex);
vi.restoreAllMocks();
vi.clearAllMocks();
});
global.afterAll(async () => {
logger.silent = false;
});