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 controller;
|
2020-08-27 09:16:36 +00:00
|
|
|
let $httpBackend;
|
2018-11-14 09:55:15 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2018-11-14 09:55:15 +00:00
|
|
|
|
2020-08-27 09:16:36 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
2020-01-02 13:44:51 +00:00
|
|
|
let $scope = $rootScope.$new();
|
2020-03-17 10:17:50 +00:00
|
|
|
const $element = angular.element('<vn-client-balance-index></vn-client-balance-index>');
|
|
|
|
controller = $componentController('vnClientBalanceIndex', {$element, $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:48:06 +00:00
|
|
|
controller._companyId = 442;
|
2020-03-17 10:17:50 +00:00
|
|
|
controller.$params.id = 101;
|
2020-02-26 14:02:47 +00:00
|
|
|
jest.spyOn(controller, 'getBalances').mockReturnThis();
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$.model, 'applyFilter').mockReturnValue(Promise.resolve());
|
|
|
|
jest.spyOn(controller.$.riskModel, 'applyFilter').mockReturnValue(Promise.resolve());
|
2020-01-03 11:29:13 +00:00
|
|
|
|
2020-01-02 13:44:51 +00:00
|
|
|
controller.getData().then(() => {
|
2020-01-03 11:48:06 +00:00
|
|
|
expect(controller.$.model.applyFilter).toHaveBeenCalledWith(null, {'clientId': 101, 'companyId': 442});
|
2020-01-02 13:44:51 +00:00
|
|
|
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 and then call getData()', () => {
|
2020-02-27 06:19:42 +00:00
|
|
|
jest.spyOn(controller, 'getData').mockReturnThis();
|
2020-01-03 11:48:06 +00:00
|
|
|
controller.companyId = 442;
|
2020-01-03 11:29:13 +00:00
|
|
|
|
2020-01-03 11:48:06 +00:00
|
|
|
expect(controller._companyId).toEqual(442);
|
2020-01-03 11:29:13 +00:00
|
|
|
expect(controller.getData).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getCurrentBalance()', () => {
|
|
|
|
it('should return the client balance amount', () => {
|
2020-01-03 11:48:06 +00:00
|
|
|
controller._companyId = 442;
|
2020-01-03 11:29:13 +00:00
|
|
|
let result = controller.getCurrentBalance();
|
|
|
|
|
|
|
|
expect(result).toEqual(713.24);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getBalances()', () => {
|
|
|
|
it('should return the total client balance amount', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'getCurrentBalance');
|
2020-01-03 11:48:06 +00:00
|
|
|
controller._companyId = 442;
|
2020-01-03 11:29:13 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2020-02-17 07:38:19 +00:00
|
|
|
|
|
|
|
describe('balances() setter', () => {
|
|
|
|
it('should set the balances data and not call the getBalances() method', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'getBalances');
|
2020-02-17 07:38:19 +00:00
|
|
|
controller.$.riskModel.data = null;
|
|
|
|
controller.balances = [{
|
|
|
|
id: 1,
|
|
|
|
debit: 1000,
|
|
|
|
credit: null
|
|
|
|
}, {
|
|
|
|
id: 2,
|
|
|
|
debit: null,
|
|
|
|
credit: 500
|
|
|
|
}, {
|
|
|
|
id: 3,
|
|
|
|
debit: null,
|
|
|
|
credit: 300
|
|
|
|
}];
|
|
|
|
|
|
|
|
expect(controller.balances).toBeDefined();
|
|
|
|
expect(controller.getBalances).not.toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set the balances data and then call the getBalances() method', () => {
|
2020-02-27 06:19:42 +00:00
|
|
|
jest.spyOn(controller, 'getBalances').mockReturnThis();
|
2020-02-17 07:38:19 +00:00
|
|
|
controller.balances = [{
|
|
|
|
id: 1,
|
|
|
|
debit: 1000,
|
|
|
|
credit: null
|
|
|
|
}, {
|
|
|
|
id: 2,
|
|
|
|
debit: null,
|
|
|
|
credit: 500
|
|
|
|
}, {
|
|
|
|
id: 3,
|
|
|
|
debit: null,
|
|
|
|
credit: 300
|
|
|
|
}];
|
|
|
|
|
|
|
|
expect(controller.balances).toBeDefined();
|
|
|
|
expect(controller.getBalances).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
2020-08-27 09:16:36 +00:00
|
|
|
|
|
|
|
describe('changeDescription()', () => {
|
|
|
|
it('should make an http PATCH query', () => {
|
|
|
|
const expectedParams = {description: 'Web'};
|
|
|
|
|
|
|
|
$httpBackend.expect('PATCH', `Receipts/1`, expectedParams).respond(200);
|
|
|
|
controller.changeDescription({
|
|
|
|
id: 1,
|
|
|
|
description: 'Web',
|
|
|
|
accountingType: {
|
|
|
|
description: 'Cash'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
2018-11-14 09:55:15 +00:00
|
|
|
});
|
|
|
|
});
|