From 11c524083457b9146110ff6546bd458f3c05a907 Mon Sep 17 00:00:00 2001 From: Gerard Date: Tue, 27 Nov 2018 13:23:51 +0100 Subject: [PATCH] tests fixed --- .../methods/client/activeWorkersWithRole.js | 2 +- .../methods/client/specs/activeBuyer.spec.js | 13 ----------- .../client/specs/activeSalesperson.spec.js | 13 ----------- .../specs/activeWorkersWithRole.spec.js | 23 +++++++++++++++++++ 4 files changed, 24 insertions(+), 27 deletions(-) delete mode 100644 services/loopback/common/methods/client/specs/activeBuyer.spec.js delete mode 100644 services/loopback/common/methods/client/specs/activeSalesperson.spec.js create mode 100644 services/loopback/common/methods/client/specs/activeWorkersWithRole.spec.js diff --git a/services/loopback/common/methods/client/activeWorkersWithRole.js b/services/loopback/common/methods/client/activeWorkersWithRole.js index 67fcf3c73..854179de8 100644 --- a/services/loopback/common/methods/client/activeWorkersWithRole.js +++ b/services/loopback/common/methods/client/activeWorkersWithRole.js @@ -24,7 +24,7 @@ module.exports = Self => { Self.activeWorkersWithRole = async filter => { let conn = Self.dataSource.connector; - if (filter.where.and && Array.isArray(filter.where.and)) { + if (filter.where && filter.where.and && Array.isArray(filter.where.and)) { let where = {}; filter.where.and.forEach(element => { where[Object.keys(element)[0]] = Object.values(element)[0]; diff --git a/services/loopback/common/methods/client/specs/activeBuyer.spec.js b/services/loopback/common/methods/client/specs/activeBuyer.spec.js deleted file mode 100644 index eadff40ed..000000000 --- a/services/loopback/common/methods/client/specs/activeBuyer.spec.js +++ /dev/null @@ -1,13 +0,0 @@ -const app = require(`${servicesDir}/client/server/server`); - -describe('Client activeBuyer', () => { - it('should return the buyers as result', async () => { - let filter = {}; - let result = await app.models.Client.activeBuyer(filter); - - let isBuyer = await app.models.Account.hasRole(result[0].id, 'buyer'); - - expect(result.length).toEqual(9); - expect(isBuyer).toBeTruthy(); - }); -}); diff --git a/services/loopback/common/methods/client/specs/activeSalesperson.spec.js b/services/loopback/common/methods/client/specs/activeSalesperson.spec.js deleted file mode 100644 index 45748e6e4..000000000 --- a/services/loopback/common/methods/client/specs/activeSalesperson.spec.js +++ /dev/null @@ -1,13 +0,0 @@ -const app = require(`${servicesDir}/client/server/server`); - -describe('Client activeSalesPerson', () => { - it('should return the sales people as result', async () => { - let filter = {}; - let result = await app.models.Client.activeSalesPerson(filter); - - let isSalesPerson = await app.models.Account.hasRole(result[0].id, 'salesPerson'); - - expect(result.length).toEqual(10); - expect(isSalesPerson).toBeTruthy(); - }); -}); diff --git a/services/loopback/common/methods/client/specs/activeWorkersWithRole.spec.js b/services/loopback/common/methods/client/specs/activeWorkersWithRole.spec.js new file mode 100644 index 000000000..17c6e90dd --- /dev/null +++ b/services/loopback/common/methods/client/specs/activeWorkersWithRole.spec.js @@ -0,0 +1,23 @@ +const app = require(`${servicesDir}/client/server/server`); + +describe('Client activeWorkersWithRole', () => { + it('should return the sales people as result', async () => { + let filter = {where: {role: 'salesPerson'}}; + let result = await app.models.Client.activeWorkersWithRole(filter); + + let isSalesPerson = await app.models.Account.hasRole(result[0].id, 'salesPerson'); + + expect(result.length).toEqual(10); + expect(isSalesPerson).toBeTruthy(); + }); + + it('should return the buyers as result', async () => { + let filter = {where: {role: 'buyer'}}; + let result = await app.models.Client.activeWorkersWithRole(filter); + + let isBuyer = await app.models.Account.hasRole(result[0].id, 'buyer'); + + expect(result.length).toEqual(9); + expect(isBuyer).toBeTruthy(); + }); +});