From c6507fc2bb9cc1062de29b6117461cba35962c95 Mon Sep 17 00:00:00 2001 From: Bernat Date: Fri, 13 Sep 2019 07:40:27 +0200 Subject: [PATCH] #1681 crear test para el endpoint getPossibleStowaways --- .../methods/ticket/getPossibleStowaways.js | 2 +- .../ticket/specs/getPossibleStowaways.spec.js | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 modules/ticket/back/methods/ticket/specs/getPossibleStowaways.spec.js diff --git a/modules/ticket/back/methods/ticket/getPossibleStowaways.js b/modules/ticket/back/methods/ticket/getPossibleStowaways.js index 2f7d1864a..2b3194f86 100644 --- a/modules/ticket/back/methods/ticket/getPossibleStowaways.js +++ b/modules/ticket/back/methods/ticket/getPossibleStowaways.js @@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethod('getPossibleStowaways', { - description: 'Returns mana of a salesperson of a ticket', + description: 'Returns a list of allowed tickets for a stowaway ticket', accessType: 'READ', accepts: [{ arg: 'id', diff --git a/modules/ticket/back/methods/ticket/specs/getPossibleStowaways.spec.js b/modules/ticket/back/methods/ticket/specs/getPossibleStowaways.spec.js new file mode 100644 index 000000000..6a05f69eb --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/getPossibleStowaways.spec.js @@ -0,0 +1,30 @@ +const app = require('vn-loopback/server/server'); +let UserError = require('vn-loopback/util/user-error'); + +describe('ticket getPossibleStowaways()', () => { + it(`should throw an error if Can't create stowaway for this ticket`, async() => { + let error; + let ticketId = 10; + + await app.models.Ticket.getPossibleStowaways(ticketId) + .catch(e => { + error = e; + }); + + expect(error).toEqual(new UserError(`Can't create stowaway for this ticket`)); + }); + // EL TICKET 12 DEVUELVE UNA LISTA VACIA + it('should return an empty list of tickets for a valid ticket', async() => { + let ticketId = 12; + let possibleStowaways = await app.models.Ticket.getPossibleStowaways(ticketId); + + expect(possibleStowaways.length).toEqual(0); + }); + + it('should return allowed list of tickets for a valid ticket', async() => { + let ticketId = 16; + let possibleStowaways = await app.models.Ticket.getPossibleStowaways(ticketId); + + expect(possibleStowaways.length).toEqual(1); + }); +});