2018-05-23 12:26:51 +00:00
|
|
|
import './index';
|
2017-08-29 10:33:48 +00:00
|
|
|
|
|
|
|
describe('Component VnClientWebAccess', () => {
|
|
|
|
let $httpBackend;
|
|
|
|
let $scope;
|
|
|
|
let vnApp;
|
2017-10-17 12:24:40 +00:00
|
|
|
let controller;
|
2017-08-29 10:33:48 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2017-08-25 06:42:53 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => {
|
2017-08-29 10:33:48 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
vnApp = _vnApp_;
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(vnApp, 'showError');
|
2020-03-17 10:17:50 +00:00
|
|
|
const $element = angular.element('<vn-client-web-access></vn-client-web-access>');
|
|
|
|
controller = $componentController('vnClientWebAccess', {$element, $scope});
|
2017-08-29 10:33:48 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('$onChanges()', () => {
|
2017-09-21 06:48:25 +00:00
|
|
|
it(`should pass client's account data to account then call isCustomer function`, () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'isCustomer');
|
2017-08-29 10:33:48 +00:00
|
|
|
controller.client = {client: 'Bruce Wayne', account: 'Wayne Industries'};
|
|
|
|
controller.account = {};
|
|
|
|
controller.$onChanges();
|
2017-09-20 12:01:33 +00:00
|
|
|
|
2017-08-29 10:33:48 +00:00
|
|
|
expect(controller.account).toBe('Wayne Industries');
|
2017-09-21 06:48:25 +00:00
|
|
|
expect(controller.isCustomer).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('isCustomer()', () => {
|
2020-01-08 10:00:50 +00:00
|
|
|
it('should return true if the password can be modified', () => {
|
2017-09-21 06:48:25 +00:00
|
|
|
controller.client = {id: '1234'};
|
2020-01-07 12:03:45 +00:00
|
|
|
|
2021-09-29 10:17:21 +00:00
|
|
|
$httpBackend.expectGET(`Clients/${controller.client.id}/hasCustomerRole`).respond(true);
|
2017-09-21 06:48:25 +00:00
|
|
|
controller.isCustomer();
|
2020-01-07 12:03:45 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.canChangePassword).toBeTruthy();
|
|
|
|
});
|
2017-09-21 06:48:25 +00:00
|
|
|
|
2020-01-07 12:03:45 +00:00
|
|
|
it(`should return a false if the password can't be modified`, () => {
|
|
|
|
controller.client = {id: '1234'};
|
|
|
|
|
2021-09-29 10:17:21 +00:00
|
|
|
$httpBackend.expectGET(`Clients/${controller.client.id}/hasCustomerRole`).respond(false);
|
2020-01-07 12:03:45 +00:00
|
|
|
controller.isCustomer();
|
2017-09-21 06:48:25 +00:00
|
|
|
$httpBackend.flush();
|
2020-01-07 12:03:45 +00:00
|
|
|
|
|
|
|
expect(controller.canChangePassword).toBeFalsy();
|
2017-08-29 10:33:48 +00:00
|
|
|
});
|
2017-08-25 06:42:53 +00:00
|
|
|
});
|
|
|
|
|
2018-08-08 07:05:31 +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();
|
|
|
|
|
2020-07-23 15:10:07 +00:00
|
|
|
$httpBackend.expectGET(`Clients/${controller.client.id}/isValidClient`).respond(false);
|
2018-08-08 07:05:31 +00:00
|
|
|
controller.checkConditions();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.canEnableCheckBox).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-08-29 10:33:48 +00:00
|
|
|
describe('onPassOpen()', () => {
|
|
|
|
it('should set passwords to empty values', () => {
|
|
|
|
controller.newPassword = 'm24x8';
|
|
|
|
controller.repeatPassword = 'm24x8';
|
|
|
|
controller.onPassOpen();
|
2017-09-20 12:01:33 +00:00
|
|
|
|
2017-08-29 10:33:48 +00:00
|
|
|
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', () => {
|
2017-08-29 10:33:48 +00:00
|
|
|
controller.client = {id: '1234'};
|
|
|
|
controller.newPassword = 'm24x8';
|
|
|
|
controller.repeatPassword = 'm24x8';
|
2017-09-21 06:48:25 +00:00
|
|
|
controller.canChangePassword = true;
|
2020-07-23 15:10:07 +00:00
|
|
|
$httpBackend.expectPATCH('Accounts/1234', {password: 'm24x8'}).respond('done');
|
2020-07-29 08:47:48 +00:00
|
|
|
controller.onPassChange();
|
2017-08-29 10:33:48 +00:00
|
|
|
$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`, () => {
|
2017-08-29 10:33:48 +00:00
|
|
|
controller.client = {id: '1234'};
|
|
|
|
controller.newPassword = '';
|
2017-09-21 06:48:25 +00:00
|
|
|
controller.canChangePassword = true;
|
2020-07-29 08:47:48 +00:00
|
|
|
controller.onPassChange();
|
2017-09-20 12:01:33 +00:00
|
|
|
|
2019-07-11 05:18:07 +00:00
|
|
|
expect(vnApp.showError).toHaveBeenCalledWith(`You must enter a new password`);
|
2017-08-29 10:33:48 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`when passwords don't match`, () => {
|
2017-09-20 12:01:33 +00:00
|
|
|
it(`should throw Passwords don't match error`, () => {
|
2017-08-29 10:33:48 +00:00
|
|
|
controller.client = {id: '1234'};
|
|
|
|
controller.newPassword = 'm24x8';
|
2017-09-21 06:48:25 +00:00
|
|
|
controller.canChangePassword = true;
|
2017-08-29 10:33:48 +00:00
|
|
|
controller.repeatPassword = 'notMatchingPassword';
|
2020-07-29 08:47:48 +00:00
|
|
|
controller.onPassChange();
|
2017-09-20 12:01:33 +00:00
|
|
|
|
2017-08-29 10:33:48 +00:00
|
|
|
expect(vnApp.showError).toHaveBeenCalledWith(`Passwords don't match`);
|
|
|
|
});
|
|
|
|
});
|
2017-08-25 06:42:53 +00:00
|
|
|
});
|
|
|
|
});
|