feat: refs # test corrective & clone
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
cd73e5adfe
commit
a0c5b1fff6
|
@ -2,34 +2,33 @@ const models = require('vn-loopback/server/server').models;
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('invoiceIn clone()', () => {
|
describe('invoiceIn clone()', () => {
|
||||||
beforeAll(async() => {
|
let ctx;
|
||||||
const activeCtx = {
|
let options;
|
||||||
accessToken: {userId: 9},
|
let tx;
|
||||||
http: {
|
|
||||||
|
beforeEach(async() => {
|
||||||
|
ctx = {
|
||||||
req: {
|
req: {
|
||||||
|
accessToken: {userId: 1},
|
||||||
headers: {origin: 'http://localhost'}
|
headers: {origin: 'http://localhost'}
|
||||||
}
|
},
|
||||||
}
|
args: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
active: activeCtx
|
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() => {
|
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, false, options);
|
const clone = await models.InvoiceIn.clone(ctx, 1, false, options);
|
||||||
|
|
||||||
expect(clone.supplierRef).toEqual('1234(2)');
|
expect(clone.supplierRef).toEqual('1234(2)');
|
||||||
|
@ -50,11 +49,28 @@ describe('invoiceIn clone()', () => {
|
||||||
|
|
||||||
expect(invoiceInTax.length).toEqual(2);
|
expect(invoiceInTax.length).toEqual(2);
|
||||||
expect(invoiceInDueDay.length).toEqual(2);
|
expect(invoiceInDueDay.length).toEqual(2);
|
||||||
|
});
|
||||||
|
|
||||||
await tx.rollback();
|
it('should return the cloned invoiceIn and also clone invoiceInIntrastat and invoiceInTaxes if it is rectificative', async() => {
|
||||||
} catch (e) {
|
const clone = await models.InvoiceIn.clone(ctx, 1, true, options);
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
|
describe('invoiceIn corrective()', () => {
|
||||||
|
let ctx;
|
||||||
|
let options;
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
beforeEach(async() => {
|
||||||
|
ctx = {
|
||||||
|
req: {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
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('La función corrective debería devolver un id cuando se ejecuta correctamente', async() => {
|
||||||
|
const originalId = 1;
|
||||||
|
const invoiceReason = 3;
|
||||||
|
const invoiceType = 2;
|
||||||
|
const invoiceClass = 1;
|
||||||
|
const cloneId = await models.InvoiceIn.corrective(ctx,
|
||||||
|
originalId, invoiceReason, invoiceType, invoiceClass, options);
|
||||||
|
|
||||||
|
expect(cloneId).toBeDefined();
|
||||||
|
|
||||||
|
const correction = await models.InvoiceInCorrection.findOne({
|
||||||
|
where: {correctedFk: originalId, correctingFk: cloneId}
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
expect(correction.cplusRectificationTypeFk).toEqual(invoiceType);
|
||||||
|
expect(correction.siiTypeInvoiceOutFk).toEqual(invoiceClass);
|
||||||
|
expect(correction.invoiceCorrectionTypeFk).toEqual(invoiceReason);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue