salix/modules/ticket/back/methods/state/specs/isEditable.spec.js

49 lines
1.8 KiB
JavaScript
Raw Normal View History

const app = require('vn-loopback/server/server');
describe('state isEditable()', () => {
it('should return false if the given state is not editable by a specific role', async() => {
const salesPersonRole = 18;
const onDeliveryState = 13;
let ctx = {req: {accessToken: {userId: salesPersonRole}}};
let result = await app.models.State.isEditable(ctx, onDeliveryState);
expect(result).toBeFalsy();
});
it('should return true if the given state is editable by a specific role', async() => {
const salesPersonRole = 18;
const asignedState = 20;
let ctx = {req: {accessToken: {userId: salesPersonRole}}};
let result = await app.models.State.isEditable(ctx, asignedState);
expect(result).toBeTruthy();
});
it('should return true again if the given state is editable by a specific role', async() => {
const employeeRole = 1;
const fixingState = 1;
let ctx = {req: {accessToken: {userId: employeeRole}}};
let result = await app.models.State.isEditable(ctx, fixingState);
expect(result).toBeTruthy();
});
it('should return false if the given state is not editable for the given role', async() => {
const employeeRole = 1;
const asignedState = 20;
let ctx = {req: {accessToken: {userId: employeeRole}}};
let result = await app.models.State.isEditable(ctx, asignedState);
expect(result).toBeFalsy();
});
it('should return true if the given state is editable for the given role', async() => {
const productionRole = 49;
const checkedState = 13;
let ctx = {req: {accessToken: {userId: productionRole}}};
let result = await app.models.State.isEditable(ctx, checkedState);
expect(result).toBeTruthy();
});
});