From 2e88957c8b7a19575d93c1a3c7bc52c514ffa6be Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Thu, 16 Aug 2018 14:00:37 +0200 Subject: [PATCH] #534 reserve.js Backend unit tests --- .../common/methods/sale/specs/reserve.spec.js | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 services/loopback/common/methods/sale/specs/reserve.spec.js diff --git a/services/loopback/common/methods/sale/specs/reserve.spec.js b/services/loopback/common/methods/sale/specs/reserve.spec.js new file mode 100644 index 000000000..79f2dcfe6 --- /dev/null +++ b/services/loopback/common/methods/sale/specs/reserve.spec.js @@ -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); + }); +});