salix/modules/client/front/web-access/index.spec.js

106 lines
4.0 KiB
JavaScript
Raw Normal View History

2018-05-23 12:26:51 +00:00
import './index';
describe('Component VnClientWebAccess', () => {
let $httpBackend;
let $scope;
let vnApp;
let controller;
2019-09-13 14:09:14 +00:00
beforeEach(angular.mock.module('client', $translateProvider => {
$translateProvider.translations('en', {});
}));
2017-08-25 06:42:53 +00:00
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => {
$scope = $rootScope.$new();
$httpBackend = _$httpBackend_;
vnApp = _vnApp_;
spyOn(vnApp, 'showError');
controller = $componentController('vnClientWebAccess', {$scope});
}));
describe('$onChanges()', () => {
2017-09-21 06:48:25 +00:00
it(`should pass client's account data to account then call isCustomer function`, () => {
spyOn(controller, 'isCustomer');
controller.client = {client: 'Bruce Wayne', account: 'Wayne Industries'};
controller.account = {};
controller.$onChanges();
expect(controller.account).toBe('Wayne Industries');
2017-09-21 06:48:25 +00:00
expect(controller.isCustomer).toHaveBeenCalledWith();
});
});
describe('isCustomer()', () => {
it(`should perform a query if client is defined with an ID`, () => {
controller.client = {id: '1234'};
controller.isCustomer();
$httpBackend.when('GET', `/client/api/Clients/${controller.client.id}/hasCustomerRole`).respond('ok');
$httpBackend.expectGET(`/client/api/Clients/${controller.client.id}/hasCustomerRole`);
2017-09-21 06:48:25 +00:00
$httpBackend.flush();
});
2017-08-25 06:42:53 +00:00
});
describe('checkConditions()', () => {
it(`should perform a query to check if the client is valid and then store a boolean into the controller`, () => {
controller.client = {id: '1234'};
expect(controller.canEnableCheckBox).toBeTruthy();
$httpBackend.when('GET', `/client/api/Clients/${controller.client.id}/isValidClient`).respond(false);
$httpBackend.expectGET(`/client/api/Clients/${controller.client.id}/isValidClient`);
controller.checkConditions();
$httpBackend.flush();
expect(controller.canEnableCheckBox).toBeFalsy();
});
});
describe('onPassOpen()', () => {
it('should set passwords to empty values', () => {
controller.newPassword = 'm24x8';
controller.repeatPassword = 'm24x8';
controller.onPassOpen();
expect(controller.newPassword).toBe('');
expect(controller.repeatPassword).toBe('');
});
});
describe('onPassChange()', () => {
2017-09-04 12:39:58 +00:00
it('should request to update the password', () => {
controller.client = {id: '1234'};
controller.newPassword = 'm24x8';
controller.repeatPassword = 'm24x8';
2017-09-21 06:48:25 +00:00
controller.canChangePassword = true;
$httpBackend.when('PATCH', '/client/api/Accounts/1234').respond('done');
$httpBackend.expectPATCH('/client/api/Accounts/1234', {password: 'm24x8'});
controller.onPassChange('ACCEPT');
$httpBackend.flush();
});
describe(`when password is empty`, () => {
2019-07-11 05:18:07 +00:00
it(`should throw 'You must enter a new password' error`, () => {
controller.client = {id: '1234'};
controller.newPassword = '';
2017-09-21 06:48:25 +00:00
controller.canChangePassword = true;
controller.onPassChange('ACCEPT');
2019-07-11 05:18:07 +00:00
expect(vnApp.showError).toHaveBeenCalledWith(`You must enter a new password`);
});
});
describe(`when passwords don't match`, () => {
it(`should throw Passwords don't match error`, () => {
controller.client = {id: '1234'};
controller.newPassword = 'm24x8';
2017-09-21 06:48:25 +00:00
controller.canChangePassword = true;
controller.repeatPassword = 'notMatchingPassword';
controller.onPassChange('ACCEPT');
expect(vnApp.showError).toHaveBeenCalledWith(`Passwords don't match`);
});
});
2017-08-25 06:42:53 +00:00
});
});