All files / test/PgBoss util.ts

100% Statements 20/20
100% Branches 0/0
100% Functions 1/1
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 603x                     3x 3x   3x 3x   3x 3x                   3x 3x                   3x             3x 3x   3x 3x 3x 3x   3x 3x   3x    
import {
  BlockEntity,
  CurrentPoolMetricsEntity,
  PoolDelistedEntity,
  PoolMetadataEntity,
  PoolRegistrationEntity,
  PoolRetirementEntity,
  StakePoolEntity,
  createDataSource
} from '@cardano-sdk/projection-typeorm';
import { Cardano } from '@cardano-sdk/core';
import { Pool } from 'pg';
import { logger } from '@cardano-sdk/util-dev';
 
export const blockId = 'test_block';
export const poolId = 'test_pool'.padEnd(56, ' ') as Cardano.PoolId;
 
export const initHandlerTest = async () => {
  const connectionConfig = {
    database: 'projection',
    host: process.env.POSTGRES_HOST_DB_SYNC!,
    password: process.env.POSTGRES_PASSWORD_DB_SYNC!,
    port: Number.parseInt(process.env.POSTGRES_PORT_DB_SYNC!, 10),
    // used by: new Pool()
    user: process.env.POSTGRES_USER_DB_SYNC!,
    // used by: createDataSource()
    username: process.env.POSTGRES_USER_DB_SYNC!
  };
  const db = new Pool(connectionConfig);
  const entities = [
    BlockEntity,
    CurrentPoolMetricsEntity,
    PoolMetadataEntity,
    PoolRegistrationEntity,
    PoolRetirementEntity,
    StakePoolEntity,
    PoolDelistedEntity
  ];
 
  const dataSource = createDataSource({
    connectionConfig,
    devOptions: { dropSchema: true, synchronize: true },
    entities,
    logger
  });
 
  await db.query('CREATE EXTENSION IF NOT EXISTS pgcrypto');
  await dataSource.initialize();
 
  const blockRepos = dataSource.getRepository(BlockEntity);
  const poolRepos = dataSource.getRepository(StakePoolEntity);
  const block = { hash: blockId, height: 23, slot: 42 };
  const stakePool = { id: poolId, status: 'active' };
 
  await blockRepos.insert(block);
  await poolRepos.insert(stakePool);
 
  return { block, dataSource, db, stakePool };
};