salix/services/loopback/common/methods/sale/specs/moveToTicket.spec.js

80 lines
2.5 KiB
JavaScript
Raw Normal View History

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 this ticket can't be modified`);
error = response;
});
expect(error).toBeDefined();
});
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);
});
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);
});
});