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

61 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-07-23 12:06:48 +00:00
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
2021-07-23 12:06:48 +00:00
describe('invoiceIn clone()', () => {
beforeAll(async() => {
const activeCtx = {
accessToken: {userId: 9},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
});
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() => {
const userId = 1;
const ctx = {
req: {
accessToken: {userId: userId},
headers: {origin: 'http://localhost:5000'},
}
};
const tx = await models.InvoiceIn.beginTransaction({});
const options = {transaction: tx};
try {
2024-02-02 13:02:16 +00:00
const clone = await models.InvoiceIn.clone(ctx, 1, false, options);
2021-07-23 12:06:48 +00:00
expect(clone.supplierRef).toEqual('1234(2)');
2024-02-02 13:02:16 +00:00
const invoiceIn = await models.InvoiceIn.findOne({
include: [
{
relation: 'invoiceInTax',
},
{
relation: 'invoiceInDueDay',
}
], where: {
id: clone.id
}
}, options);
const invoiceInTax = invoiceIn.invoiceInTax();
const invoiceInDueDay = invoiceIn.invoiceInDueDay();
2021-07-23 12:06:48 +00:00
2024-02-02 13:02:16 +00:00
expect(invoiceInTax.length).toEqual(2);
expect(invoiceInDueDay.length).toEqual(2);
2021-07-23 12:06:48 +00:00
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});