84 lines
2.6 KiB
JavaScript
84 lines
2.6 KiB
JavaScript
|
const app = require(`${servicesDir}/ticket/server/server`);
|
||
|
|
||
|
describe('sale moveToTicket()', () => {
|
||
|
it('should throw an error if the ticket is not editable', async() => {
|
||
|
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();
|
||
|
});
|
||
|
|
||
|
it('should throw an error if the receiving ticket is not editable', async() => {
|
||
|
let error;
|
||
|
|
||
|
let params = {actualTicketFk: 1, newTicketFk: 10};
|
||
|
|
||
|
await app.models.Sale.moveToTicket(params)
|
||
|
.catch(response => {
|
||
|
expect(response.message).toEqual(`The sales of that ticket can't be modified`);
|
||
|
error = response;
|
||
|
});
|
||
|
|
||
|
expect(error).toBeDefined();
|
||
|
});
|
||
|
|
||
|
it('should transfer the sales from ticket 1 to ticket 13', async() => {
|
||
|
let senderTicketSales = await app.models.Ticket.getSales(1);
|
||
|
let receiverTicketSales = await app.models.Ticket.getSales(13);
|
||
|
|
||
|
expect(senderTicketSales.length).toEqual(4);
|
||
|
expect(receiverTicketSales.length).toEqual(0);
|
||
|
|
||
|
let params = {
|
||
|
actualTicketFk: 1,
|
||
|
newTicketFk: 13,
|
||
|
sales: [
|
||
|
{id: 1},
|
||
|
{id: 2},
|
||
|
{id: 3},
|
||
|
{id: 4}]
|
||
|
};
|
||
|
|
||
|
await app.models.Sale.moveToTicket(params);
|
||
|
|
||
|
senderTicketSales = await app.models.Ticket.getSales(1);
|
||
|
receiverTicketSales = await app.models.Ticket.getSales(13);
|
||
|
|
||
|
expect(senderTicketSales.length).toEqual(0);
|
||
|
expect(receiverTicketSales.length).toEqual(4);
|
||
|
});
|
||
|
|
||
|
it('should transfer the sales back from ticket 13 to ticket 1', async() => {
|
||
|
let senderTicketSales = await app.models.Ticket.getSales(13);
|
||
|
let receiverTicketSales = await app.models.Ticket.getSales(1);
|
||
|
|
||
|
expect(senderTicketSales.length).toEqual(4);
|
||
|
expect(receiverTicketSales.length).toEqual(0);
|
||
|
|
||
|
let params = {
|
||
|
actualTicketFk: 13,
|
||
|
newTicketFk: 1,
|
||
|
sales: [
|
||
|
{id: 1},
|
||
|
{id: 2},
|
||
|
{id: 3},
|
||
|
{id: 4}]
|
||
|
};
|
||
|
|
||
|
await app.models.Sale.moveToTicket(params);
|
||
|
|
||
|
senderTicketSales = await app.models.Ticket.getSales(13);
|
||
|
receiverTicketSales = await app.models.Ticket.getSales(1);
|
||
|
|
||
|
expect(senderTicketSales.length).toEqual(0);
|
||
|
expect(receiverTicketSales.length).toEqual(4);
|
||
|
});
|
||
|
});
|