From b5d2d534350b4281c2b581415197130531ea0f23 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 16 Feb 2023 10:45:13 +0100 Subject: [PATCH] fix: test back --- .../back/methods/invoiceOut/specs/refund.spec.js | 2 +- modules/ticket/back/methods/sale/refund.js | 6 +++--- modules/ticket/back/methods/sale/specs/refund.spec.js | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/refund.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/refund.spec.js index 628318d42..c5a1ac603 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/refund.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/refund.spec.js @@ -17,7 +17,7 @@ describe('InvoiceOut refund()', () => { try { const result = await models.InvoiceOut.refund('T1111111', options); - expect(result.length).toEqual(2); + expect(result.length).toEqual(1); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/sale/refund.js b/modules/ticket/back/methods/sale/refund.js index 3558be15a..7b63fd66e 100644 --- a/modules/ticket/back/methods/sale/refund.js +++ b/modules/ticket/back/methods/sale/refund.js @@ -97,7 +97,7 @@ module.exports = Self => { } for (const sale of sales) { - const refundTicketId = await getTicketRefundId(createSingleTicket, sale.ticketFk, refundTickets); + const refundTicketId = await getTicketRefundId(createSingleTicket, sale.ticketFk, refundTickets, mappedTickets); const createdSale = await models.Sale.create({ ticketFk: refundTicketId, @@ -122,7 +122,7 @@ module.exports = Self => { const services = await models.TicketService.find(servicesFilter, myOptions); for (const service of services) { - const refundTicketId = await getTicketRefundId(createSingleTicket, service.ticketFk, refundTickets); + const refundTicketId = await getTicketRefundId(createSingleTicket, service.ticketFk, refundTickets, mappedTickets); await models.TicketService.create({ description: service.description, @@ -180,7 +180,7 @@ module.exports = Self => { }, myOptions); } - async function getTicketRefundId(createSingleTicket, ticketId, refundTickets) { + async function getTicketRefundId(createSingleTicket, ticketId, refundTickets, mappedTickets) { if (createSingleTicket) { const [firstRefundTicket] = refundTickets; return firstRefundTicket.id; diff --git a/modules/ticket/back/methods/sale/specs/refund.spec.js b/modules/ticket/back/methods/sale/specs/refund.spec.js index 74077cf29..403b4b477 100644 --- a/modules/ticket/back/methods/sale/specs/refund.spec.js +++ b/modules/ticket/back/methods/sale/specs/refund.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); -describe('sale refund()', () => { +describe('Sale refund()', () => { const userId = 5; const activeCtx = { accessToken: {userId: userId}, @@ -22,7 +22,7 @@ describe('sale refund()', () => { try { const options = {transaction: tx}; - const response = await models.Sale.refund(salesIds, servicesIds, options); + const response = await models.Sale.refund(salesIds, servicesIds, false, options); expect(response.length).toBeGreaterThanOrEqual(1); @@ -40,7 +40,8 @@ describe('sale refund()', () => { try { const options = {transaction: tx}; - const tickets = await models.Sale.refund(salesIds, servicesIds, options); + const createSingleTicket = false; + const tickets = await models.Sale.refund(salesIds, servicesIds, createSingleTicket, options); const ticketsIds = tickets.map(ticket => ticket.id);