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

66 lines
2.1 KiB
JavaScript

const models = require('vn-loopback/server/server').models;
describe('invoiceIn clone()', () => {
const ctx = beforeAll.getCtx();
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() => {
const clone = await models.InvoiceIn.clone(ctx, 1, false, options);
expect(clone.supplierRef).toEqual('1234(2)');
const invoiceIn = await models.InvoiceIn.findOne({
include: [
{
relation: 'invoiceInTax',
},
{
relation: 'invoiceInDueDay',
}
], where: {
id: clone.id
}
}, 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() => {
const clone = await models.InvoiceIn.clone(ctx, 1, true, options);
expect(clone.supplierRef).toEqual('1234(2)');
const invoiceIn = await models.InvoiceIn.findOne({
include: [
{
relation: 'invoiceInTax',
},
{
relation: 'invoiceInIntrastat',
}
], where: {
id: clone.id
}
}, options);
const invoiceInTax = invoiceIn.invoiceInTax();
const invoiceInIntrastat = invoiceIn.invoiceInIntrastat();
expect(invoiceInTax.length).toEqual(2);
expect(invoiceInIntrastat.length).toEqual(2);
});
});