2023-03-06 08:27:53 +00:00
|
|
|
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() => {
|
2023-03-06 08:27:53 +00:00
|
|
|
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);
|
2023-03-06 08:27:53 +00:00
|
|
|
|
|
|
|
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);
|
2023-03-06 08:27:53 +00:00
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
await tx.rollback();
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error.message).toEqual(`Insert a date range`);
|
|
|
|
});
|
|
|
|
});
|