2021-09-29 06:27:18 +00:00
|
|
|
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'},
|
|
|
|
__: () => {}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
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
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
let error;
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
2019-03-01 10:50:26 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
const ticketId = 2;
|
|
|
|
const sales = [{id: 5}];
|
|
|
|
const reserved = false;
|
2018-08-16 12:00:37 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
await models.Sale.reserve(ctx, ticketId, sales, reserved, options);
|
2018-08-16 12:00:37 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
error = e;
|
|
|
|
}
|
2018-08-16 12:00:37 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
expect(error).toEqual(new Error(`The sales of this ticket can't be modified`));
|
2018-08-16 12:00:37 +00:00
|
|
|
});
|
|
|
|
|
2018-09-21 13:01:51 +00:00
|
|
|
it('should update the given sales of a ticket to reserved', async() => {
|
2021-09-29 06:27:18 +00:00
|
|
|
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
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
expect(originalTicketSales[0].reserved).toEqual(false);
|
|
|
|
expect(originalTicketSales[1].reserved).toEqual(false);
|
2018-08-16 12:00:37 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
const ticketId = 11;
|
|
|
|
const sales = [{id: 7}, {id: 8}];
|
|
|
|
const reserved = true;
|
2018-08-16 12:00:37 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
await models.Sale.reserve(ctx, ticketId, sales, reserved, options);
|
2018-08-16 12:00:37 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
const reservedTicketSales = await models.Ticket.getSales(ticketId, options);
|
2018-08-16 12:00:37 +00:00
|
|
|
|
2021-09-29 06:27:18 +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
|
|
|
});
|
|
|
|
});
|