Updated unit tests

This commit is contained in:
Joan Sanchez 2021-04-14 08:15:03 +02:00
parent 6b8074e32f
commit 78313bd9a7
3 changed files with 50 additions and 23 deletions

View File

@ -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();
});
});

View File

@ -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);
});
});

View File

@ -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');
});
});