diff --git a/modules/client/front/balance/create/index.spec.js b/modules/client/front/balance/create/index.spec.js
new file mode 100644
index 0000000000..11fdb1040c
--- /dev/null
+++ b/modules/client/front/balance/create/index.spec.js
@@ -0,0 +1,76 @@
+import './index';
+
+describe('Client', () => {
+ describe('Component vnClientBalancCreate', () => {
+ let controller;
+ let $httpBackend;
+ let $httpParamSerializer;
+
+ beforeEach(ngModule('client'));
+
+ beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
+ $httpBackend = _$httpBackend_;
+ $httpParamSerializer = _$httpParamSerializer_;
+ let $scope = $rootScope.$new();
+ const $element = angular.element('');
+ const $transclude = {
+ $$boundTransclude: {
+ $$slots: []
+ }
+ };
+ controller = $componentController('vnClientBalanceCreate', {$element, $scope, $transclude});
+ controller.receipt = {
+ clientFk: 101,
+ companyFk: 442
+ };
+ }));
+
+ describe('bankSelection() setter', () => {
+ it('should set the receipt description property', () => {
+ controller.bankSelection = {
+ id: 1,
+ bank: 'Cash',
+ accountingType: {
+ id: 2,
+ receiptDescription: 'Cash'
+ }
+ };
+
+ expect(controller.receipt.description).toEqual('Cash');
+ });
+ });
+
+ describe('getAmountPaid()', () => {
+ it('should make an http GET query and then set the receipt amountPaid property', () => {
+ controller.$params = {id: 101};
+ const receipt = controller.receipt;
+ const filter = {
+ where: {
+ clientFk: 101,
+ companyFk: 442
+ }
+ };
+ const serializedParams = $httpParamSerializer({filter});
+ $httpBackend.expect('GET', `ClientRisks?${serializedParams}`,).respond([{amount: 20}]);
+ controller.getAmountPaid();
+ $httpBackend.flush();
+
+ expect(receipt.amountPaid).toEqual(20);
+ });
+ });
+
+ describe('responseHandler()', () => {
+ it('should make an http POST query and then call to the parent responseHandler() method', () => {
+ jest.spyOn(controller.vnApp, 'showSuccess');
+
+ controller.$params = {id: 101};
+
+ $httpBackend.expect('POST', `Receipts`,).respond({id: 1});
+ controller.responseHandler('accept');
+ $httpBackend.flush();
+
+ expect(controller.vnApp.showSuccess).toHaveBeenCalled();
+ });
+ });
+ });
+});
diff --git a/modules/client/front/balance/index/index.js b/modules/client/front/balance/index/index.js
index 40a6e49571..3c76feabc4 100644
--- a/modules/client/front/balance/index/index.js
+++ b/modules/client/front/balance/index/index.js
@@ -58,7 +58,7 @@ class Controller extends Section {
return balance.companyFk === selectedCompany;
});
- return currentBalance.amount;
+ return currentBalance && currentBalance.amount;
}
getBalances() {
diff --git a/modules/client/front/balance/index/index.spec.js b/modules/client/front/balance/index/index.spec.js
index 496407847d..bdbea38460 100644
--- a/modules/client/front/balance/index/index.spec.js
+++ b/modules/client/front/balance/index/index.spec.js
@@ -3,10 +3,12 @@ import './index';
describe('Client', () => {
describe('Component vnClientBalanceIndex', () => {
let controller;
+ let $httpBackend;
beforeEach(ngModule('client'));
- beforeEach(inject(($componentController, $rootScope) => {
+ beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
+ $httpBackend = _$httpBackend_;
let $scope = $rootScope.$new();
const $element = angular.element('');
controller = $componentController('vnClientBalanceIndex', {$element, $scope});
@@ -133,5 +135,21 @@ describe('Client', () => {
expect(controller.getBalances).toHaveBeenCalledWith();
});
});
+
+ 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();
+ });
+ });
});
});