2018-05-23 12:26:51 +00:00
|
|
|
import './index';
|
2019-02-28 07:55:34 +00:00
|
|
|
import watcher from 'core/mocks/watcher';
|
2017-08-29 10:33:48 +00:00
|
|
|
|
2017-09-04 13:06:43 +00:00
|
|
|
describe('Client', () => {
|
2018-05-24 13:02:38 +00:00
|
|
|
describe('Component vnClientAddressCreate', () => {
|
2020-01-24 08:47:24 +00:00
|
|
|
let $scope;
|
2017-10-17 12:24:40 +00:00
|
|
|
let controller;
|
2020-01-24 08:47:24 +00:00
|
|
|
let $httpBackend;
|
|
|
|
let $element;
|
2017-09-04 13:06:43 +00:00
|
|
|
let $state;
|
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
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, _$state_, _$httpBackend_) => {
|
2020-01-24 08:47:24 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$httpBackend = _$httpBackend_;
|
2017-09-04 13:06:43 +00:00
|
|
|
$state = _$state_;
|
|
|
|
$state.params.id = '1234';
|
2020-01-24 08:47:24 +00:00
|
|
|
$element = angular.element('<vn-client-address-create></vn-client-address-create>');
|
|
|
|
controller = $componentController('vnClientAddressCreate', {$element, $scope});
|
2019-06-13 11:08:11 +00:00
|
|
|
controller.$.watcher = watcher;
|
|
|
|
controller.$.watcher.submit = () => {
|
2019-02-28 07:55:34 +00:00
|
|
|
return {
|
|
|
|
then: callback => {
|
|
|
|
callback({data: {id: 124}});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
2021-06-23 11:24:23 +00:00
|
|
|
controller.client = {id: 1101, defaultAddressFk: 121};
|
2017-09-04 13:06:43 +00:00
|
|
|
}));
|
2017-08-29 10:33:48 +00:00
|
|
|
|
2017-09-04 13:06:43 +00:00
|
|
|
it('should define and set address property', () => {
|
2020-01-28 08:03:20 +00:00
|
|
|
expect(controller.address.isActive).toBe(true);
|
2019-02-28 07:55:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('onSubmit()', () => {
|
|
|
|
it('should perform a PATCH and not set value to defaultAddressFk property', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$state, 'go');
|
2020-01-28 08:03:20 +00:00
|
|
|
controller.address.isDefaultAddress = false;
|
2019-02-28 07:55:34 +00:00
|
|
|
controller.onSubmit();
|
|
|
|
|
|
|
|
expect(controller.client.defaultAddressFk).toEqual(121);
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('client.card.address.index');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should perform a PATCH and set a value to defaultAddressFk property', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$state, 'go');
|
2020-01-28 08:03:20 +00:00
|
|
|
controller.address.isDefaultAddress = true;
|
2019-02-28 07:55:34 +00:00
|
|
|
controller.onSubmit();
|
|
|
|
|
|
|
|
expect(controller.client.defaultAddressFk).toEqual(124);
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('client.card.address.index');
|
|
|
|
});
|
2017-09-04 13:06:43 +00:00
|
|
|
});
|
2019-07-08 12:07:09 +00:00
|
|
|
|
2020-03-03 14:03:54 +00:00
|
|
|
describe('town() setter', () => {
|
2020-10-20 12:42:23 +00:00
|
|
|
it(`should set provinceFk property`, () => {
|
2020-03-03 14:03:54 +00:00
|
|
|
controller.town = {
|
|
|
|
provinceFk: 1,
|
|
|
|
code: 46001,
|
|
|
|
province: {
|
|
|
|
id: 1,
|
|
|
|
name: 'New york',
|
|
|
|
country: {
|
|
|
|
id: 2,
|
|
|
|
name: 'USA'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
postcodes: []
|
|
|
|
};
|
|
|
|
|
2020-10-20 12:42:23 +00:00
|
|
|
expect(controller.address.provinceFk).toEqual(1);
|
2020-03-03 14:03:54 +00:00
|
|
|
});
|
|
|
|
|
2020-10-20 12:42:23 +00:00
|
|
|
it(`should set provinceFk property and fill the postalCode if there's just one`, () => {
|
2020-03-03 14:03:54 +00:00
|
|
|
controller.town = {
|
|
|
|
provinceFk: 1,
|
|
|
|
code: 46001,
|
|
|
|
province: {
|
|
|
|
id: 1,
|
|
|
|
name: 'New york',
|
|
|
|
country: {
|
|
|
|
id: 2,
|
|
|
|
name: 'USA'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
postcodes: [{code: '46001'}]
|
|
|
|
};
|
|
|
|
|
2020-10-20 12:42:23 +00:00
|
|
|
expect(controller.address.provinceFk).toEqual(1);
|
2020-03-03 14:03:54 +00:00
|
|
|
expect(controller.address.postalCode).toEqual('46001');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('postcode() setter', () => {
|
|
|
|
it(`should set the town and province properties`, () => {
|
|
|
|
controller.postcode = {
|
2019-07-08 12:07:09 +00:00
|
|
|
townFk: 1,
|
|
|
|
code: 46001,
|
|
|
|
town: {
|
|
|
|
id: 1,
|
|
|
|
name: 'New York',
|
|
|
|
province: {
|
|
|
|
id: 1,
|
|
|
|
name: 'New york',
|
|
|
|
country: {
|
|
|
|
id: 2,
|
|
|
|
name: 'USA'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(controller.address.city).toEqual('New York');
|
2020-10-20 12:42:23 +00:00
|
|
|
expect(controller.address.provinceFk).toEqual(1);
|
2019-07-08 12:07:09 +00:00
|
|
|
});
|
|
|
|
});
|
2020-01-24 08:47:24 +00:00
|
|
|
|
|
|
|
describe('onCustomAgentAccept()', () => {
|
|
|
|
it(`should create a new customs agent and then set the customsAgentFk property on the address`, () => {
|
|
|
|
const expectedResult = {id: 1, fiscalName: 'Customs agent one'};
|
|
|
|
$httpBackend.when('POST', 'CustomsAgents').respond(200, expectedResult);
|
|
|
|
controller.onCustomAgentAccept();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-10-20 12:42:23 +00:00
|
|
|
expect(controller.address.customsAgentFk).toEqual(1);
|
2020-01-24 08:47:24 +00:00
|
|
|
});
|
|
|
|
});
|
2017-08-31 06:53:17 +00:00
|
|
|
});
|
|
|
|
});
|