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

63 lines
1.8 KiB
JavaScript
Raw Normal View History

const models = require('vn-loopback/server/server').models;
2018-08-16 12:00:37 +00:00
describe('sale reserve()', () => {
2021-07-29 15:40:45 +00:00
const ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
it('should throw an error if the ticket can not be modified', async() => {
const tx = await models.Sale.beginTransaction({});
2018-08-16 12:00:37 +00:00
let error;
try {
const options = {transaction: tx};
const ticketId = 2;
const sales = [{id: 5}];
const reserved = false;
2018-08-16 12:00:37 +00:00
await models.Sale.reserve(ctx, ticketId, sales, reserved, options);
2018-08-16 12:00:37 +00:00
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
2018-08-16 12:00:37 +00:00
expect(error).toEqual(new Error(`The sales of this ticket can't be modified`));
2018-08-16 12:00:37 +00:00
});
it('should update the given sales of a ticket to reserved', async() => {
const tx = await models.Sale.beginTransaction({});
try {
const options = {transaction: tx};
originalTicketSales = await models.Ticket.getSales(11, options);
2018-08-16 12:00:37 +00:00
expect(originalTicketSales[0].reserved).toEqual(false);
expect(originalTicketSales[1].reserved).toEqual(false);
2018-08-16 12:00:37 +00:00
const ticketId = 11;
const sales = [{id: 7}, {id: 8}];
const reserved = true;
2018-08-16 12:00:37 +00:00
await models.Sale.reserve(ctx, ticketId, sales, reserved, options);
2018-08-16 12:00:37 +00:00
const reservedTicketSales = await models.Ticket.getSales(ticketId, options);
2018-08-16 12:00:37 +00:00
expect(reservedTicketSales[0].reserved).toEqual(true);
expect(reservedTicketSales[1].reserved).toEqual(true);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
2018-08-16 12:00:37 +00:00
});
});