import 'mocha' ; import { assert } from 'chai' ; import knex from '../../../src/db/knex' ; import { seedDatabase , getDatabaseConstraintDefinition , } from '../../helpers/helpers' ; describe ( 'Database Schema - PayID Regex Example Table' , function ( ) : void { let payIdRegex ; before ( async function ( ) { await seedDatabase ( ) ; const validPayIdConstraint = await getDatabaseConstraintDefinition ( 'valid_pay_id' , 'account' ) ; const regexExtractor = /'(?<payIdRegex>.*?)'/u ; const match = regexExtractor . exec ( validPayIdConstraint ) ; payIdRegex = match ?. groups ?. payIdRegex ?? '' ; if ( payIdRegex === '' ) { throw new Error ( 'Expected payIdRegex to be defined.' ) ; } } ) ; it ( 'Contains the expected number of valid PayIDs' , async function ( ) { const EXPECTED_VALID_PAYID_COUNT = 23 ; const validPayIdCount = await knex . count ( '*' ) . from ( 'payid_examples' ) . where ( 'pay_id' , '~*' , payIdRegex ) . then ( async ( result ) => Number ( result [ 0 ] . count ) ) ; const isValidCount = await knex . count ( '*' ) . from ( 'payid_examples' ) . where ( 'is_valid' , true ) . then ( async ( result ) => Number ( result [ 0 ] . count ) ) ; assert . strictEqual ( validPayIdCount , EXPECTED_VALID_PAYID_COUNT ) ; assert . strictEqual ( isValidCount , EXPECTED_VALID_PAYID_COUNT ) ; } ) ; it ( 'Contains the expected number of invalid PayIDs' , async function ( ) { const EXPECTED_INVALID_PAYID_COUNT = 28 ; const invalidPayIdCount = await knex . count ( '*' ) . from ( 'payid_examples' ) . where ( 'pay_id' , '!~*' , payIdRegex ) . then ( async ( result ) => Number ( result [ 0 ] . count ) ) ; const isInvalidCount = await knex . count ( '*' ) . from ( 'payid_examples' ) . where ( 'is_valid' , false ) . then ( async ( result ) => Number ( result [ 0 ] . count ) ) ; assert . strictEqual ( invalidPayIdCount , EXPECTED_INVALID_PAYID_COUNT ) ; assert . strictEqual ( isInvalidCount , EXPECTED_INVALID_PAYID_COUNT ) ; } ) ; } ) ;