Merge pull request '3817-updatePortfolio' (#989) from 3817-updatePortfolio into dev
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
Reviewed-on: #989 Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
commit
a3c928d196
|
@ -1,21 +1,39 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('Client updatePortfolio', () => {
|
||||
const clientId = 1108;
|
||||
const activeCtx = {
|
||||
accessToken: {userId: 9},
|
||||
http: {
|
||||
req: {
|
||||
headers: {origin: 'http://localhost'},
|
||||
[`__`]: value => {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
beforeAll(() => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
});
|
||||
});
|
||||
|
||||
it('should update the portfolioWeight when the salesPerson of a client changes', async() => {
|
||||
const clientId = 1108;
|
||||
const salesPersonId = 18;
|
||||
|
||||
const tx = await models.Client.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const expectedResult = 841.63;
|
||||
|
||||
const clientQuery = `UPDATE vn.client SET salesPersonFk = ${salesPersonId} WHERE id = ${clientId}; `;
|
||||
await models.Client.rawSql(clientQuery);
|
||||
const client = await models.Client.findById(clientId, null, options);
|
||||
await client.updateAttribute('salesPersonFk', salesPersonId, options);
|
||||
|
||||
await models.Client.updatePortfolio();
|
||||
await models.Client.updatePortfolio(options);
|
||||
|
||||
const portfolioQuery = `SELECT portfolioWeight FROM bs.salesPerson WHERE workerFk = ${salesPersonId}; `;
|
||||
const [salesPerson] = await models.Client.rawSql(portfolioQuery, null, options);
|
||||
|
@ -30,21 +48,21 @@ describe('Client updatePortfolio', () => {
|
|||
});
|
||||
|
||||
it('should keep the same portfolioWeight when a salesperson is unassigned of a client', async() => {
|
||||
pending('task 3817');
|
||||
const clientId = 1107;
|
||||
const salesPersonId = 19;
|
||||
const tx = await models.Client.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const expectedResult = 34.40;
|
||||
|
||||
await models.Client.rawSql(`UPDATE vn.client SET salesPersonFk = NULL WHERE id = ${clientId}; `);
|
||||
const client = await models.Client.findById(clientId, null, options);
|
||||
await client.updateAttribute('salesPersonFk', null, options);
|
||||
|
||||
await models.Client.updatePortfolio();
|
||||
|
||||
const portfolioQuery = `SELECT portfolioWeight FROM bs.salesPerson WHERE workerFk = ${salesPersonId}; `;
|
||||
const [salesPerson] = await models.Client.rawSql(portfolioQuery, null, options);
|
||||
const [salesPerson] = await models.Client.rawSql(portfolioQuery);
|
||||
|
||||
expect(salesPerson.portfolioWeight).toEqual(expectedResult);
|
||||
|
||||
|
|
|
@ -13,8 +13,13 @@ module.exports = function(Self) {
|
|||
}
|
||||
});
|
||||
|
||||
Self.updatePortfolio = async() => {
|
||||
Self.updatePortfolio = async options => {
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
query = `CALL bs.salesPerson_updatePortfolio()`;
|
||||
return await Self.rawSql(query);
|
||||
return Self.rawSql(query, null, myOptions);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -136,6 +136,9 @@
|
|||
"mysql": {
|
||||
"columnName": "businessTypeFk"
|
||||
}
|
||||
},
|
||||
"salesPersonFk": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
|
Loading…
Reference in New Issue