From 05ae6bd5340a403ab63aed119b7a37e2d7320089 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Wed, 22 Aug 2018 09:20:34 +0200 Subject: [PATCH] #548 ticket/summary.js Backend unit tests --- .../methods/ticket/specs/summary.spec.js | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/services/loopback/common/methods/ticket/specs/summary.spec.js b/services/loopback/common/methods/ticket/specs/summary.spec.js index a75825181..f616d9fe7 100644 --- a/services/loopback/common/methods/ticket/specs/summary.spec.js +++ b/services/loopback/common/methods/ticket/specs/summary.spec.js @@ -1,12 +1,35 @@ -// const app = require(`${servicesDir}/ticket/server/server`); +const app = require(`${servicesDir}/ticket/server/server`); -// describe('ticket summary()', () => { -// describe('getTicketData()', () => { -// it('should sum all sales price', done => { -// let result = getTicketData(model, 1); +describe('ticket summary()', () => { + it('should return a summary object containing data from 1 ticket', async() => { + let result = await app.models.Ticket.summary(1); -// expect(result).toEqual("pepinillos"); -// done(); -// }); -// }); -// }); + expect(result.id).toEqual(1); + expect(result.nickname).toEqual('Batman'); + }); + + it('should return a summary object containing sales from 1 ticket', async() => { + let result = await app.models.Ticket.summary(1); + + expect(result.sales.length).toEqual(4); + }); + + it('should return a summary object containing subTotal for 1 ticket', async() => { + let result = await app.models.Ticket.summary(1); + + expect(result.subTotal).toEqual(389.5); + }); + + it('should return a summary object containing VAT for 1 ticket', async() => { + let result = await app.models.Ticket.summary(1); + + expect(result.VAT).toEqual(58.75); + }); + + it('should return a summary object containing total for 1 ticket', async() => { + let result = await app.models.Ticket.summary(1); + let expectedTotal = result.subTotal + result.VAT; + + expect(result.total).toEqual(expectedTotal); + }); +});