5638-ticket.summary_states #1538
|
@ -50,6 +50,7 @@ describe('Item Edit basic data path', () => {
|
||||||
|
|
||||||
it(`should create a new intrastat and save it`, async() => {
|
it(`should create a new intrastat and save it`, async() => {
|
||||||
await page.click($.newIntrastatButton);
|
await page.click($.newIntrastatButton);
|
||||||
|
await page.waitForSelector($.intrastatForm);
|
||||||
await page.fillForm($.intrastatForm, {
|
await page.fillForm($.intrastatForm, {
|
||||||
id: '588420239',
|
id: '588420239',
|
||||||
description: 'Tropical Flowers'
|
description: 'Tropical Flowers'
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('editableStates', {
|
Self.remoteMethodCtx('editableStates', {
|
||||||
description: 'Gets the editable states according the user role ',
|
description: 'Gets the editable states according the user role ',
|
||||||
|
@ -19,25 +20,16 @@ module.exports = Self => {
|
||||||
Self.editableStates = async(ctx, filter, options) => {
|
Self.editableStates = async(ctx, filter, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
const myOptions = {};
|
const myOptions = {...(options || {})};
|
||||||
vicent marked this conversation as resolved
|
|||||||
|
|
||||||
if (typeof options == 'object')
|
|
||||||
Object.assign(myOptions, options);
|
|
||||||
|
|
||||||
let statesList = await models.State.find(filter, myOptions);
|
|
||||||
const isProduction = await models.VnUser.hasRole(userId, 'production', myOptions);
|
const isProduction = await models.VnUser.hasRole(userId, 'production', myOptions);
|
||||||
const isSalesPerson = await models.VnUser.hasRole(userId, 'salesPerson', myOptions);
|
|
||||||
const isAdministrative = await models.VnUser.hasRole(userId, 'administrative', myOptions);
|
const isAdministrative = await models.VnUser.hasRole(userId, 'administrative', myOptions);
|
||||||
|
|
||||||
if (isProduction || isAdministrative)
|
if (!isProduction && !isAdministrative)
|
||||||
vicent marked this conversation as resolved
Outdated
alexm
commented
Refactor, ho tens en rocket Refactor, ho tens en rocket
|
|||||||
return statesList;
|
filter = mergeFilters(filter, {where: {alertLevel: 0}});
|
||||||
|
|
||||||
if (isSalesPerson) {
|
const states = await models.State.find(filter, myOptions);
|
||||||
return statesList = statesList.filter(stateList =>
|
|
||||||
stateList.alertLevel === 0 || stateList.code === 'PICKER_DESIGNED'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return statesList.filter(stateList => stateList.alertLevel === 0);
|
return states;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,31 +24,6 @@ describe('ticket editableStates()', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return the expected states by a specific role`, async() => {
|
|
||||||
const tx = await models.State.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
const productionRole = 18;
|
|
||||||
const ctx = {req: {accessToken: {userId: productionRole}}};
|
|
||||||
|
|
||||||
const editableStates = await models.State.editableStates(ctx, filter, options);
|
|
||||||
|
|
||||||
const deliveredState = editableStates.some(state => state.code == 'DELIVERED');
|
|
||||||
|
|
||||||
const pickerDesignedState = editableStates.some(state => state.code == 'PICKER_DESIGNED');
|
|
||||||
|
|
||||||
expect(deliveredState).toBeFalsy();
|
|
||||||
expect(pickerDesignedState).toBeTruthy();
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should return again the expected state by a specific role`, async() => {
|
it(`should return again the expected state by a specific role`, async() => {
|
||||||
const tx = await models.State.beginTransaction({});
|
const tx = await models.State.beginTransaction({});
|
||||||
|
|
||||||
|
@ -70,4 +45,25 @@ describe('ticket editableStates()', () => {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it(`should return the expected state matching with the name`, async() => {
|
||||||
|
const tx = await models.State.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const employeeRole = 1;
|
||||||
|
const ctx = {req: {accessToken: {userId: employeeRole}}};
|
||||||
|
const filter = {where: {name: {like: '%Previa OK%'}}};
|
||||||
|
|
||||||
|
const [editableStates] = await models.State.editableStates(ctx, filter, options);
|
||||||
|
|
||||||
|
expect(editableStates.name).toBe('Previa OK');
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Revisar