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

53 lines
1.4 KiB
JavaScript

const app = require('vn-loopback/server/server');
describe('sale reserve()', () => {
afterAll(async() => {
let params = {
sales: [
{id: 7},
{id: 8}],
ticketFk: 11,
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 = {ticketFk: 2,
sales: [{id: 5}],
reserved: false};
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 to reserved', async() => {
originalTicketSales = await app.models.Ticket.getSales(11);
expect(originalTicketSales[0].reserved).toEqual(0);
expect(originalTicketSales[1].reserved).toEqual(0);
let params = {
sales: [
{id: 7},
{id: 8}],
ticketFk: 11,
reserved: true
};
await app.models.Sale.reserve(params);
let reservedTicketSales = await app.models.Ticket.getSales(11);
expect(reservedTicketSales[0].reserved).toEqual(1);
expect(reservedTicketSales[1].reserved).toEqual(1);
});
});