diff --git a/back/methods/collection/spec/assignCollection.spec.js b/back/methods/collection/spec/assignCollection.spec.js index e8f3882a3..7cdcd6cb6 100644 --- a/back/methods/collection/spec/assignCollection.spec.js +++ b/back/methods/collection/spec/assignCollection.spec.js @@ -15,9 +15,7 @@ describe('ticket assignCollection()', () => { args: {} }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx.req - }); + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: ctx.req}); options = {transaction: tx}; tx = await models.Sale.beginTransaction({}); @@ -25,7 +23,7 @@ describe('ticket assignCollection()', () => { }); afterEach(async() => { - await tx.rollback(); + if (tx) await tx.rollback(); }); it('should throw an error when there is not picking tickets', async() => { diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/refundAndInvoice.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/refundAndInvoice.spec.js index 46cc4458b..c54ae5f6c 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/refundAndInvoice.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/refundAndInvoice.spec.js @@ -14,7 +14,7 @@ describe('InvoiceOut refundAndInvoice()', () => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: activeCtx}); }); - fit('should refund an invoice and create a new invoice', async() => { + it('should refund an invoice and create a new invoice', async() => { const tx = await models.InvoiceOut.beginTransaction({}); const options = {transaction: tx}; diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/transfer.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/transfer.spec.js index 5aeb92ec3..f8a43dc2f 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/transfer.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/transfer.spec.js @@ -2,16 +2,11 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); const UserError = require('vn-loopback/util/user-error'); -describe('InvoiceOut transfer()', () => { +fdescribe('InvoiceOut transfer()', () => { const userId = 5; - const ctx = { - req: { - accessToken: {userId}, - __: (key, obj) => `Translated: ${key}, ${JSON.stringify(obj)}`, - getLocale: () => 'es' - }, - args: {} - }; + let options; + let tx; + let ctx; const activeCtx = {accessToken: {userId}}; const id = 4; const newClientFk = 1101; @@ -19,13 +14,28 @@ describe('InvoiceOut transfer()', () => { const siiTypeInvoiceOutFk = 1; const invoiceCorrectionTypeFk = 1; - beforeEach(() => { + beforeEach(async() => { + ctx = { + req: { + accessToken: {userId: 1106}, + headers: {origin: 'http://localhost'}, + __: value => value, + getLocale: () => 'es' + }, + args: {} + }; + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: activeCtx}); + options = {transaction: tx}; + tx = await models.Sale.beginTransaction({}); + options.transaction = tx; + }); + + afterEach(async() => { + await tx.rollback(); }); it('should transfer an invoice to a new client and return the new invoice ID', async() => { - const tx = await models.InvoiceOut.beginTransaction({}); - const options = {transaction: tx}; const makeInvoice = true; try { @@ -45,7 +55,7 @@ describe('InvoiceOut transfer()', () => { const transferredTickets = await models.Ticket.find({ where: { - invoiceOutFk: result, + refFk: result, clientFk: newClientFk } }, options); @@ -60,8 +70,6 @@ describe('InvoiceOut transfer()', () => { }); it('should throw an error if original invoice is not found', async() => { - const tx = await models.InvoiceOut.beginTransaction({}); - const options = {transaction: tx}; const makeInvoice = true; try { await models.InvoiceOut.transfer( @@ -83,8 +91,6 @@ describe('InvoiceOut transfer()', () => { }); it('should throw an error if the new client is the same as the original client', async() => { - const tx = await models.InvoiceOut.beginTransaction({}); - const options = {transaction: tx}; const makeInvoice = true; const originalInvoice = await models.InvoiceOut.findById(id); @@ -107,40 +113,31 @@ describe('InvoiceOut transfer()', () => { } }); - it('should not create a new invoice if makeInvoice is false', async() => { - const tx = await models.InvoiceOut.beginTransaction({}); - const options = {transaction: tx}; + fit('should not create a new invoice if makeInvoice is false', async() => { + const originalTickets = await models.Ticket.find({ + where: {clientFk: newClientFk, refFk: null}, + options + }); - try { - const originalTickets = await models.Ticket.find({ - where: {clientFk: newClientFk, invoiceOutFk: null}, - options - }); + const result = await models.InvoiceOut.transfer( + ctx, + id, + newClientFk, + cplusRectificationTypeFk, + siiTypeInvoiceOutFk, + invoiceCorrectionTypeFk, + false, + options + ); - const result = await models.InvoiceOut.transfer( - ctx, - id, - newClientFk, - cplusRectificationTypeFk, - siiTypeInvoiceOutFk, - invoiceCorrectionTypeFk, - false, - options - ); + expect(result).toBeUndefined(); - expect(result).toBeUndefined(); + // await tx.commit(); + const transferredTickets = await models.Ticket.find({ + where: {clientFk: newClientFk, refFk: null}, + options + }); - const transferredTickets = await models.Ticket.find({ - where: {clientFk: newClientFk, invoiceOutFk: null}, - options - }); - - expect(transferredTickets.length).toBeGreaterThan(originalTickets.length); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + expect(transferredTickets.length).toBeGreaterThan(originalTickets.length); }); });