salix/modules/invoiceIn/back/methods/invoice-in/specs/unbilledClients.spec.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

const models = require('vn-loopback/server/server').models;
2023-03-16 08:35:00 +00:00
describe('invoiceIn unbilledClients()', () => {
it('should return all unbilled clients 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 {
2023-03-16 08:35:00 +00:00
const result = await models.InvoiceIn.unbilledClients(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 {
2023-03-16 08:35:00 +00:00
await models.InvoiceIn.unbilledClients(ctx, options);
await tx.rollback();
} catch (e) {
error = e;
await tx.rollback();
}
expect(error.message).toEqual(`Insert a date range`);
});
});