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,59 +2,75 @@ const models = require('vn-loopback/server/server').models;
|
|||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('invoiceIn clone()', () => {
|
||||
beforeAll(async() => {
|
||||
const activeCtx = {
|
||||
accessToken: {userId: 9},
|
||||
http: {
|
||||
req: {
|
||||
headers: {origin: 'http://localhost'}
|
||||
}
|
||||
}
|
||||
let ctx;
|
||||
let options;
|
||||
let tx;
|
||||
|
||||
beforeEach(async() => {
|
||||
ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 1},
|
||||
headers: {origin: 'http://localhost'}
|
||||
},
|
||||
args: {}
|
||||
};
|
||||
|
||||
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() => {
|
||||
const userId = 1;
|
||||
const ctx = {
|
||||
req: {
|
||||
const clone = await models.InvoiceIn.clone(ctx, 1, false, options);
|
||||
|
||||
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);
|
||||
|
||||
expect(clone.supplierRef).toEqual('1234(2)');
|
||||
const invoiceIn = await models.InvoiceIn.findOne({
|
||||
include: [
|
||||
{
|
||||
relation: 'invoiceInTax',
|
||||
},
|
||||
{
|
||||
relation: 'invoiceInDueDay',
|
||||
}
|
||||
], where: {
|
||||
id: clone.id
|
||||
expect(clone.supplierRef).toEqual('1234(2)');
|
||||
const invoiceIn = await models.InvoiceIn.findOne({
|
||||
include: [
|
||||
{
|
||||
relation: 'invoiceInTax',
|
||||
},
|
||||
{
|
||||
relation: 'invoiceInDueDay',
|
||||
}
|
||||
}, options);
|
||||
const invoiceInTax = invoiceIn.invoiceInTax();
|
||||
const invoiceInDueDay = invoiceIn.invoiceInDueDay();
|
||||
], where: {
|
||||
id: clone.id
|
||||
}
|
||||
}, options);
|
||||
const invoiceInTax = invoiceIn.invoiceInTax();
|
||||
const invoiceInDueDay = invoiceIn.invoiceInDueDay();
|
||||
|
||||
expect(invoiceInTax.length).toEqual(2);
|
||||
expect(invoiceInDueDay.length).toEqual(2);
|
||||
expect(invoiceInTax.length).toEqual(2);
|
||||
expect(invoiceInDueDay.length).toEqual(2);
|
||||
});
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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