diff --git a/modules/ticket/back/methods/ticket/specs/transferSales.spec.js b/modules/ticket/back/methods/ticket/specs/transferSales.spec.js index 8894c92d8..75823f00a 100644 --- a/modules/ticket/back/methods/ticket/specs/transferSales.spec.js +++ b/modules/ticket/back/methods/ticket/specs/transferSales.spec.js @@ -135,44 +135,45 @@ describe('sale transferSales()', () => { expect(error).toBeDefined(); }); - xit('should partially transfer the sales from one ticket to a new one', async() => { + it('should transfer two sales to a new ticket but one shall be partial', async() => { const ctx = {req: {accessToken: {userId: 101}}}; - let currentTicket = await app.models.Ticket.findById(11); - let currentTicketSales = []; - let saleToRestore = await app.models.Sale.findById(7); - currentTicketSales.push(saleToRestore); - - expect(currentTicketSales[0].quantity).toEqual(15); - - const currentTicketId = currentTicket.id; + const originalTicketId = 11; const receiverTicketId = undefined; - const originalQuantity = currentTicketSales[0].quantity; + let currentTicketSales = await app.models.Ticket.getSales(originalTicketId); + + const originalPartialSaleId = currentTicketSales[0].id; + const originalCompleteSaleId = currentTicketSales[1].id; + let originalQuantity = currentTicketSales[0].quantity; currentTicketSales[0].quantity = 1; - let salesToPartiallyTransfer = [currentTicketSales[0]]; - const saleIdToRestore = currentTicketSales[0].id; let createdTicket = await app.models.Ticket.transferSales( - ctx, currentTicketId, receiverTicketId, salesToPartiallyTransfer); + ctx, originalTicketId, receiverTicketId, currentTicketSales); createdTicketId = createdTicket.id; createdTicketsIds.push(createdTicket.id); - currentTicketSales = await app.models.Ticket.getSales(currentTicket.id); - receiverTicketSales = await app.models.Ticket.getSales(createdTicket.id); + currentTicketSales = await app.models.Ticket.getSales(originalTicketId); + receiverTicketSales = await app.models.Ticket.getSales(createdTicketId); + + const [createdPartialSale] = receiverTicketSales.filter(sale => { + return sale.id != originalCompleteSaleId; + }); + + expect(currentTicketSales.length).toEqual(1); + expect(currentTicketSales[0].quantity).toEqual(originalQuantity -= 1); + expect(receiverTicketSales.length).toEqual(2); + expect(createdPartialSale.quantity).toEqual(1); + + let saleToRestore = await app.models.Sale.findById(originalPartialSaleId); + await saleToRestore.updateAttribute('quantity', originalQuantity); + + let saleToReturnToTicket = await app.models.Sale.findById(originalCompleteSaleId); + await saleToReturnToTicket.updateAttribute('ticketFk', originalTicketId); + + currentTicketSales = await app.models.Ticket.getSales(originalTicketId); expect(currentTicketSales.length).toEqual(2); - expect(currentTicketSales[0].quantity).toEqual(14); - expect(receiverTicketSales.length).toEqual(1); - expect(receiverTicketSales[0].quantity).toEqual(1); - - saleToRestore.updateAttribute('quantity', originalQuantity); - - currentTicketSales = await app.models.Ticket.getSales(currentTicket.id); - - - expect(currentTicketSales[0].quantity).toEqual(15); - expect(currentTicketSales[0].id).toEqual(saleIdToRestore); }); }); });