refs #5128 add testBack
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2023-04-18 09:09:09 +02:00
parent c9dffe9175
commit 48cd23750e
4 changed files with 45 additions and 40 deletions

View File

@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('setRating', {
description: 'Change role and hasGrant if user has setRating',
description: 'Change rating and recommendedCredit of a client',
accepts: [
{
arg: 'id',

View File

@ -0,0 +1,43 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('Client setRating()', () => {
const financialId = 73;
const activeCtx = {
accessToken: {userId: financialId},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
const ctx = {req: activeCtx};
beforeAll(async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
});
it('should change rating and recommendedCredit', async() => {
const tx = await models.Ticket.beginTransaction({});
try {
const options = {transaction: tx};
const clientId = 1101;
const newRating = 10;
const newRecommendedCredit = 20;
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;
}
});
});

View File

@ -281,7 +281,7 @@ module.exports = Self => {
await Self.changeCredit(ctx, finalState, changes);
// Credit management changes
if (orgData.rating != changes.rating || orgData.recommendedCredit != changes.recommendedCredit)
if (orgData?.rating != changes.rating || orgData?.recommendedCredit != changes.recommendedCredit)
await Self.changeCreditManagement(ctx, finalState, changes);
const oldInstance = {};

View File

@ -1,38 +0,0 @@
import './index';
describe('client unpaid', () => {
describe('Component vnClientUnpaid', () => {
let controller;
beforeEach(ngModule('client'));
beforeEach(inject($componentController => {
const $element = angular.element('<vn-client-unpaid></vn-client-unpaid>');
controller = $componentController('vnClientUnpaid', {$element});
}));
describe('setDefaultDate()', () => {
it(`should not set today date if has dated`, () => {
const hasData = true;
const yesterday = Date.vnNew();
yesterday.setDate(yesterday.getDate() - 1);
controller.clientUnpaid = {
dated: yesterday
};
controller.setDefaultDate(hasData);
expect(controller.clientUnpaid.dated).toEqual(yesterday);
});
it(`should set today if not has dated`, () => {
const hasData = true;
controller.clientUnpaid = {};
controller.setDefaultDate(hasData);
expect(controller.clientUnpaid.dated).toBeDefined();
});
});
});
});