test client.balance
gitea/salix/1971-frontTest_client.balance There was a failure building this commit
Details
gitea/salix/1971-frontTest_client.balance There was a failure building this commit
Details
This commit is contained in:
parent
9c364fccb7
commit
b6353f1b5c
|
@ -162,7 +162,7 @@ export default {
|
||||||
},
|
},
|
||||||
clientBalance: {
|
clientBalance: {
|
||||||
balanceButton: 'vn-left-menu a[ui-sref="client.card.balance.index"]',
|
balanceButton: 'vn-left-menu a[ui-sref="client.card.balance.index"]',
|
||||||
companyAutocomplete: 'vn-client-balance-index vn-autocomplete[ng-model="$ctrl.companyFk"]',
|
companyAutocomplete: 'vn-client-balance-index vn-autocomplete[ng-model="$ctrl.companyId"]',
|
||||||
newPaymentButton: `vn-float-button`,
|
newPaymentButton: `vn-float-button`,
|
||||||
newPaymentBank: '.vn-dialog.shown vn-autocomplete[ng-model="$ctrl.receipt.bankFk"]',
|
newPaymentBank: '.vn-dialog.shown vn-autocomplete[ng-model="$ctrl.receipt.bankFk"]',
|
||||||
newPaymentAmountInput: '.vn-dialog.shown vn-input-number[ng-model="$ctrl.receipt.amountPaid"] input',
|
newPaymentAmountInput: '.vn-dialog.shown vn-input-number[ng-model="$ctrl.receipt.amountPaid"] input',
|
||||||
|
|
|
@ -11,12 +11,12 @@ module.exports = Self => {
|
||||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
||||||
http: {source: 'query'}
|
http: {source: 'query'}
|
||||||
}, {
|
}, {
|
||||||
arg: 'clientFk',
|
arg: 'clientId',
|
||||||
type: 'Number',
|
type: 'Number',
|
||||||
description: 'The client id',
|
description: 'The client id',
|
||||||
required: true,
|
required: true,
|
||||||
}, {
|
}, {
|
||||||
arg: 'companyFk',
|
arg: 'companyId',
|
||||||
type: 'Number',
|
type: 'Number',
|
||||||
description: 'The company id',
|
description: 'The company id',
|
||||||
required: true,
|
required: true,
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
vn-id="company"
|
vn-id="company"
|
||||||
class="dense"
|
class="dense"
|
||||||
ng-model="$ctrl.companyFk"
|
ng-model="$ctrl.companyId"
|
||||||
url="Companies"
|
url="Companies"
|
||||||
show-field="code"
|
show-field="code"
|
||||||
value-field="id"
|
value-field="id"
|
||||||
|
|
|
@ -20,27 +20,27 @@ class Controller {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
get companyFk() {
|
get companyId() {
|
||||||
if (!this._companyFk)
|
if (!this._companyId)
|
||||||
this.companyFk = this.vnConfig.companyFk;
|
this.companyId = this.vnConfig.companyFk;
|
||||||
|
|
||||||
return this._companyFk;
|
return this._companyId;
|
||||||
}
|
}
|
||||||
|
|
||||||
set companyFk(id) {
|
set companyId(value) {
|
||||||
this._companyFk = id;
|
this._companyId = value;
|
||||||
|
|
||||||
if (id) this.getData();
|
if (value) this.getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
getData() {
|
getData() {
|
||||||
return this.$.model.applyFilter(null, {
|
return this.$.model.applyFilter(null, {
|
||||||
clientFk: this.$stateParams.id,
|
clientId: this.$stateParams.id,
|
||||||
companyFk: this.companyFk
|
companyId: this.companyId
|
||||||
}).then(() => this.$.riskModel.applyFilter({
|
}).then(() => this.$.riskModel.applyFilter({
|
||||||
where: {
|
where: {
|
||||||
clientFk: this.$stateParams.id,
|
clientFk: this.$stateParams.id,
|
||||||
companyFk: this.companyFk
|
companyFk: this.companyId
|
||||||
}
|
}
|
||||||
})).then(() => this.getBalances());
|
})).then(() => this.getBalances());
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ class Controller {
|
||||||
|
|
||||||
getCurrentBalance() {
|
getCurrentBalance() {
|
||||||
const clientRisks = this.$.riskModel.data;
|
const clientRisks = this.$.riskModel.data;
|
||||||
const selectedCompany = this.companyFk;
|
const selectedCompany = this.companyId;
|
||||||
const currentBalance = clientRisks.find(balance => {
|
const currentBalance = clientRisks.find(balance => {
|
||||||
return balance.companyFk === selectedCompany;
|
return balance.companyFk === selectedCompany;
|
||||||
});
|
});
|
||||||
|
@ -63,7 +63,6 @@ class Controller {
|
||||||
balance.balance = this.getCurrentBalance();
|
balance.balance = this.getCurrentBalance();
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
let previousBalance = balances[index - 1];
|
let previousBalance = balances[index - 1];
|
||||||
|
|
||||||
balance.balance = previousBalance.balance - (previousBalance.debit - previousBalance.credit);
|
balance.balance = previousBalance.balance - (previousBalance.debit - previousBalance.credit);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -71,7 +70,7 @@ class Controller {
|
||||||
|
|
||||||
|
|
||||||
openCreateDialog() {
|
openCreateDialog() {
|
||||||
this.$.balanceCreateDialog.companyFk = this.companyFk;
|
this.$.balanceCreateDialog.companyFk = this.companyId;
|
||||||
this.$.balanceCreateDialog.onResponse = () => this.getData();
|
this.$.balanceCreateDialog.onResponse = () => this.getData();
|
||||||
this.$.balanceCreateDialog.show();
|
this.$.balanceCreateDialog.show();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,18 +11,30 @@ describe('Client', () => {
|
||||||
$componentController = _$componentController_;
|
$componentController = _$componentController_;
|
||||||
let $scope = $rootScope.$new();
|
let $scope = $rootScope.$new();
|
||||||
controller = $componentController('vnClientBalanceIndex', {$scope});
|
controller = $componentController('vnClientBalanceIndex', {$scope});
|
||||||
controller._companyFk = 442;
|
|
||||||
controller.$stateParams.id = 101;
|
|
||||||
|
|
||||||
controller.$.model = {applyFilter: () => {}};
|
controller.$.model = {applyFilter: () => {}};
|
||||||
controller.$.riskModel = {applyFilter: () => {}};
|
controller.$.riskModel = {
|
||||||
|
applyFilter: () => {},
|
||||||
|
data:
|
||||||
|
[{
|
||||||
|
clientFk: 101,
|
||||||
|
companyFk: 442,
|
||||||
|
amount: 713.24,
|
||||||
|
company: {
|
||||||
|
id: 442,
|
||||||
|
code: 'VNL'
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('getData()', () => {
|
describe('getData()', () => {
|
||||||
it('should apply the filters on he models and get the client balance', () => {
|
it('should apply the filters on he models and get the client balance', () => {
|
||||||
|
controller._companyFk = 442;
|
||||||
|
controller.$stateParams.id = 101;
|
||||||
spyOn(controller, 'getBalances');
|
spyOn(controller, 'getBalances');
|
||||||
spyOn(controller.$.model, 'applyFilter').and.returnValue(Promise.resolve());
|
spyOn(controller.$.model, 'applyFilter').and.returnValue(Promise.resolve());
|
||||||
spyOn(controller.$.riskModel, 'applyFilter').and.returnValue(Promise.resolve());
|
spyOn(controller.$.riskModel, 'applyFilter').and.returnValue(Promise.resolve());
|
||||||
|
|
||||||
controller.getData().then(() => {
|
controller.getData().then(() => {
|
||||||
expect(controller.$.model.applyFilter).toHaveBeenCalledWith(null, {'clientFk': 101, 'companyFk': 442});
|
expect(controller.$.model.applyFilter).toHaveBeenCalledWith(null, {'clientFk': 101, 'companyFk': 442});
|
||||||
expect(controller.$.riskModel.applyFilter).toHaveBeenCalledWith({'where': {'clientFk': 101, 'companyFk': 442}});
|
expect(controller.$.riskModel.applyFilter).toHaveBeenCalledWith({'where': {'clientFk': 101, 'companyFk': 442}});
|
||||||
|
@ -30,5 +42,60 @@ describe('Client', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('company setter/getter', () => {
|
||||||
|
it('should return the company', () => {
|
||||||
|
controller.companyFk = null;
|
||||||
|
|
||||||
|
expect(controller._companyFk).toEqual(jasmine.any(Object));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the company and then call getData()', () => {
|
||||||
|
spyOn(controller, 'getData');
|
||||||
|
controller.companyFk = 442;
|
||||||
|
|
||||||
|
expect(controller._companyFk).toEqual(442);
|
||||||
|
expect(controller.getData).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getCurrentBalance()', () => {
|
||||||
|
it('should return the client balance amount', () => {
|
||||||
|
controller._companyFk = 442;
|
||||||
|
let result = controller.getCurrentBalance();
|
||||||
|
|
||||||
|
expect(result).toEqual(713.24);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getBalances()', () => {
|
||||||
|
it('should return the total client balance amount', () => {
|
||||||
|
spyOn(controller, 'getCurrentBalance').and.callThrough();
|
||||||
|
controller._companyFk = 442;
|
||||||
|
controller.$.model = {data:
|
||||||
|
[{
|
||||||
|
id: 1,
|
||||||
|
debit: 1000,
|
||||||
|
credit: null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
debit: null,
|
||||||
|
credit: 500
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
debit: null,
|
||||||
|
credit: 300
|
||||||
|
}
|
||||||
|
]};
|
||||||
|
controller.getBalances();
|
||||||
|
const expectedBalances = controller.$.model.data;
|
||||||
|
|
||||||
|
expect(expectedBalances[0].balance).toEqual(713.24);
|
||||||
|
expect(expectedBalances[1].balance).toEqual(-286.76);
|
||||||
|
expect(expectedBalances[2].balance).toEqual(213.24);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue