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

59 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-08-16 12:00:37 +00:00
const app = require(`${servicesDir}/ticket/server/server`);
describe('sale reserve()', () => {
afterAll(async() => {
let params = {
sales: [
{id: 1},
{id: 2},
{id: 3},
{id: 4}],
ticketFk: 1,
reserved: false
};
await app.models.Sale.reserve(params);
});
it('should throw an error if the ticket can not be modified', async() => {
let error;
let params = {actualTicketFk: 10, sales: [{id: 4, instance: 3}]};
await app.models.Sale.reserve(params)
.catch(response => {
expect(response).toEqual(new Error(`The sales of this ticket can't be modified`));
error = response;
});
expect(error).toBeDefined();
});
it('should update the given sales of a ticket as reserved', async() => {
originalTicketSales = await app.models.Ticket.getSales(1);
expect(originalTicketSales[0].reserved).toEqual(0);
expect(originalTicketSales[1].reserved).toEqual(0);
expect(originalTicketSales[2].reserved).toEqual(0);
expect(originalTicketSales[3].reserved).toEqual(0);
let params = {
sales: [
{id: 1},
{id: 2},
{id: 3},
{id: 4}],
ticketFk: 1,
reserved: true
};
await app.models.Sale.reserve(params);
let reservedTicketSales = await app.models.Ticket.getSales(1);
expect(reservedTicketSales[0].reserved).toEqual(1);
expect(reservedTicketSales[1].reserved).toEqual(1);
expect(reservedTicketSales[2].reserved).toEqual(1);
expect(reservedTicketSales[3].reserved).toEqual(1);
});
});