salix/modules/ticket/back/methods/sale/specs/moveToTicket.spec.js

80 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-12-21 11:50:28 +00:00
const app = require(`${serviceRoot}/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 () => {
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 () => {
let error;
let params = {actualTicketFk: 1, newTicketFk: 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 transfer the sales from one ticket to another', async () => {
let senderTicketSales = await app.models.Ticket.getSales(11);
let receiverTicketSales = await app.models.Ticket.getSales(13);
expect(senderTicketSales.length).toEqual(2);
expect(receiverTicketSales.length).toEqual(0);
let params = {
actualTicketFk: 11,
newTicketFk: 13,
sales: [
{id: 7},
{id: 8}]
};
await app.models.Sale.moveToTicket(params);
senderTicketSales = await app.models.Ticket.getSales(11);
receiverTicketSales = await app.models.Ticket.getSales(13);
expect(senderTicketSales.length).toEqual(0);
expect(receiverTicketSales.length).toEqual(2);
});
2018-11-06 12:59:16 +00:00
it('should transfers back the sales', async () => {
let senderTicketSales = await app.models.Ticket.getSales(13);
let receiverTicketSales = await app.models.Ticket.getSales(11);
expect(senderTicketSales.length).toEqual(2);
expect(receiverTicketSales.length).toEqual(0);
let params = {
actualTicketFk: 13,
newTicketFk: 11,
sales: [
{id: 7},
{id: 8}]
};
await app.models.Sale.moveToTicket(params);
senderTicketSales = await app.models.Ticket.getSales(13);
receiverTicketSales = await app.models.Ticket.getSales(11);
expect(senderTicketSales.length).toEqual(0);
expect(receiverTicketSales.length).toEqual(2);
});
});