77 lines
2.3 KiB
JavaScript
77 lines
2.3 KiB
JavaScript
const models = require('vn-loopback/server/server').models;
|
|
const LoopBackContext = require('loopback-context');
|
|
|
|
describe('invoiceIn clone()', () => {
|
|
let ctx;
|
|
let options;
|
|
let tx;
|
|
|
|
beforeEach(async() => {
|
|
ctx = {
|
|
req: {
|
|
accessToken: {userId: 1},
|
|
headers: {origin: 'http://localhost'}
|
|
},
|
|
args: {}
|
|
};
|
|
|
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
|
active: ctx.req
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|