const models = require('vn-loopback/server/server').models; describe('invoiceIn negativeBases()', () => { it('should return all negative bases in a date range', async() => { const tx = await models.InvoiceIn.beginTransaction({}); const options = {transaction: tx}; const ctx = { args: { from: new Date().setMonth(new Date().getMonth() - 12), to: new Date(), filter: {} } }; try { const result = await models.InvoiceIn.negativeBases(ctx, options); expect(result.length).toBeGreaterThan(0); await tx.rollback(); } catch (e) { await tx.rollback(); throw e; } }); it('should throw an error if a date range is not in args', async() => { let error; const tx = await models.InvoiceIn.beginTransaction({}); const options = {transaction: tx}; const ctx = { args: { filter: {} } }; try { await models.InvoiceIn.negativeBases(ctx, options); await tx.rollback(); } catch (e) { error = e; await tx.rollback(); } expect(error.message).toEqual(`Insert a date range`); }); });