salix/modules/client/front/billing-data/index.spec.js

103 lines
3.6 KiB
JavaScript
Raw Normal View History

2018-05-23 12:26:51 +00:00
import './index';
2018-11-07 12:04:16 +00:00
describe('Client', () => {
describe('Component vnClientBillingData', () => {
let $httpBackend;
let $scope;
let controller;
2018-10-17 10:49:18 +00:00
let vnApp;
beforeEach(ngModule('client'));
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => {
2019-11-28 11:54:34 +00:00
let $element = angular.element('<vn-client-billing-data></vn-client-billing-data>');
$httpBackend = _$httpBackend_;
2018-10-17 10:49:18 +00:00
vnApp = _vnApp_;
2019-09-13 14:09:14 +00:00
$scope = $rootScope.$new();
$scope.watcher = {};
2020-02-26 12:22:52 +00:00
jest.spyOn(vnApp, 'showError');
2019-11-28 11:54:34 +00:00
controller = $componentController('vnClientBillingData', {$element, $scope});
controller.client = {id: 101, name: 'Client name', payMethodFk: 4};
2018-10-08 11:09:30 +00:00
$scope.watcher.orgData = {id: 101, name: 'Client name', payMethodFk: 4};
}));
2018-10-08 11:09:30 +00:00
describe('hasPaymethodChanges()', () => {
it(`should return true if there are changes on payMethod data`, () => {
controller.client.payMethodFk = 5;
2018-10-08 11:09:30 +00:00
expect(controller.hasPaymethodChanges()).toBeTruthy();
});
2017-08-30 10:30:48 +00:00
2018-10-08 11:09:30 +00:00
it(`should return false if there are no changes on payMethod data`, () => {
controller.client.payMethodFk = 4;
2018-10-08 11:09:30 +00:00
expect(controller.hasPaymethodChanges()).toBeFalsy();
});
});
2018-10-17 10:49:18 +00:00
2019-11-28 11:54:34 +00:00
describe('onBankEntityAccept()', () => {
2018-10-17 10:49:18 +00:00
it('should request to create a new bank entity', () => {
let newBankEntity = {
name: 'My new bank entity',
bic: 'ES123',
2019-03-07 11:11:06 +00:00
countryFk: 1,
id: 999
2018-10-17 10:49:18 +00:00
};
controller.newBankEntity = newBankEntity;
2019-11-28 11:54:34 +00:00
$httpBackend.expectPOST('BankEntities', newBankEntity).respond({id: 999});
controller.onBankEntityAccept();
2018-10-17 10:49:18 +00:00
$httpBackend.flush();
2019-11-28 11:54:34 +00:00
expect(controller.client.bankEntityFk).toEqual(newBankEntity.id);
2018-10-17 10:49:18 +00:00
});
});
2019-11-28 11:54:34 +00:00
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';
2019-11-28 11:54:34 +00:00
$httpBackend.whenRoute('GET', `BankEntities`).respond([{id: 123}]);
controller.autofillBic();
$httpBackend.flush();
2019-11-28 11:54:34 +00:00
expect(controller.client.bankEntityFk).toEqual(123);
});
2019-11-28 11:54:34 +00:00
it(`Should set clients bankEntityFk to null if no bank entity founds`, () => {
controller.client.iban = 'ES9121000418450200051332';
2019-11-28 11:54:34 +00:00
$httpBackend.whenRoute('GET', `BankEntities`).respond([]);
controller.autofillBic();
$httpBackend.flush();
2019-11-28 11:54:34 +00:00
expect(controller.client.bankEntityFk).toBeNull();
});
});
2018-11-23 07:44:19 +00:00
describe('ibanCountry()', () => {
it('should return a country code from iban', () => {
controller.client.iban = 'ES123';
let countryCode = controller.ibanCountry;
expect(countryCode).toEqual('ES');
});
});
2017-08-30 13:30:49 +00:00
});
});