2019-08-12 10:31:31 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
|
|
|
|
|
|
|
describe('state isEditable()', () => {
|
2020-02-06 10:50:32 +00:00
|
|
|
it('should return false if the state is not editable by a specific role', async() => {
|
2019-08-12 10:31:31 +00:00
|
|
|
const salesPersonRole = 18;
|
|
|
|
const onDeliveryState = 13;
|
|
|
|
let ctx = {req: {accessToken: {userId: salesPersonRole}}};
|
|
|
|
let result = await app.models.State.isEditable(ctx, onDeliveryState);
|
|
|
|
|
2020-02-06 10:50:32 +00:00
|
|
|
expect(result).toBe(false);
|
2019-08-12 10:31:31 +00:00
|
|
|
});
|
|
|
|
|
2020-02-06 10:50:32 +00:00
|
|
|
it('should return true if the state is editable by a specific role', async() => {
|
2019-08-12 10:31:31 +00:00
|
|
|
const salesPersonRole = 18;
|
|
|
|
const asignedState = 20;
|
|
|
|
let ctx = {req: {accessToken: {userId: salesPersonRole}}};
|
|
|
|
let result = await app.models.State.isEditable(ctx, asignedState);
|
|
|
|
|
2020-02-06 10:50:32 +00:00
|
|
|
expect(result).toBe(true);
|
2019-08-12 10:31:31 +00:00
|
|
|
});
|
|
|
|
|
2020-02-06 10:50:32 +00:00
|
|
|
it('should return true again if the state is editable by a specific role', async() => {
|
2019-08-12 10:31:31 +00:00
|
|
|
const employeeRole = 1;
|
|
|
|
const fixingState = 1;
|
|
|
|
let ctx = {req: {accessToken: {userId: employeeRole}}};
|
|
|
|
let result = await app.models.State.isEditable(ctx, fixingState);
|
|
|
|
|
2020-02-06 10:50:32 +00:00
|
|
|
expect(result).toBe(true);
|
2019-08-12 10:31:31 +00:00
|
|
|
});
|
|
|
|
|
2020-02-06 10:50:32 +00:00
|
|
|
it('should return false if the state is not editable for the given role', async() => {
|
2019-08-12 10:31:31 +00:00
|
|
|
const employeeRole = 1;
|
2020-09-25 12:50:04 +00:00
|
|
|
const asignedState = 13;
|
2019-08-12 10:31:31 +00:00
|
|
|
let ctx = {req: {accessToken: {userId: employeeRole}}};
|
|
|
|
let result = await app.models.State.isEditable(ctx, asignedState);
|
|
|
|
|
2020-02-06 10:50:32 +00:00
|
|
|
expect(result).toBe(false);
|
2019-08-12 10:31:31 +00:00
|
|
|
});
|
|
|
|
|
2020-02-06 10:50:32 +00:00
|
|
|
it('should return true if the state is editable for the given role', async() => {
|
2019-08-12 10:31:31 +00:00
|
|
|
const productionRole = 49;
|
2020-02-06 10:50:32 +00:00
|
|
|
const onDeliveryState = 13;
|
2019-08-12 10:31:31 +00:00
|
|
|
let ctx = {req: {accessToken: {userId: productionRole}}};
|
2020-02-06 10:50:32 +00:00
|
|
|
let result = await app.models.State.isEditable(ctx, onDeliveryState);
|
|
|
|
|
|
|
|
expect(result).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return true if the ticket is editable, the role is salesPerson and the ticket state is printed', async() => {
|
|
|
|
const salesPersonRole = 18;
|
|
|
|
const printedState = 4;
|
|
|
|
const okState = 3;
|
|
|
|
const ctx = {req: {accessToken: {userId: salesPersonRole}}};
|
|
|
|
|
|
|
|
let canEditCurrent = await app.models.State.isEditable(ctx, printedState);
|
|
|
|
let canAsignNew = await app.models.State.isEditable(ctx, okState);
|
|
|
|
let result = canEditCurrent && canAsignNew;
|
2019-08-12 10:31:31 +00:00
|
|
|
|
2020-02-06 10:50:32 +00:00
|
|
|
expect(result).toBe(true);
|
2019-08-12 10:31:31 +00:00
|
|
|
});
|
|
|
|
});
|