salix/modules/invoiceOut/back/methods/invoiceOut/specs/globalInvoicing.spec.js

41 lines
1.3 KiB
JavaScript

const models = require('vn-loopback/server/server').models;
describe('InvoiceOut globalInvoicing()', () => {
const userId = 1;
const companyFk = 442;
const clientId = 1101;
const invoicedTicketId = 8;
const invoiceSerial = 'A';
const activeCtx = {
accessToken: {userId: userId},
};
const ctx = {req: activeCtx};
it('should make a global invoicing', async() => {
spyOn(models.InvoiceOut, 'createPdf').and.returnValue(new Promise(resolve => resolve(true)));
const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx};
try {
ctx.args = {
invoiceDate: new Date(),
maxShipped: new Date(),
fromClientId: clientId,
toClientId: clientId,
companyFk: companyFk
};
const result = await models.InvoiceOut.globalInvoicing(ctx, options);
const ticket = await models.Ticket.findById(invoicedTicketId, null, options);
expect(result.length).toBeGreaterThan(0);
expect(ticket.refFk).toContain(invoiceSerial);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});