2018-11-14 09:55:15 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Client', () => {
|
2019-04-16 11:40:26 +00:00
|
|
|
describe('Component vnClientBalanceIndex', () => {
|
2018-11-14 09:55:15 +00:00
|
|
|
let $componentController;
|
|
|
|
let controller;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2018-11-14 09:55:15 +00:00
|
|
|
|
2020-01-02 13:44:51 +00:00
|
|
|
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
|
2018-11-14 09:55:15 +00:00
|
|
|
$componentController = _$componentController_;
|
2020-01-02 13:44:51 +00:00
|
|
|
let $scope = $rootScope.$new();
|
2019-04-16 11:40:26 +00:00
|
|
|
controller = $componentController('vnClientBalanceIndex', {$scope});
|
2020-01-02 13:44:51 +00:00
|
|
|
controller.$.model = {applyFilter: () => {}};
|
2020-01-03 11:29:13 +00:00
|
|
|
controller.$.riskModel = {
|
|
|
|
applyFilter: () => {},
|
|
|
|
data:
|
|
|
|
[{
|
|
|
|
clientFk: 101,
|
|
|
|
companyFk: 442,
|
|
|
|
amount: 713.24,
|
|
|
|
company: {
|
|
|
|
id: 442,
|
|
|
|
code: 'VNL'
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
};
|
2020-01-02 13:44:51 +00:00
|
|
|
}));
|
2018-11-14 09:55:15 +00:00
|
|
|
|
2020-01-02 13:44:51 +00:00
|
|
|
describe('getData()', () => {
|
|
|
|
it('should apply the filters on he models and get the client balance', () => {
|
2020-01-03 11:29:13 +00:00
|
|
|
controller._companyFk = 442;
|
|
|
|
controller.$stateParams.id = 101;
|
2020-01-02 13:44:51 +00:00
|
|
|
spyOn(controller, 'getBalances');
|
|
|
|
spyOn(controller.$.model, 'applyFilter').and.returnValue(Promise.resolve());
|
|
|
|
spyOn(controller.$.riskModel, 'applyFilter').and.returnValue(Promise.resolve());
|
2020-01-03 11:29:13 +00:00
|
|
|
|
2020-01-02 13:44:51 +00:00
|
|
|
controller.getData().then(() => {
|
|
|
|
expect(controller.$.model.applyFilter).toHaveBeenCalledWith(null, {'clientFk': 101, 'companyFk': 442});
|
|
|
|
expect(controller.$.riskModel.applyFilter).toHaveBeenCalledWith({'where': {'clientFk': 101, 'companyFk': 442}});
|
|
|
|
expect(controller.getBalances).toHaveBeenCalledWith();
|
|
|
|
});
|
2018-11-14 09:55:15 +00:00
|
|
|
});
|
|
|
|
});
|
2020-01-03 11:29:13 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2018-11-14 09:55:15 +00:00
|
|
|
});
|
|
|
|
});
|