2018-08-17 11:23:07 +00:00
|
|
|
const app = require(`${servicesDir}/ticket/server/server`);
|
|
|
|
|
|
|
|
describe('sale moveToTicket()', () => {
|
2018-11-06 12:59:16 +00:00
|
|
|
it('should throw an error if the ticket is not editable', async () => {
|
2018-08-17 11:23:07 +00:00
|
|
|
let error;
|
|
|
|
|
|
|
|
let params = {actualTicketFk: 10};
|
|
|
|
|
|
|
|
await app.models.Sale.moveToTicket(params)
|
|
|
|
.catch(response => {
|
|
|
|
expect(response.message).toEqual(`The sales of this ticket can't be modified`);
|
|
|
|
error = response;
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2018-11-06 12:59:16 +00:00
|
|
|
it('should throw an error if the receiving ticket is not editable', async () => {
|
2018-08-17 11:23:07 +00:00
|
|
|
let error;
|
|
|
|
|
|
|
|
let params = {actualTicketFk: 1, newTicketFk: 10};
|
|
|
|
|
|
|
|
await app.models.Sale.moveToTicket(params)
|
|
|
|
.catch(response => {
|
2018-09-21 13:01:51 +00:00
|
|
|
expect(response.message).toEqual(`The sales of this ticket can't be modified`);
|
2018-08-17 11:23:07 +00:00
|
|
|
error = response;
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2018-11-06 12:59:16 +00:00
|
|
|
it('should transfer the sales from one ticket to another', async () => {
|
2018-09-21 13:01:51 +00:00
|
|
|
let senderTicketSales = await app.models.Ticket.getSales(11);
|
2018-08-17 11:23:07 +00:00
|
|
|
let receiverTicketSales = await app.models.Ticket.getSales(13);
|
|
|
|
|
2018-09-21 13:01:51 +00:00
|
|
|
expect(senderTicketSales.length).toEqual(2);
|
2018-08-17 11:23:07 +00:00
|
|
|
expect(receiverTicketSales.length).toEqual(0);
|
|
|
|
|
|
|
|
let params = {
|
2018-09-21 13:01:51 +00:00
|
|
|
actualTicketFk: 11,
|
2018-08-17 11:23:07 +00:00
|
|
|
newTicketFk: 13,
|
|
|
|
sales: [
|
2018-09-21 13:01:51 +00:00
|
|
|
{id: 7},
|
|
|
|
{id: 8}]
|
2018-08-17 11:23:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
await app.models.Sale.moveToTicket(params);
|
|
|
|
|
2018-09-21 13:01:51 +00:00
|
|
|
senderTicketSales = await app.models.Ticket.getSales(11);
|
2018-08-17 11:23:07 +00:00
|
|
|
receiverTicketSales = await app.models.Ticket.getSales(13);
|
|
|
|
|
|
|
|
expect(senderTicketSales.length).toEqual(0);
|
2018-09-21 13:01:51 +00:00
|
|
|
expect(receiverTicketSales.length).toEqual(2);
|
2018-08-17 11:23:07 +00:00
|
|
|
});
|
|
|
|
|
2018-11-06 12:59:16 +00:00
|
|
|
it('should transfers back the sales', async () => {
|
2018-08-17 11:23:07 +00:00
|
|
|
let senderTicketSales = await app.models.Ticket.getSales(13);
|
2018-09-21 13:01:51 +00:00
|
|
|
let receiverTicketSales = await app.models.Ticket.getSales(11);
|
2018-08-17 11:23:07 +00:00
|
|
|
|
2018-09-21 13:01:51 +00:00
|
|
|
expect(senderTicketSales.length).toEqual(2);
|
2018-08-17 11:23:07 +00:00
|
|
|
expect(receiverTicketSales.length).toEqual(0);
|
|
|
|
|
|
|
|
let params = {
|
|
|
|
actualTicketFk: 13,
|
2018-09-21 13:01:51 +00:00
|
|
|
newTicketFk: 11,
|
2018-08-17 11:23:07 +00:00
|
|
|
sales: [
|
2018-09-21 13:01:51 +00:00
|
|
|
{id: 7},
|
|
|
|
{id: 8}]
|
2018-08-17 11:23:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
await app.models.Sale.moveToTicket(params);
|
|
|
|
|
|
|
|
senderTicketSales = await app.models.Ticket.getSales(13);
|
2018-09-21 13:01:51 +00:00
|
|
|
receiverTicketSales = await app.models.Ticket.getSales(11);
|
2018-08-17 11:23:07 +00:00
|
|
|
|
|
|
|
expect(senderTicketSales.length).toEqual(0);
|
2018-09-21 13:01:51 +00:00
|
|
|
expect(receiverTicketSales.length).toEqual(2);
|
2018-08-17 11:23:07 +00:00
|
|
|
});
|
|
|
|
});
|