const models = require('vn-loopback/server/server').models; describe('order addToOrder()', () => { const orderId = 8; it('should add a row to a given order', async() => { const tx = await models.Order.beginTransaction({}); try { const options = {transaction: tx}; const unmodifiedRows = await models.OrderRow.find({where: {orderFk: orderId}}, options); expect(unmodifiedRows.length).toBe(2); const params = { orderFk: orderId, items: [{ itemFk: 1, quantity: 10, warehouseFk: 1 }] }; await models.OrderRow.addToOrder(params, options); const modifiedRows = await models.OrderRow.find({where: {orderFk: orderId}}, options); expect(modifiedRows.length).toBe(3); await tx.rollback(); } catch (e) { await tx.rollback(); throw e; } }); });