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

66 lines
2.1 KiB
JavaScript
Raw Normal View History

2021-07-23 12:06:48 +00:00
const models = require('vn-loopback/server/server').models;
describe('invoiceIn clone()', () => {
2024-06-14 06:39:57 +00:00
const ctx = beforeAll.getCtx();
2024-02-05 10:59:51 +00:00
let options;
let tx;
beforeEach(async() => {
options = {transaction: tx};
tx = await models.Sale.beginTransaction({});
options.transaction = tx;
});
afterEach(async() => {
await tx.rollback();
});
it('should return the cloned invoiceIn and also clone invoiceInDueDays ' +
'and invoiceInTaxes if there are any referencing the invoiceIn', async() => {
2024-02-05 10:59:51 +00:00
const clone = await models.InvoiceIn.clone(ctx, 1, false, options);
2021-07-23 12:06:48 +00:00
2024-02-05 10:59:51 +00:00
expect(clone.supplierRef).toEqual('1234(2)');
const invoiceIn = await models.InvoiceIn.findOne({
include: [
{
relation: 'invoiceInTax',
},
{
relation: 'invoiceInDueDay',
}
], where: {
id: clone.id
2021-07-23 12:06:48 +00:00
}
2024-02-05 10:59:51 +00:00
}, options);
const invoiceInTax = invoiceIn.invoiceInTax();
const invoiceInDueDay = invoiceIn.invoiceInDueDay();
expect(invoiceInTax.length).toEqual(2);
expect(invoiceInDueDay.length).toEqual(2);
});
it('should return the cloned invoiceIn and also clone invoiceInIntrastat ' +
'and invoiceInTaxes if it is rectificative', async() => {
2024-02-05 10:59:51 +00:00
const clone = await models.InvoiceIn.clone(ctx, 1, true, options);
2021-07-23 12:06:48 +00:00
2024-02-05 10:59:51 +00:00
expect(clone.supplierRef).toEqual('1234(2)');
const invoiceIn = await models.InvoiceIn.findOne({
include: [
{
relation: 'invoiceInTax',
},
{
relation: 'invoiceInIntrastat',
2024-02-02 13:02:16 +00:00
}
2024-02-05 10:59:51 +00:00
], where: {
id: clone.id
}
}, options);
const invoiceInTax = invoiceIn.invoiceInTax();
const invoiceInIntrastat = invoiceIn.invoiceInIntrastat();
expect(invoiceInTax.length).toEqual(2);
expect(invoiceInIntrastat.length).toEqual(2);
2021-07-23 12:06:48 +00:00
});
});