3756-client_address_isLogifloraAllowed #930

Merged
joan merged 6 commits from 3756-client_address_isLogifloraAllowed into dev 2022-04-08 07:49:46 +00:00
7 changed files with 88 additions and 23 deletions

View File

@ -6,6 +6,12 @@ describe('Address updateAddress', () => {
const provinceId = 5;
const incotermsId = 'FAS';
const customAgentOneId = 1;
const employeeId = 1;
const ctx = {
req: {
accessToken: {userId: employeeId}
}
};
it('should throw the non uee member error if no incoterms is defined', async() => {
const tx = await models.Client.beginTransaction({});
@ -14,11 +20,9 @@ describe('Address updateAddress', () => {
try {
const options = {transaction: tx};
const ctx = {
args: {
ctx.args = {
provinceFk: provinceId,
customsAgentFk: customAgentOneId
}
};
await models.Client.updateAddress(ctx, clientId, addressId, options);
@ -40,11 +44,9 @@ describe('Address updateAddress', () => {
try {
const options = {transaction: tx};
const ctx = {
args: {
ctx.args = {
provinceFk: provinceId,
incotermsFk: incotermsId
}
};
await models.Client.updateAddress(ctx, clientId, addressId, options);
@ -66,13 +68,11 @@ describe('Address updateAddress', () => {
const options = {transaction: tx};
const expectedResult = 'My edited address';
const ctx = {
args: {
ctx.args = {
provinceFk: provinceId,
nickname: expectedResult,
incotermsFk: incotermsId,
customsAgentFk: customAgentOneId
}
};
await models.Client.updateAddress(ctx, clientId, addressId, options);
@ -88,6 +88,48 @@ describe('Address updateAddress', () => {
}
});
it('should return an error for a user without enough privileges', async() => {
const tx = await models.Client.beginTransaction({});
try {
const options = {transaction: tx};
ctx.args = {
isLogifloraAllowed: true
};
await models.Client.updateAddress(ctx, clientId, addressId, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error.message).toEqual(`You don't have enough privileges`);
});
it('should update isLogifloraAllowed', async() => {
const tx = await models.Client.beginTransaction({});
const salesAssistantId = 21;
try {
const options = {transaction: tx};
ctx.req.accessToken.userId = salesAssistantId;
ctx.args = {
isLogifloraAllowed: true
};
await models.Client.updateAddress(ctx, clientId, addressId, options);
const address = await models.Address.findById(addressId, null, options);
expect(address.isLogifloraAllowed).toEqual(true);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should update the address', async() => {
const tx = await models.Client.beginTransaction({});
@ -95,10 +137,8 @@ describe('Address updateAddress', () => {
const options = {transaction: tx};
const expectedResult = 'My second time edited address';
const ctx = {
args: {
ctx.args = {
nickname: expectedResult
}
};
await models.Client.updateAddress(ctx, clientId, addressId, options);

View File

@ -68,6 +68,10 @@ module.exports = function(Self) {
{
arg: 'isEqualizated',
type: 'boolean'
},
{
arg: 'isLogifloraAllowed',
type: 'boolean'
}
],
returns: {
@ -83,11 +87,16 @@ module.exports = function(Self) {
Self.updateAddress = async(ctx, clientId, addressId, options) => {
const models = Self.app.models;
const args = ctx.args;
const userId = ctx.req.accessToken.userId;
const myOptions = {};
const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant', myOptions);
alexm marked this conversation as resolved Outdated
Outdated
Review

Make use of models property

Make use of models property
if (typeof options == 'object')
Object.assign(myOptions, options);
if (args.isLogifloraAllowed && !isSalesAssistant)
alexm marked this conversation as resolved Outdated
Outdated
Review

Make use of args property

Make use of args property
throw new UserError(`You don't have enough privileges`);
const address = await models.Address.findOne({
where: {
id: addressId,

View File

@ -50,6 +50,9 @@
},
"isEqualizated": {
"type": "boolean"
},
"isLogifloraAllowed": {
"type": "boolean"
}
},
"validations": [],

View File

@ -39,6 +39,12 @@
ng-model="$ctrl.address.isEqualizated"
vn-acl="administrative, salesAssistant">
</vn-check>
<vn-check
vn-one
label="Is Logiflora allowed"
ng-model="$ctrl.address.isLogifloraAllowed"
vn-acl="salesAssistant">
</vn-check>
</vn-horizontal>
<vn-horizontal>
<vn-textfield

View File

@ -60,6 +60,11 @@
ng-model="address.isEqualizated"
disabled="true">
</vn-check>
<vn-check
vn-one label="Is Logiflora allowed"
ng-model="address.isLogifloraAllowed"
disabled="true">
</vn-check>
</vn-one>
<vn-vertical
vn-one

View File

@ -17,6 +17,7 @@ class Controller extends Section {
'phone',
'mobile',
'isEqualizated',
'isLogifloraAllowed',
'postalCode'
],
order: [

View File

@ -27,3 +27,4 @@ Mobile: Móvil
# Common
Fiscal name: Nombre fiscal
Street: Dirección fiscal
Is Logiflora allowed: Compra directa en Holanda