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()', () => {
|
2023-04-12 10:33:14 +00:00
|
|
|
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 {
|
|
|
|
const clone = await models.InvoiceIn.clone(ctx, 1, options);
|
|
|
|
|
2021-09-07 09:55:26 +00:00
|
|
|
expect(clone.supplierRef).toEqual('1234(2)');
|
2021-07-23 12:06:48 +00:00
|
|
|
|
|
|
|
const invoiceInTaxes = await models.InvoiceInTax.find({where: {invoiceInFk: clone.id}}, options);
|
|
|
|
|
2021-08-12 05:39:26 +00:00
|
|
|
expect(invoiceInTaxes.length).toEqual(2);
|
2021-07-23 12:06:48 +00:00
|
|
|
|
|
|
|
const invoiceInDueDays = await models.InvoiceInDueDay.find({where: {invoiceInFk: clone.id}}, options);
|
|
|
|
|
|
|
|
expect(invoiceInDueDays.length).toEqual(2);
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|