import * as v8 from 'v8' ; import App from '../../src/app' ; import config from '../../src/config' ; import knex from '../../src/db/knex' ; import syncDatabaseSchema from '../../src/db/syncDatabaseSchema' ; param obj returns function structuredClone < T > ( obj ) { return v8 . deserialize ( v8 . serialize ( obj ) ) ; } returns export async function appSetup ( ) { const app = new App ( ) ; const testConfig = structuredClone ( config ) ; testConfig . database . options . seedDatabase = true ; await app . init ( testConfig ) ; return app ; } param app export function appCleanup ( app ) { app . close ( ) ; } export async function seedDatabase ( ) { const testConfig = structuredClone ( config ) ; testConfig . database . options . seedDatabase = true ; await syncDatabaseSchema ( testConfig . database ) ; } param constraintName param tableName returns export async function getDatabaseConstraintDefinition ( constraintName , tableName ) { return knex . raw ( `
        -- Select the constraint definition in the relevant table.
        -- We fetch the relevant constraint, get the constraint definition.
        --
        SELECT  pg_get_constraintdef(con.oid) as constraint_def
        FROM    pg_constraint con
                INNER JOIN pg_class rel ON rel.oid = con.conrelid
        WHERE   con.conname = ?
                AND rel.relname = ?;
      ` , [ constraintName , tableName ] ) . then ( async ( result ) => result . rows [ 0 ] . constraint_def ) ; }