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

145 lines
5.7 KiB
JavaScript
Raw Normal View History

2018-05-23 12:26:51 +00:00
import './index';
2018-12-27 11:54:16 +00:00
import watcher from 'core/mocks/watcher';
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_) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
2018-10-08 11:09:30 +00:00
$scope.watcher = watcher;
2018-10-17 10:49:18 +00:00
vnApp = _vnApp_;
spyOn(vnApp, 'showError');
2018-08-09 10:54:29 +00:00
controller = $componentController('vnClientBillingData', {$scope: $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-07-31 09:51:24 +00:00
describe('onSubmit()', () => {
it(`should call notifyChanges() if there are changes on payMethod data`, () => {
spyOn(controller, 'notifyChanges');
controller.client.payMethodFk = 5;
controller.onSubmit();
expect(controller.notifyChanges).toHaveBeenCalledWith();
});
});
// Excluded due mailer changes #79
xdescribe('notifyChanges()', () => {
2018-10-08 11:09:30 +00:00
it(`should perform a GET query`, () => {
2018-08-09 10:54:29 +00:00
$httpBackend.when('GET', `/mailer/notification/payment-update/101`).respond(true);
$httpBackend.expect('GET', `/mailer/notification/payment-update/101`);
controller.notifyChanges();
$httpBackend.flush();
});
});
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
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',
countryFk: 1
};
controller.onBankEntityResponse('ACCEPT');
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: '',
countryFk: 1
};
controller.onBankEntityResponse('ACCEPT');
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',
countryFk: 1
};
controller.newBankEntity = newBankEntity;
$httpBackend.when('POST', '/client/api/BankEntities').respond('done');
$httpBackend.expectPOST('/client/api/BankEntities', newBankEntity);
controller.onBankEntityResponse('ACCEPT');
$httpBackend.flush();
});
});
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));
$httpBackend.when('GET', `/client/api/BankEntities?filter=${json}`).respond('done');
$httpBackend.expect('GET', `/client/api/BankEntities?filter=${json}`);
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));
$httpBackend.when('GET', `/client/api/BankEntities?filter=${json}`).respond([{id: 128}]);
$httpBackend.expect('GET', `/client/api/BankEntities?filter=${json}`);
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
});
});