2019-01-24 08:08:28 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2018-08-16 12:00:37 +00:00
|
|
|
|
|
|
|
describe('sale reserve()', () => {
|
2020-07-01 12:28:05 +00:00
|
|
|
const ctx = {req: {accessToken: {userId: 9}}};
|
2019-03-01 10:50:26 +00:00
|
|
|
afterAll(async done => {
|
2019-07-22 11:14:00 +00:00
|
|
|
let ctx = {req: {accessToken: {userId: 9}}};
|
2018-08-16 12:00:37 +00:00
|
|
|
let params = {
|
|
|
|
sales: [
|
2018-09-21 13:01:51 +00:00
|
|
|
{id: 7},
|
|
|
|
{id: 8}],
|
|
|
|
ticketFk: 11,
|
2018-08-16 12:00:37 +00:00
|
|
|
reserved: false
|
|
|
|
};
|
|
|
|
|
2019-07-22 11:14:00 +00:00
|
|
|
await app.models.Sale.reserve(ctx, params);
|
2019-03-01 10:50:26 +00:00
|
|
|
|
|
|
|
done();
|
2018-08-16 12:00:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw an error if the ticket can not be modified', async() => {
|
|
|
|
let error;
|
2020-07-01 12:28:05 +00:00
|
|
|
const ticketId = 2;
|
|
|
|
const sales = [{id: 5}];
|
|
|
|
const reserved = false;
|
2018-08-16 12:00:37 +00:00
|
|
|
|
2020-07-01 12:28:05 +00:00
|
|
|
await app.models.Sale.reserve(ctx, ticketId, sales, reserved)
|
2018-08-16 12:00:37 +00:00
|
|
|
.catch(response => {
|
|
|
|
expect(response).toEqual(new Error(`The sales of this ticket can't be modified`));
|
|
|
|
error = response;
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2018-09-21 13:01:51 +00:00
|
|
|
it('should update the given sales of a ticket to reserved', async() => {
|
|
|
|
originalTicketSales = await app.models.Ticket.getSales(11);
|
2018-08-16 12:00:37 +00:00
|
|
|
|
|
|
|
expect(originalTicketSales[0].reserved).toEqual(0);
|
|
|
|
expect(originalTicketSales[1].reserved).toEqual(0);
|
|
|
|
|
2020-07-01 12:28:05 +00:00
|
|
|
const ticketId = 11;
|
|
|
|
const sales = [{id: 7}, {id: 8}];
|
|
|
|
const reserved = true;
|
2018-08-16 12:00:37 +00:00
|
|
|
|
2020-07-01 12:28:05 +00:00
|
|
|
await app.models.Sale.reserve(ctx, ticketId, sales, reserved);
|
2018-08-16 12:00:37 +00:00
|
|
|
|
2020-07-01 12:28:05 +00:00
|
|
|
const reservedTicketSales = await app.models.Ticket.getSales(ticketId);
|
2018-08-16 12:00:37 +00:00
|
|
|
|
|
|
|
expect(reservedTicketSales[0].reserved).toEqual(1);
|
|
|
|
expect(reservedTicketSales[1].reserved).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|