Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/dev This commit looks good Details

This commit is contained in:
Juan Ferrer 2019-10-01 13:46:16 +02:00
commit a4892845e0
1 changed files with 27 additions and 26 deletions

View File

@ -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);
});
});
});