salix/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js

62 lines
2.1 KiB
JavaScript
Raw Normal View History

2022-03-03 13:42:12 +00:00
const models = require('vn-loopback/server/server').models;
describe('AgencyTerm createInvoiceIn()', () => {
const rows = [
{
routeFk: 2,
supplierFk: 1,
created: '2022-03-02T23:00:00.000Z',
totalPrice: 165
}
];
const dms = [
{
id: 7,
file: '7.pdf',
contentType: 'application/pdf',
reference: '1',
description: 'Plants SL',
hasFile: false,
companyFk: 442,
dmsTypeFk: 1,
warehouseFk: 1,
workerFk: 9
}
];
const userId = 1;
const activeCtx = {
accessToken: {userId: userId},
};
const ctx = {req: activeCtx};
it('should make a global invoicing', async() => {
const tx = await models.AgencyTerm.beginTransaction({});
const options = {transaction: tx};
try {
const invoiceInId = 10;
const invoiceInDueDayId = 11;
const invoiceInTaxId = 12;
const oldInvoiceIn = await models.AgencyTerm.findById(invoiceInId, null, options);
const oldInvoiceInDueDay = await models.AgencyTerm.findById(invoiceInDueDayId, null, options);
const oldInvoiceInTax = await models.AgencyTerm.findById(invoiceInTaxId, null, options);
const [newInvoiceIn] = await models.Ticket.rawSql('SELECT MAX(id) id FROM invoiceIn', null, options);
// const [newInvoiceInDueDay] = await models.AgencyTerm.rawSql('SELECT MAX(id) id FROM invoiceInDueDay', null, options);
// const [newInvoiceInTax] = await models.AgencyTerm.rawSql('SELECT MAX(id) id FROM invoiceInTax', null, options);
await models.AgencyTerm.createInvoiceIn(rows, dms, options);
// expect(newInvoiceIn.id).toEqual(oldInvoiceIn.id + 1);
// expect(newInvoiceInDueDay.id).toEqual(oldInvoiceInDueDay.id + 1);
// expect(newInvoiceInTax.id).toEqual(oldInvoiceInTax.id + 1);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});