import 'mocha' ; import * as chai from 'chai' ; import * as chaiAsPromised from 'chai-as-promised' ; import { insertUser } from '../../../src/data-access/users' ; import { DatabaseError , DatabaseErrorMessage } from '../../../src/utils/errors' ; import { seedDatabase } from '../../helpers/helpers' ; chai . use ( chaiAsPromised ) ; const { assert } = chai ; describe ( 'Data Access - Database Errors' , function ( ) : void { before ( async function ( ) { await seedDatabase ( ) ; } ) ; const exampleAddresses = [ { paymentNetwork : 'ABC' , environment : 'XYZ' , details : { address : 'abc.xyz' , tag : '123' , } , } , ] ; it ( 'Raises an error when attempting to insert a user with an null PayID' , async function ( ) { const payId = null ; const insertedAddresses = insertUser ( payId , exampleAddresses ) ; return assert . isRejected ( insertedAddresses , DatabaseError , DatabaseErrorMessage . NotNull ) ; } ) ; it ( 'Raises an error when attempting to insert a user with an empty PayID' , async function ( ) { const payId = '' ; const insertedAddresses = insertUser ( payId , exampleAddresses ) ; return assert . isRejected ( insertedAddresses , DatabaseError , DatabaseErrorMessage . EmptyStringPayId ) ; } ) ; it ( 'Raises an error when attempting to insert a user with an uppercase PayID' , async function ( ) { const payId = 'ALICE$example.com' ; const insertedAddresses = insertUser ( payId , exampleAddresses ) ; return assert . isRejected ( insertedAddresses , DatabaseError , DatabaseErrorMessage . StringCasePayId ) ; } ) ; it ( 'Raises an error when attempting to insert a user with a PayID already in use' , async function ( ) { const payId = 'alice$xpring.money' ; const insertedAddresses = insertUser ( payId , exampleAddresses ) ; return assert . isRejected ( insertedAddresses , DatabaseError , DatabaseErrorMessage . UniqueConstraintPayId ) ; } ) ; it ( 'Raises an error when attempting to insert an address with a NULL details payload' , async function ( ) { const payId = 'alice$example.com' ; const addresses = [ { paymentNetwork : 'XRPL' , environment : 'TESTNET' , } , ] ; const insertedAddresses = insertUser ( payId , addresses ) ; return assert . isRejected ( insertedAddresses , DatabaseError , DatabaseErrorMessage . NotNull ) ; } ) ; it ( 'Raises an error when attempting to insert an address with an empty paymentNetwork' , async function ( ) { const payId = 'alice$example.com' ; const addresses = [ { paymentNetwork : '' , environment : 'TESTNET' , details : { address : 'abc' , } , } , ] ; const insertedAddresses = insertUser ( payId , addresses ) ; return assert . isRejected ( insertedAddresses , DatabaseError , DatabaseErrorMessage . EmptyStringPaymentNetwork ) ; } ) ; it ( 'Raises an error when attempting to insert an address with an empty environment' , async function ( ) { const payId = 'alice$example.com' ; const addresses = [ { paymentNetwork : 'XRPL' , environment : '' , details : { address : 'abc' , } , } , ] ; const insertedAddresses = insertUser ( payId , addresses ) ; return assert . isRejected ( insertedAddresses , DatabaseError , DatabaseErrorMessage . EmptyStringEnvironment ) ; } ) ; it ( 'Raises an error when attempting to insert multiple addresses for the same (paymentNetwork, environment)' , async function ( ) { const payId = 'alice$example.com' ; const addresses = [ { paymentNetwork : 'XRPL' , environment : 'TESTNET' , details : { address : 'abc' , } , } , { paymentNetwork : 'XRPL' , environment : 'TESTNET' , details : { address : 'xyz' , } , } , ] ; const insertedAddresses = insertUser ( payId , addresses ) ; return assert . isRejected ( insertedAddresses , DatabaseError , DatabaseErrorMessage . UniqueConstraintAddress ) ; } ) ; } ) ;