DataBroker

DataBroker

Class for working with real data in unit tests

Constructor

new DataBroker(db)

Create a new data broker

Source:
Parameters:
Name Type Default Description
db Db null

The database to read/write into

Members

db :Db

The database to read/write to

Source:
Type:

deleted :Object

Arrays of deleted indexed by table name

Source:
Type:
  • Object

ids :Object

Arrays of newly inserted ids indexed by table name

Source:
Type:
  • Object

now :Date

The current date

Source:
Type:
  • Date

uniqid :String

A unique id suitable for a unit test

Source:
Type:
  • String

Methods

(async) cleanup() → {Promise.<Number>}

Delete insertions and restore deleted

Source:
Returns:
Type:
Promise.<Number>

The total number of rows affected

created_and_modified(userId) → {Object}

Get value for created_at, created_by, modified_at and modified_by

Source:
Parameters:
Name Type Default Description
userId Number 0

The user id to use for created_by and modified_by

Returns:
Type:
Object

createdAndModified(userId) → {Object}

Get value for createdAt, createdBy, modifiedAt and modifiedBy

Source:
Parameters:
Name Type Default Description
userId Number 0

The user id to use for createdBy and modifiedBy

Returns:
Type:
Object

(async) delete(table, criteria) → {Promise.<Array.<Object>>}

Delete records that can be re-inserted later

Source:
Parameters:
Name Type Description
table String

The name of the table to delete from

criteria Object

The criteria to match the records

Returns:
Type:
Promise.<Array.<Object>>

An array of all the records

(async) insert(table, values, options) → {Promise.<(Number|Object)>}

Insert records that can be cleaned up later

Properties:
Name Type Description
options.compositeKey Array

An array of column names that form a composite key

Source:
Parameters:
Name Type Description
table String

The name of the table to insert into

values Object

The record to insert

options Object

Additional options

Returns:
Type:
Promise.<(Number|Object)>

Resolves with the id of the new record or the composite key