2021-07-23 12:06:48 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
2023-04-12 10:33:14 +00:00
|
|
|
const LoopBackContext = require('loopback-context');
|
2021-07-23 12:06:48 +00:00
|
|
|
|
2021-09-07 09:55:26 +00:00
|
|
|
describe('invoiceIn clone()', () => {
|
2024-02-05 10:59:51 +00:00
|
|
|
let ctx;
|
|
|
|
let options;
|
|
|
|
let tx;
|
|
|
|
|
|
|
|
beforeEach(async() => {
|
|
|
|
ctx = {
|
|
|
|
req: {
|
|
|
|
accessToken: {userId: 1},
|
|
|
|
headers: {origin: 'http://localhost'}
|
|
|
|
},
|
|
|
|
args: {}
|
2023-04-12 10:33:14 +00:00
|
|
|
};
|
2024-02-05 10:59:51 +00:00
|
|
|
|
2023-04-12 10:33:14 +00:00
|
|
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
2024-02-05 10:59:51 +00:00
|
|
|
active: ctx.req
|
2023-04-12 10:33:14 +00:00
|
|
|
});
|
2024-02-05 10:59:51 +00:00
|
|
|
|
|
|
|
options = {transaction: tx};
|
|
|
|
tx = await models.Sale.beginTransaction({});
|
|
|
|
options.transaction = tx;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async() => {
|
|
|
|
await tx.rollback();
|
2023-04-12 10:33:14 +00:00
|
|
|
});
|
|
|
|
|
2021-07-23 12:06:48 +00:00
|
|
|
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() => {
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|