diff --git a/modules/client/back/methods/client/specs/activeWorkersWithRole.spec.js b/modules/client/back/methods/client/specs/activeWorkersWithRole.spec.js deleted file mode 100644 index fcf871d9b..000000000 --- a/modules/client/back/methods/client/specs/activeWorkersWithRole.spec.js +++ /dev/null @@ -1,23 +0,0 @@ -const app = require('vn-loopback/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(19); - 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(17); - expect(isBuyer).toBeTruthy(); - }); -}); diff --git a/modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js b/modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js new file mode 100644 index 000000000..c44fb72f9 --- /dev/null +++ b/modules/worker/back/methods/worker/specs/activeWithInheritedRole.spec.js @@ -0,0 +1,29 @@ +const app = require('vn-loopback/server/server'); + +describe('Worker activeWithInheritedRole', () => { + it('should return the workers with an inherited role of salesPerson', async() => { + const filter = {where: {role: 'salesPerson'}}; + const result = await app.models.Worker.activeWithInheritedRole(filter); + + const randomIndex = Math.floor(Math.random() * result.length); + const worker = result[randomIndex]; + + const isSalesPerson = await app.models.Account.hasRole(worker.id, 'salesPerson'); + + expect(result.length).toEqual(19); + expect(isSalesPerson).toBe(true); + }); + + it('should return the workers with an inherited role of buyer', async() => { + const filter = {where: {role: 'buyer'}}; + const result = await app.models.Worker.activeWithInheritedRole(filter); + + const randomIndex = Math.floor(Math.random() * result.length); + const worker = result[randomIndex]; + + const isBuyer = await app.models.Account.hasRole(worker.id, 'buyer'); + + expect(result.length).toEqual(17); + expect(isBuyer).toBe(true); + }); +}); diff --git a/modules/worker/back/methods/worker/specs/activeWithRole.spec.js b/modules/worker/back/methods/worker/specs/activeWithRole.spec.js new file mode 100644 index 000000000..88a312e24 --- /dev/null +++ b/modules/worker/back/methods/worker/specs/activeWithRole.spec.js @@ -0,0 +1,21 @@ +const app = require('vn-loopback/server/server'); + +describe('Worker activeWithRole', () => { + it('should return the sales people as result', async() => { + const filter = {where: {role: 'salesPerson'}}; + const result = await app.models.Worker.activeWithRole(filter); + const firstWorker = result[0]; + + expect(result.length).toEqual(1); + expect(firstWorker.nickname).toEqual('salesPersonNick'); + }); + + it('should return the buyers as result', async() => { + const filter = {where: {role: 'buyer'}}; + const result = await app.models.Worker.activeWithRole(filter); + const firstWorker = result[0]; + + expect(result.length).toEqual(1); + expect(firstWorker.nickname).toEqual('buyerNick'); + }); +});