Test #1636 refactor test de back isEditable y editableState
gitea/salix/dev This commit has test failures
Details
gitea/salix/dev This commit has test failures
Details
This commit is contained in:
parent
41dc5f93e5
commit
b6cc769df3
|
@ -1,35 +1,32 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('ticket editableStates()', () => {
|
||||
it('should call the editableStates method with the production role and check that the result contain the DELIVERED state', async() => {
|
||||
const ctx = {req: {accessToken: {userId: 49}}};
|
||||
it('should return the expected state for the given role', async() => {
|
||||
const productionRole = 49;
|
||||
const ctx = {req: {accessToken: {userId: productionRole}}};
|
||||
let result = await app.models.State.editableStates(ctx);
|
||||
let codeExists = result.some(state => state.code == 'DELIVERED');
|
||||
let deliveredState = result.some(state => state.code == 'DELIVERED');
|
||||
|
||||
expect(codeExists).toBeTruthy();
|
||||
expect(deliveredState).toBeTruthy();
|
||||
});
|
||||
|
||||
it(`should call the editableStates method with the salesPerson role and check that the result not contain the DELIVERED state`, async() => {
|
||||
const ctx = {req: {accessToken: {userId: 18}}};
|
||||
it(`should returns the expected states by a specific role`, async() => {
|
||||
const productionRole = 18;
|
||||
const ctx = {req: {accessToken: {userId: productionRole}}};
|
||||
let result = await app.models.State.editableStates(ctx);
|
||||
let codeExists = result.some(state => state.code == 'DELIVERED');
|
||||
let deliveredState = result.some(state => state.code == 'DELIVERED');
|
||||
let pickerDesignedState = result.some(state => state.code == 'PICKER_DESIGNED');
|
||||
|
||||
expect(codeExists).toBeFalsy();
|
||||
expect(deliveredState).toBeFalsy();
|
||||
expect(pickerDesignedState).toBeTruthy();
|
||||
});
|
||||
|
||||
it(`should call the editableStates method with the salesPerson role and check that the result contain the PICKER_DESIGNED state`, async() => {
|
||||
const ctx = {req: {accessToken: {userId: 18}}};
|
||||
it(`should return again the expected state by a specific role`, async() => {
|
||||
const employeeRole = 1;
|
||||
const ctx = {req: {accessToken: {userId: employeeRole}}};
|
||||
let result = await app.models.State.editableStates(ctx);
|
||||
let codeExists = result.some(state => state.code == 'PICKER_DESIGNED');
|
||||
let pickerDesignedState = result.some(state => state.code == 'PICKER_DESIGNED');
|
||||
|
||||
expect(codeExists).toBeTruthy();
|
||||
});
|
||||
|
||||
it(`should call the editableStates method with the employee role and check that the result not contain the PICKER_DESIGNED state`, async() => {
|
||||
const ctx = {req: {accessToken: {userId: 1}}};
|
||||
let result = await app.models.State.editableStates(ctx);
|
||||
let codeExists = result.some(state => state.code == 'PICKER_DESIGNED');
|
||||
|
||||
expect(codeExists).toBeFalsy();
|
||||
expect(pickerDesignedState).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
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();
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue