60 lines
1.7 KiB
JavaScript
60 lines
1.7 KiB
JavaScript
const app = require('vn-loopback/server/server');
|
|
|
|
describe('sale reserve()', () => {
|
|
const ctx = {
|
|
req: {
|
|
accessToken: {userId: 9},
|
|
headers: {origin: 'localhost:5000'},
|
|
__: () => {}
|
|
}
|
|
};
|
|
|
|
afterAll(async done => {
|
|
let ctx = {req: {accessToken: {userId: 9}}};
|
|
let params = {
|
|
sales: [
|
|
{id: 7},
|
|
{id: 8}],
|
|
ticketFk: 11,
|
|
reserved: false
|
|
};
|
|
|
|
await app.models.Sale.reserve(ctx, params);
|
|
|
|
done();
|
|
});
|
|
|
|
it('should throw an error if the ticket can not be modified', async() => {
|
|
let error;
|
|
const ticketId = 2;
|
|
const sales = [{id: 5}];
|
|
const reserved = false;
|
|
|
|
await app.models.Sale.reserve(ctx, ticketId, sales, reserved)
|
|
.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(false);
|
|
expect(originalTicketSales[1].reserved).toEqual(false);
|
|
|
|
const ticketId = 11;
|
|
const sales = [{id: 7}, {id: 8}];
|
|
const reserved = true;
|
|
|
|
await app.models.Sale.reserve(ctx, ticketId, sales, reserved);
|
|
|
|
const reservedTicketSales = await app.models.Ticket.getSales(ticketId);
|
|
|
|
expect(reservedTicketSales[0].reserved).toEqual(true);
|
|
expect(reservedTicketSales[1].reserved).toEqual(true);
|
|
});
|
|
});
|