2018-11-14 09:55:15 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Client', () => {
|
|
|
|
describe('Component vnClientRiskIndex', () => {
|
|
|
|
let $componentController;
|
|
|
|
let $scope;
|
2019-04-05 11:20:34 +00:00
|
|
|
let $httpBackend;
|
|
|
|
let $httpParamSerializer;
|
2018-11-14 09:55:15 +00:00
|
|
|
let controller;
|
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2018-11-14 09:55:15 +00:00
|
|
|
|
2019-04-05 11:20:34 +00:00
|
|
|
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
2018-11-14 09:55:15 +00:00
|
|
|
$componentController = _$componentController_;
|
2019-04-05 11:20:34 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
2018-11-14 09:55:15 +00:00
|
|
|
$scope = $rootScope.$new();
|
2019-01-23 16:49:28 +00:00
|
|
|
controller = $componentController('vnClientRiskIndex', {$scope});
|
2018-11-14 09:55:15 +00:00
|
|
|
}));
|
|
|
|
|
2019-04-05 11:20:34 +00:00
|
|
|
describe('balances() setter', () => {
|
2018-11-14 09:55:15 +00:00
|
|
|
it('should calculate the balance for each line from the oldest date to the newest', () => {
|
2019-04-05 11:20:34 +00:00
|
|
|
controller.getCurrentBalance = jasmine.createSpy(controller, 'getCurrentBalance').and.returnValue(1000);
|
|
|
|
let balances = [
|
|
|
|
{credit: -100, debit: 0},
|
|
|
|
{credit: 0, debit: 300},
|
2018-11-14 09:55:15 +00:00
|
|
|
{credit: 100, debit: 0},
|
2019-04-05 11:20:34 +00:00
|
|
|
{credit: 0, debit: -300}
|
2018-11-14 09:55:15 +00:00
|
|
|
];
|
2019-04-05 11:20:34 +00:00
|
|
|
const params = {filter: controller.filter};
|
|
|
|
let serializedParams = $httpParamSerializer(params);
|
|
|
|
$httpBackend.when('GET', `/client/api/ClientRisks?${serializedParams}`).respond(balances);
|
|
|
|
$httpBackend.expect('GET', `/client/api/ClientRisks?${serializedParams}`);
|
|
|
|
controller.balances = balances;
|
|
|
|
$httpBackend.flush();
|
2018-11-14 09:55:15 +00:00
|
|
|
|
2019-04-05 11:20:34 +00:00
|
|
|
expect(controller.balances[0].balance).toEqual(1000);
|
|
|
|
expect(controller.balances[1].balance).toEqual(900);
|
|
|
|
expect(controller.balances[2].balance).toEqual(600);
|
|
|
|
expect(controller.balances[3].balance).toEqual(700);
|
2018-11-14 09:55:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|