const models = require('vn-loopback/server/server').models; describe('order removes()', () => { it('should throw an error if rows property is empty', async() => { const tx = await models.Order.beginTransaction({}); let error; try { const options = {transaction: tx}; await models.OrderRow.removes({rows: []}, options); await tx.rollback(); } catch (e) { await tx.rollback(); error = e; } expect(error).toEqual(new Error('There is nothing to delete')); }); it('should throw an error if the row selected is not editable', async() => { const tx = await models.Order.beginTransaction({}); let error; try { const options = {transaction: tx}; await models.OrderRow.removes({rows: [2]}, options); await tx.rollback(); } catch (e) { await tx.rollback(); error = e; } expect(error).toEqual(new Error('This order is not editable')); }); it('should delete the row', async() => { const tx = await models.Order.beginTransaction({}); try { const options = {transaction: tx}; const params = { rows: [12], actualOrderId: 16 }; const res = await models.OrderRow.removes(params, options); expect(res).toEqual([{count: 1}]); await tx.rollback(); } catch (e) { await tx.rollback(); throw e; } }); });