From e925146c73266515ed32c4dfb6784db5484e0cf9 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Tue, 21 Aug 2018 08:08:39 +0200 Subject: [PATCH] #547 ticket/new.js Backend unit tests plus order new refactor --- .../common/methods/ticket/specs/new.spec.js | 33 +++++++++++++++++++ .../common/methods/order/specs/new.spec.js | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 services/loopback/common/methods/ticket/specs/new.spec.js diff --git a/services/loopback/common/methods/ticket/specs/new.spec.js b/services/loopback/common/methods/ticket/specs/new.spec.js new file mode 100644 index 000000000..1f4639403 --- /dev/null +++ b/services/loopback/common/methods/ticket/specs/new.spec.js @@ -0,0 +1,33 @@ +const app = require(`${servicesDir}/ticket/server/server`); + +describe('ticket new()', () => { + it('should throw an error if the address doesnt exist', async() => { + let error; + let params = {addressFk: 'invalid address', clientFk: 101}; + + await app.models.Ticket.new(params) + .catch(response => { + expect(response.message).toEqual(`This address doesn't exist`); + error = response; + }); + + expect(error).toBeDefined(); + }); + + it('should return the id of the created ticket', async() => { + let params = { + warehouseFk: 1, + clientFk: 101, + companyFk: 442, + addressFk: 25516, + agencyModeFk: 1, + userId: 9 + }; + + ticketId = await app.models.Ticket.new(params); + + let newestTicketIdInFixtures = 21; + + expect(ticketId).toBeGreaterThan(newestTicketIdInFixtures); + }); +}); diff --git a/services/order/common/methods/order/specs/new.spec.js b/services/order/common/methods/order/specs/new.spec.js index ebda20020..7150b86cc 100644 --- a/services/order/common/methods/order/specs/new.spec.js +++ b/services/order/common/methods/order/specs/new.spec.js @@ -59,7 +59,7 @@ describe('order new()', () => { let orderId = await app.models.Order.new(params); - let highestOrderIdInFixtures = 4; + let highestOrderIdInFixtures = 3; expect(orderId).toBeGreaterThan(highestOrderIdInFixtures); });