#534 reserve.js Backend unit tests

This commit is contained in:
Carlos Jimenez 2018-08-16 14:00:37 +02:00
parent 51e5e76edd
commit 2e88957c8b
1 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,58 @@
const app = require(`${servicesDir}/ticket/server/server`);
describe('sale reserve()', () => {
afterAll(async() => {
let params = {
sales: [
{id: 1},
{id: 2},
{id: 3},
{id: 4}],
ticketFk: 1,
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 = {actualTicketFk: 10, sales: [{id: 4, instance: 3}]};
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 as reserved', async() => {
originalTicketSales = await app.models.Ticket.getSales(1);
expect(originalTicketSales[0].reserved).toEqual(0);
expect(originalTicketSales[1].reserved).toEqual(0);
expect(originalTicketSales[2].reserved).toEqual(0);
expect(originalTicketSales[3].reserved).toEqual(0);
let params = {
sales: [
{id: 1},
{id: 2},
{id: 3},
{id: 4}],
ticketFk: 1,
reserved: true
};
await app.models.Sale.reserve(params);
let reservedTicketSales = await app.models.Ticket.getSales(1);
expect(reservedTicketSales[0].reserved).toEqual(1);
expect(reservedTicketSales[1].reserved).toEqual(1);
expect(reservedTicketSales[2].reserved).toEqual(1);
expect(reservedTicketSales[3].reserved).toEqual(1);
});
});