2018-05-23 12:26:51 +00:00
|
|
|
import './index';
|
2017-08-29 10:33:48 +00:00
|
|
|
|
2018-11-07 12:04:16 +00:00
|
|
|
describe('Client', () => {
|
2017-09-04 13:06:43 +00:00
|
|
|
describe('Component vnClientBillingData', () => {
|
|
|
|
let $httpBackend;
|
|
|
|
let $scope;
|
2017-10-17 12:24:40 +00:00
|
|
|
let controller;
|
2018-10-17 10:49:18 +00:00
|
|
|
let vnApp;
|
2017-08-29 10:33:48 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2017-08-29 10:33:48 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => {
|
2017-09-04 13:06:43 +00:00
|
|
|
$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 = {};
|
2018-10-17 10:49:18 +00:00
|
|
|
spyOn(vnApp, 'showError');
|
2019-09-13 14:09:14 +00:00
|
|
|
controller = $componentController('vnClientBillingData', {$scope});
|
2018-07-10 12:13:47 +00:00
|
|
|
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};
|
2017-09-04 13:06:43 +00:00
|
|
|
}));
|
2017-08-29 10:33:48 +00:00
|
|
|
|
2018-10-08 11:09:30 +00:00
|
|
|
describe('hasPaymethodChanges()', () => {
|
|
|
|
it(`should return true if there are changes on payMethod data`, () => {
|
2018-07-10 12:13:47 +00:00
|
|
|
controller.client.payMethodFk = 5;
|
|
|
|
|
2018-10-08 11:09:30 +00:00
|
|
|
expect(controller.hasPaymethodChanges()).toBeTruthy();
|
2017-08-30 06:38:41 +00:00
|
|
|
});
|
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`, () => {
|
2018-07-10 12:13:47 +00:00
|
|
|
controller.client.payMethodFk = 4;
|
2017-09-20 12:01:33 +00:00
|
|
|
|
2018-10-08 11:09:30 +00:00
|
|
|
expect(controller.hasPaymethodChanges()).toBeFalsy();
|
2017-09-04 13:06:43 +00:00
|
|
|
});
|
2018-07-10 12:13:47 +00:00
|
|
|
});
|
2018-10-17 10:49:18 +00:00
|
|
|
|
|
|
|
describe('onBankEntityOpen()', () => {
|
|
|
|
it('should set reset the new bank entity properties', () => {
|
|
|
|
controller.newBankEntity.name = 'My new bank entity';
|
|
|
|
controller.newBankEntity.bic = 'ES123';
|
|
|
|
controller.onBankEntityOpen();
|
|
|
|
|
|
|
|
expect(controller.newBankEntity.name).toBe('');
|
|
|
|
expect(controller.newBankEntity.bic).toBe('');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onBankEntityResponse()', () => {
|
|
|
|
it(`should throw an error if name property is empty`, () => {
|
|
|
|
controller.newBankEntity = {
|
|
|
|
name: '',
|
|
|
|
bic: 'ES123',
|
2019-03-07 11:11:06 +00:00
|
|
|
countryFk: 1,
|
|
|
|
id: 999
|
2018-10-17 10:49:18 +00:00
|
|
|
};
|
2019-10-30 15:57:14 +00:00
|
|
|
controller.onBankEntityResponse('accept');
|
2018-10-17 10:49:18 +00:00
|
|
|
|
|
|
|
expect(vnApp.showError).toHaveBeenCalledWith(`Name can't be empty`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should throw an error if bic property is empty`, () => {
|
|
|
|
controller.newBankEntity = {
|
|
|
|
name: 'My new bank entity',
|
|
|
|
bic: '',
|
2019-03-07 11:11:06 +00:00
|
|
|
countryFk: 1,
|
|
|
|
id: 999
|
2018-10-17 10:49:18 +00:00
|
|
|
};
|
2019-10-30 15:57:14 +00:00
|
|
|
controller.onBankEntityResponse('accept');
|
2018-10-17 10:49:18 +00:00
|
|
|
|
|
|
|
expect(vnApp.showError).toHaveBeenCalledWith(`Swift / BIC can't be empty`);
|
|
|
|
});
|
|
|
|
|
|
|
|
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-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('POST', 'BankEntities').respond('done');
|
|
|
|
$httpBackend.expectPOST('BankEntities', newBankEntity);
|
2019-10-30 15:57:14 +00:00
|
|
|
controller.onBankEntityResponse('accept');
|
2018-10-17 10:49:18 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
2018-11-07 08:17:07 +00:00
|
|
|
|
|
|
|
describe('autofillBic() should perform a GET query if client iban is specified and country code is "ES".', () => {
|
|
|
|
it(`Should not define bankEntityFk property`, () => {
|
|
|
|
controller.client.payMethodFk = 5;
|
|
|
|
controller.client.iban = 'ES9121000418450200051332';
|
|
|
|
let expectedFilter = {where: {id: 2100}};
|
|
|
|
let json = encodeURIComponent(JSON.stringify(expectedFilter));
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('GET', `BankEntities?filter=${json}`).respond('done');
|
|
|
|
$httpBackend.expect('GET', `BankEntities?filter=${json}`);
|
2018-11-07 08:17:07 +00:00
|
|
|
controller.autofillBic();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.client.bankEntityFk).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`Should define bankEntityFk property`, () => {
|
|
|
|
controller.client.payMethodFk = 5;
|
|
|
|
controller.client.iban = 'ES1501280010120123456789';
|
|
|
|
let expectedFilter = {where: {id: 128}};
|
|
|
|
let json = encodeURIComponent(JSON.stringify(expectedFilter));
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('GET', `BankEntities?filter=${json}`).respond([{id: 128}]);
|
|
|
|
$httpBackend.expect('GET', `BankEntities?filter=${json}`);
|
2018-11-07 08:17:07 +00:00
|
|
|
controller.autofillBic();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.client.bankEntityFk).toEqual(128);
|
|
|
|
});
|
|
|
|
});
|
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
|
|
|
});
|
|
|
|
});
|