From 4cb82524cb96021c7527f652b0dfc8ebad3170b3 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 4 Jan 2024 08:37:34 +0100 Subject: [PATCH] test: refs #3979 quito clone parametro group porque no se usa --- .../methods/invoiceOut/transferInvoice.js | 2 +- modules/ticket/back/methods/sale/clone.js | 6 ++--- modules/ticket/back/methods/sale/refund.js | 1 - .../back/methods/sale/specs/clone.spec.js | 24 ++++++------------- 4 files changed, 10 insertions(+), 23 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js index dde535c99..2d77705e7 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js @@ -78,7 +78,7 @@ module.exports = Self => { const sales = await models.Sale.find(filterTicket, myOptions); const salesIds = sales.map(sale => sale.id); - const clonedTickets = await models.Sale.clone(ctx, salesIds, servicesIds, null, false, false, myOptions); + const clonedTickets = await models.Sale.clone(ctx, salesIds, servicesIds, null, false, myOptions); const clonedTicketIds = []; for (const clonedTicket of clonedTickets) { diff --git a/modules/ticket/back/methods/sale/clone.js b/modules/ticket/back/methods/sale/clone.js index 233d114cf..661b656df 100644 --- a/modules/ticket/back/methods/sale/clone.js +++ b/modules/ticket/back/methods/sale/clone.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.clone = async(ctx, salesIds, servicesIds, withWarehouse, group, negative, options) => { + Self.clone = async(ctx, salesIds, servicesIds, withWarehouse, negative, options) => { const models = Self.app.models; const myOptions = {}; let tx; @@ -28,8 +28,6 @@ module.exports = Self => { const mappedTickets = new Map(); - if (group) ticketsIds = [ticketsIds[0]]; - for (let ticketId of ticketsIds) { const newTicket = await createTicket( ctx, @@ -43,7 +41,7 @@ module.exports = Self => { } for (const sale of sales) { - const newTicketId = group ? ticketsIds : mappedTickets.get(sale.ticketFk); + const newTicketId = mappedTickets.get(sale.ticketFk); const createdSale = await models.Sale.create({ ticketFk: newTicketId, diff --git a/modules/ticket/back/methods/sale/refund.js b/modules/ticket/back/methods/sale/refund.js index 17b70f12b..c5d0415c0 100644 --- a/modules/ticket/back/methods/sale/refund.js +++ b/modules/ticket/back/methods/sale/refund.js @@ -47,7 +47,6 @@ module.exports = Self => { salesIds, servicesIds, withWarehouse, - false, true, myOptions ); diff --git a/modules/ticket/back/methods/sale/specs/clone.spec.js b/modules/ticket/back/methods/sale/specs/clone.spec.js index b12a7e982..095f94cad 100644 --- a/modules/ticket/back/methods/sale/specs/clone.spec.js +++ b/modules/ticket/back/methods/sale/specs/clone.spec.js @@ -25,16 +25,15 @@ describe('Ticket cloning - clone function', () => { }); afterEach(async() => { - await tx.commit(); + await tx.rollback(); }); it('should create new tickets with cloned sales with warehouse', async() => { const salesIds = [1, 2, 3]; const servicesIds = []; const withWarehouse = true; - const group = false; const negative = false; - const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, withWarehouse, group, negative, options); + const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, withWarehouse, negative, options); expect(newTickets).toBeDefined(); expect(newTickets.length).toBeGreaterThan(0); @@ -43,9 +42,9 @@ describe('Ticket cloning - clone function', () => { it('should handle negative quantities correctly', async() => { const negative = true; const salesIds = [7, 8]; - const newTickets = await models.Sale.clone(ctx, salesIds, [], false, false, negative, options); + const servicesIds = []; + const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, false, negative, options); - // Verify that the cloned sales have negative quantities for (const ticket of newTickets) { const sales = await models.Sale.find({where: {ticketFk: ticket.id}}, options); sales.forEach(sale => { @@ -54,21 +53,11 @@ describe('Ticket cloning - clone function', () => { } }); - it('should group sales into a single ticket if group is true', async() => { - const salesIds = [1, 2, 3, 4, 5]; - const group = true; - const newTickets = await models.Sale.clone(ctx, salesIds, [], false, group, false, options); - - expect(newTickets.length).toEqual(1); - // Additional assertions for ticket grouping - }); - it('should create new components and services for cloned tickets', async() => { const servicesIds = [2]; const salesIds = [5]; - const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, false, false, false, options); + const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, false, false, options); - // Verify that components and services are created for each new ticket for (const ticket of newTickets) { const sale = await models.Sale.findOne({where: {ticketFk: ticket.id}}, options); const components = await models.SaleComponent.find({where: {saleFk: sale.id}}, options); @@ -82,8 +71,9 @@ describe('Ticket cloning - clone function', () => { it('should handle transaction rollback on error', async() => { const negative = true; const salesIds = [1, 2, 3, 4, 5]; + const servicesIds = []; try { - await models.Sale.clone(ctx, salesIds, [], false, false, negative, options); + await models.Sale.clone(ctx, salesIds, servicesIds, false, negative, options); fail('Expected error was not thrown'); } catch (error) { expect(error).toBeDefined();