2022-03-03 13:42:12 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
|
|
|
|
2022-05-12 09:43:41 +00:00
|
|
|
describe('AgencyTerm createInvoiceIn()', () => {
|
2024-06-11 08:00:30 +00:00
|
|
|
const {ctx} = beforeAll;
|
2022-03-03 13:42:12 +00:00
|
|
|
const rows = [
|
|
|
|
{
|
|
|
|
routeFk: 2,
|
|
|
|
supplierFk: 1,
|
|
|
|
created: '2022-03-02T23:00:00.000Z',
|
|
|
|
totalPrice: 165
|
|
|
|
}
|
|
|
|
];
|
|
|
|
const dms = [
|
|
|
|
{
|
2022-03-04 10:28:45 +00:00
|
|
|
id: 6
|
2022-03-03 13:42:12 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2022-03-08 12:42:44 +00:00
|
|
|
it('should make an invoiceIn', async() => {
|
2022-03-03 13:42:12 +00:00
|
|
|
const tx = await models.AgencyTerm.beginTransaction({});
|
|
|
|
const options = {transaction: tx};
|
|
|
|
|
|
|
|
try {
|
|
|
|
const invoiceInId = 10;
|
|
|
|
const invoiceInDueDayId = 11;
|
|
|
|
const invoiceInTaxId = 12;
|
|
|
|
|
2022-03-04 10:28:45 +00:00
|
|
|
const oldInvoiceIn = await models.InvoiceIn.findById(invoiceInId, null, options);
|
|
|
|
const oldInvoiceInDueDay = await models.InvoiceInDueDay.findById(invoiceInDueDayId, null, options);
|
|
|
|
const oldInvoiceInTax = await models.InvoiceInTax.findById(invoiceInTaxId, null, options);
|
2022-03-03 13:42:12 +00:00
|
|
|
|
2023-06-01 06:32:06 +00:00
|
|
|
await models.AgencyTerm.createInvoiceIn(ctx, rows, dms, options);
|
2022-03-03 13:42:12 +00:00
|
|
|
|
2022-03-04 10:28:45 +00:00
|
|
|
const [newInvoiceIn] = await models.InvoiceIn.rawSql('SELECT MAX(id) id FROM invoiceIn', null, options);
|
2022-05-12 09:43:41 +00:00
|
|
|
|
|
|
|
const dueDayQuery = 'SELECT MAX(id) id FROM invoiceInDueDay';
|
|
|
|
const [newInvoiceInDueDay] = await models.InvoiceInDueDay.rawSql(dueDayQuery, null, options);
|
|
|
|
|
|
|
|
const taxQuery = 'SELECT MAX(id) id FROM invoiceInTax';
|
|
|
|
const [newInvoiceInTax] = await models.InvoiceInTax.rawSql(taxQuery, null, options);
|
2022-03-04 10:28:45 +00:00
|
|
|
|
|
|
|
expect(newInvoiceIn.id).toBeGreaterThan(oldInvoiceIn.id);
|
|
|
|
expect(newInvoiceInDueDay.id).toBeGreaterThan(oldInvoiceInDueDay.id);
|
|
|
|
expect(newInvoiceInTax.id).toBeGreaterThan(oldInvoiceInTax.id);
|
2022-03-03 13:42:12 +00:00
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|