fix: excluded backTest fixed
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
f66e5fac9e
commit
0c996f7915
|
@ -1,21 +1,39 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('Client updatePortfolio', () => {
|
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() => {
|
it('should update the portfolioWeight when the salesPerson of a client changes', async() => {
|
||||||
|
const clientId = 1108;
|
||||||
const salesPersonId = 18;
|
const salesPersonId = 18;
|
||||||
|
|
||||||
const tx = await models.Client.beginTransaction({});
|
const tx = await models.Client.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const expectedResult = 841.63;
|
const expectedResult = 841.63;
|
||||||
|
|
||||||
const clientQuery = `UPDATE vn.client SET salesPersonFk = ${salesPersonId} WHERE id = ${clientId}; `;
|
const client = await models.Client.findById(clientId, null, options);
|
||||||
await models.Client.rawSql(clientQuery);
|
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 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, null, options);
|
||||||
|
@ -30,21 +48,21 @@ describe('Client updatePortfolio', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should keep the same portfolioWeight when a salesperson is unassigned of a client', async() => {
|
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 salesPersonId = 19;
|
||||||
const tx = await models.Client.beginTransaction({});
|
const tx = await models.Client.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const expectedResult = 34.40;
|
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();
|
await models.Client.updatePortfolio();
|
||||||
|
|
||||||
const portfolioQuery = `SELECT portfolioWeight FROM bs.salesPerson WHERE workerFk = ${salesPersonId}; `;
|
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);
|
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()`;
|
query = `CALL bs.salesPerson_updatePortfolio()`;
|
||||||
return await Self.rawSql(query);
|
return await Self.rawSql(query, null, myOptions);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -136,6 +136,9 @@
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"columnName": "businessTypeFk"
|
"columnName": "businessTypeFk"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"salesPersonFk": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
Loading…
Reference in New Issue