106 lines
3.9 KiB
JavaScript
106 lines
3.9 KiB
JavaScript
import './index';
|
|
|
|
describe('Component VnClientWebAccess', () => {
|
|
let $httpBackend;
|
|
let $scope;
|
|
let vnApp;
|
|
let controller;
|
|
|
|
beforeEach(() => {
|
|
ngModule('client');
|
|
});
|
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => {
|
|
$scope = $rootScope.$new();
|
|
$httpBackend = _$httpBackend_;
|
|
vnApp = _vnApp_;
|
|
spyOn(vnApp, 'showError');
|
|
controller = $componentController('vnClientWebAccess', {$scope});
|
|
}));
|
|
|
|
describe('$onChanges()', () => {
|
|
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');
|
|
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`);
|
|
$httpBackend.flush();
|
|
});
|
|
});
|
|
|
|
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()', () => {
|
|
it('should request to update the password', () => {
|
|
controller.client = {id: '1234'};
|
|
controller.newPassword = 'm24x8';
|
|
controller.repeatPassword = 'm24x8';
|
|
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`, () => {
|
|
it(`should throw Passwords can't be empty error`, () => {
|
|
controller.client = {id: '1234'};
|
|
controller.newPassword = '';
|
|
controller.canChangePassword = true;
|
|
controller.onPassChange('ACCEPT');
|
|
|
|
expect(vnApp.showError).toHaveBeenCalledWith(`Passwords can't be empty`);
|
|
});
|
|
});
|
|
|
|
describe(`when passwords don't match`, () => {
|
|
it(`should throw Passwords don't match error`, () => {
|
|
controller.client = {id: '1234'};
|
|
controller.newPassword = 'm24x8';
|
|
controller.canChangePassword = true;
|
|
controller.repeatPassword = 'notMatchingPassword';
|
|
controller.onPassChange('ACCEPT');
|
|
|
|
expect(vnApp.showError).toHaveBeenCalledWith(`Passwords don't match`);
|
|
});
|
|
});
|
|
});
|
|
});
|