Merge pull request 'hotfix creditClient' (!2041) from hotfix-creditClient into master
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #2041 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
bb6861d799
|
@ -28,7 +28,6 @@ module.exports = Self => {
|
|||
Self.setRating = async function(ctx, id, rating, recommendedCredit, options) {
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
|
@ -42,6 +41,7 @@ module.exports = Self => {
|
|||
const clientUpdated = await client.updateAttributes({
|
||||
rating: rating,
|
||||
recommendedCredit: recommendedCredit
|
||||
|
||||
}, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
|
|
@ -40,4 +40,26 @@ describe('Client setRating()', () => {
|
|||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should change rating and recommendedCredit to 0', async() => {
|
||||
const tx = await models.Ticket.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const clientId = 1101;
|
||||
const newRating = 0;
|
||||
const newRecommendedCredit = 0;
|
||||
|
||||
const updatedClient = await models.Client.setRating(ctx, clientId, newRating, newRecommendedCredit, options);
|
||||
|
||||
expect(updatedClient.rating).toEqual(newRating);
|
||||
expect(updatedClient.recommendedCredit).toEqual(newRecommendedCredit);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -319,7 +319,8 @@ module.exports = Self => {
|
|||
await Self.changeCredit(ctx, finalState, changes);
|
||||
|
||||
// Credit management changes
|
||||
if (changes?.rating || changes?.recommendedCredit)
|
||||
|
||||
if (changes?.rating >= 0 || changes?.recommendedCredit >= 0)
|
||||
await Self.changeCreditManagement(ctx, finalState, changes);
|
||||
|
||||
const oldInstance = {};
|
||||
|
|
Loading…
Reference in New Issue