import config from '../src/config' import chai, { expect, should, assert } from 'chai' import _ from 'lodash' const knex = require('knex')(config.database) const bookshelf = require('bookshelf')(knex) const Test = bookshelf.Model.extend({ tableName: 'TEST_ONLY', idAttribute: 'ID', softDelete: false }) // //Standard Chai Style it('Testing Creating Notification Setting Record', function() { //Just to get a random value const value = Math.floor((Math.random() * 10000) + 1).toString() let obj = { NAME: value } return createNsWithTransaction(obj).then(function(data) { let res = data.toJSON() expect(value).to.equal(res.NAME) }) }) function createNsWithTransaction(object) { //With Promises return new Promise(async (resolve, reject) => { bookshelf.transaction(async (t) => { try { const model = await Test.forge(object).save(null, { transacting: t }) //This commits the Transaction resolve(model) } catch (err) { logger.error(' Test Failed', err) await this.rollbackTransaction(t) reject(err) } }) }) }