import './index'; describe('Client', () => { describe('Component vnClientBillingData', () => { let $httpBackend; let $scope; let controller; let vnApp; beforeEach(ngModule('client')); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => { let $element = angular.element(''); $httpBackend = _$httpBackend_; vnApp = _vnApp_; $scope = $rootScope.$new(); $scope.watcher = {}; spyOn(vnApp, 'showError'); controller = $componentController('vnClientBillingData', {$element, $scope}); controller.client = {id: 101, name: 'Client name', payMethodFk: 4}; $scope.watcher.orgData = {id: 101, name: 'Client name', payMethodFk: 4}; })); describe('hasPaymethodChanges()', () => { it(`should return true if there are changes on payMethod data`, () => { controller.client.payMethodFk = 5; expect(controller.hasPaymethodChanges()).toBeTruthy(); }); it(`should return false if there are no changes on payMethod data`, () => { controller.client.payMethodFk = 4; expect(controller.hasPaymethodChanges()).toBeFalsy(); }); }); describe('onBankEntityAccept()', () => { it('should request to create a new bank entity', () => { let newBankEntity = { name: 'My new bank entity', bic: 'ES123', countryFk: 1, id: 999 }; controller.newBankEntity = newBankEntity; $httpBackend.expectPOST('BankEntities', newBankEntity).respond({id: 999}); controller.onBankEntityAccept(); $httpBackend.flush(); expect(controller.client.bankEntityFk).toEqual(newBankEntity.id); }); }); describe('autofillBic()', () => { it(`Should do nothing if there is not client`, () => { controller.client = undefined; controller.autofillBic(); expect(controller.client).toBeUndefined(); }); it(`Should do nothing if the iban is not spanish`, () => { controller.client.iban = 'FR9121000418450200051332'; controller.autofillBic(); expect(controller.client.bankEntityFk).toBeUndefined(); }); it(`Should set the bankEntityId in the client`, () => { controller.client.iban = 'ES9121000418450200051332'; $httpBackend.whenRoute('GET', `BankEntities`).respond([{id: 123}]); controller.autofillBic(); $httpBackend.flush(); expect(controller.client.bankEntityFk).toEqual(123); }); it(`Should set clients bankEntityFk to null if no bank entity founds`, () => { controller.client.iban = 'ES9121000418450200051332'; $httpBackend.whenRoute('GET', `BankEntities`).respond([]); controller.autofillBic(); $httpBackend.flush(); expect(controller.client.bankEntityFk).toBeNull(); }); }); describe('ibanCountry()', () => { it('should return a country code from iban', () => { controller.client.iban = 'ES123'; let countryCode = controller.ibanCountry; expect(countryCode).toEqual('ES'); }); }); }); });