2018-05-23 12:26:51 +00:00
|
|
|
import './index';
|
2020-02-04 10:25:15 +00:00
|
|
|
import watcher from 'core/mocks/watcher';
|
2018-02-05 09:58:49 +00:00
|
|
|
|
|
|
|
describe('Client', () => {
|
|
|
|
describe('Component vnClientFiscalData', () => {
|
|
|
|
let $httpBackend;
|
|
|
|
let $scope;
|
2020-02-04 10:25:15 +00:00
|
|
|
let $element;
|
2018-02-05 09:58:49 +00:00
|
|
|
let controller;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2018-02-05 09:58:49 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
2018-02-05 09:58:49 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$scope = $rootScope.$new();
|
2020-02-04 10:25:15 +00:00
|
|
|
$scope.watcher = watcher;
|
2021-06-23 11:24:23 +00:00
|
|
|
$scope.watcher.orgData = {id: 1101, isEqualizated: false, isTaxDataChecked: false};
|
2020-02-04 10:25:15 +00:00
|
|
|
$element = angular.element('<vn-client-fiscal-data></client-fiscal-data>');
|
|
|
|
controller = $componentController('vnClientFiscalData', {$element, $scope});
|
2018-07-03 09:13:33 +00:00
|
|
|
controller.card = {reload: () => {}};
|
2020-02-04 10:25:15 +00:00
|
|
|
controller.client = {
|
2021-06-23 11:24:23 +00:00
|
|
|
id: 1101,
|
2020-02-04 10:25:15 +00:00
|
|
|
email: 'batman@gothamcity.com',
|
|
|
|
phone: '1111111111',
|
|
|
|
isEqualizated: false,
|
|
|
|
isTaxDataChecked: false
|
|
|
|
};
|
2020-03-03 14:03:54 +00:00
|
|
|
|
2020-05-21 09:14:34 +00:00
|
|
|
controller._province = {};
|
|
|
|
controller._town = {};
|
|
|
|
controller._postcode = {};
|
2018-02-05 09:58:49 +00:00
|
|
|
}));
|
|
|
|
|
2020-02-04 10:25:15 +00:00
|
|
|
describe('onSubmit()', () => {
|
|
|
|
it('should call the save() method directly', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'save');
|
2020-02-04 10:25:15 +00:00
|
|
|
|
|
|
|
controller.onSubmit();
|
|
|
|
|
|
|
|
expect(controller.save).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call the checkExistingClient() if the isTaxDataChecked property is checked', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'save');
|
|
|
|
jest.spyOn(controller, 'checkExistingClient');
|
2020-02-04 10:25:15 +00:00
|
|
|
|
|
|
|
controller.client.isTaxDataChecked = true;
|
|
|
|
controller.onSubmit();
|
|
|
|
|
|
|
|
expect(controller.save).not.toHaveBeenCalledWith();
|
|
|
|
expect(controller.checkExistingClient).toHaveBeenCalledWith();
|
|
|
|
});
|
2020-11-19 09:51:28 +00:00
|
|
|
|
|
|
|
it('should enable the hasToInvoice property any time the form activates the client with isActive', () => {
|
|
|
|
$scope.watcher.orgData.isActive = false;
|
|
|
|
controller.client.isActive = true;
|
|
|
|
controller.client.hasToInvoice = false;
|
|
|
|
|
|
|
|
controller.onSubmit();
|
|
|
|
|
|
|
|
expect(controller.client.hasToInvoice).toBe(true);
|
|
|
|
});
|
2020-02-04 10:25:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('checkExistingClient()', () => {
|
2020-03-04 08:26:12 +00:00
|
|
|
it(`should make a HTTP GET query filtering by email, phone and mobile`, () => {
|
|
|
|
controller.client.mobile = 222222222;
|
|
|
|
const filterObj = {
|
|
|
|
where: {
|
|
|
|
and: [
|
|
|
|
{or: [
|
|
|
|
{email: controller.client.email},
|
|
|
|
{phone: controller.client.phone},
|
|
|
|
{mobile: controller.client.mobile}
|
|
|
|
]},
|
|
|
|
{id: {neq: controller.client.id}}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const filter = encodeURIComponent(JSON.stringify(filterObj));
|
2020-03-06 12:06:01 +00:00
|
|
|
$httpBackend.expect('GET', `Clients/findOne?filter=${filter}`).respond(404);
|
2020-03-04 08:26:12 +00:00
|
|
|
controller.checkExistingClient();
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should show a save confirmation and then set the despiteOfClient property`, () => {
|
2020-02-04 10:25:15 +00:00
|
|
|
controller.$.confirmDuplicatedClient = {show: () => {}};
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$.confirmDuplicatedClient, 'show');
|
2020-03-04 08:26:12 +00:00
|
|
|
|
2020-02-04 10:25:15 +00:00
|
|
|
const filterObj = {
|
|
|
|
where: {
|
|
|
|
and: [
|
|
|
|
{or: [{email: controller.client.email}, {phone: controller.client.phone}]},
|
|
|
|
{id: {neq: controller.client.id}}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
2021-06-23 11:24:23 +00:00
|
|
|
const expectedClient = {id: 1102};
|
2020-02-04 10:25:15 +00:00
|
|
|
const filter = encodeURIComponent(JSON.stringify(filterObj));
|
|
|
|
$httpBackend.expect('GET', `Clients/findOne?filter=${filter}`).respond(expectedClient);
|
|
|
|
controller.checkExistingClient();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.$.confirmDuplicatedClient.show).toHaveBeenCalledWith();
|
2021-06-23 11:24:23 +00:00
|
|
|
expect(controller.client.despiteOfClient).toEqual(1102);
|
2020-02-04 10:25:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('checkEtChanges()', () => {
|
|
|
|
it(`should show a propagation confirmation if isEqualizated property is changed and invoice by address is checked`, () => {
|
|
|
|
controller.$.propagateIsEqualizated = {show: () => {}};
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$.propagateIsEqualizated, 'show');
|
2020-02-04 10:25:15 +00:00
|
|
|
|
|
|
|
const orgData = $scope.watcher.orgData;
|
|
|
|
orgData.hasToInvoiceByAddress = true;
|
|
|
|
controller.client.isEqualizated = true;
|
|
|
|
|
|
|
|
controller.checkEtChanges(orgData);
|
|
|
|
|
|
|
|
expect(controller.$.propagateIsEqualizated.show).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should call to the onAcceptEt() method if isEqualizated property is changed and invoice by address isn't checked`, () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'onAcceptEt');
|
2020-02-04 10:25:15 +00:00
|
|
|
|
|
|
|
const orgData = $scope.watcher.orgData;
|
|
|
|
orgData.hasToInvoiceByAddress = false;
|
|
|
|
controller.client.isEqualizated = true;
|
|
|
|
|
|
|
|
controller.checkEtChanges(orgData);
|
|
|
|
|
|
|
|
expect(controller.onAcceptEt).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onAcceptEt()', () => {
|
2018-02-05 09:58:49 +00:00
|
|
|
it('should request to patch the propagation of tax status', () => {
|
|
|
|
controller.client = {id: 123, isEqualizated: false};
|
2020-07-23 15:10:07 +00:00
|
|
|
$httpBackend.expectPATCH(`Clients/${controller.client.id}/addressesPropagateRe`, {isEqualizated: controller.client.isEqualizated}).respond('done');
|
2020-02-04 10:25:15 +00:00
|
|
|
controller.onAcceptEt();
|
2018-02-05 09:58:49 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
});
|
2020-03-03 14:03:54 +00:00
|
|
|
|
|
|
|
describe('province() setter', () => {
|
|
|
|
it(`should set countryFk property`, () => {
|
2020-05-21 09:14:34 +00:00
|
|
|
controller.client.countryFk = null;
|
2020-03-03 14:03:54 +00:00
|
|
|
controller.province = {
|
|
|
|
id: 1,
|
|
|
|
name: 'New york',
|
|
|
|
country: {
|
|
|
|
id: 2,
|
|
|
|
name: 'USA'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(controller.client.countryFk).toEqual(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('town() setter', () => {
|
|
|
|
it(`should set provinceFk property`, () => {
|
|
|
|
controller.town = {
|
|
|
|
provinceFk: 1,
|
|
|
|
code: 46001,
|
|
|
|
province: {
|
|
|
|
id: 1,
|
|
|
|
name: 'New york',
|
|
|
|
country: {
|
|
|
|
id: 2,
|
|
|
|
name: 'USA'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
postcodes: []
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(controller.client.provinceFk).toEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should set provinceFk property and fill the postalCode if there's just one`, () => {
|
|
|
|
controller.town = {
|
|
|
|
provinceFk: 1,
|
|
|
|
code: 46001,
|
|
|
|
province: {
|
|
|
|
id: 1,
|
|
|
|
name: 'New york',
|
|
|
|
country: {
|
|
|
|
id: 2,
|
|
|
|
name: 'USA'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
postcodes: [{code: '46001'}]
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(controller.client.provinceFk).toEqual(1);
|
|
|
|
expect(controller.client.postcode).toEqual('46001');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('postcode() setter', () => {
|
|
|
|
it(`should set the town, provinceFk and contryFk properties`, () => {
|
|
|
|
controller.postcode = {
|
|
|
|
townFk: 1,
|
|
|
|
code: 46001,
|
|
|
|
town: {
|
|
|
|
id: 1,
|
|
|
|
name: 'New York',
|
|
|
|
province: {
|
|
|
|
id: 1,
|
|
|
|
name: 'New york',
|
|
|
|
country: {
|
|
|
|
id: 2,
|
|
|
|
name: 'USA'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(controller.client.city).toEqual('New York');
|
|
|
|
expect(controller.client.provinceFk).toEqual(1);
|
|
|
|
expect(controller.client.countryFk).toEqual(2);
|
|
|
|
});
|
|
|
|
});
|
2018-02-05 09:58:49 +00:00
|
|
|
});
|
|
|
|
});
|