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

115 lines
4.2 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;
beforeEach(ngModule('client'));
2017-08-25 06:42:53 +00:00
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => {
$scope = $rootScope.$new();
$httpBackend = _$httpBackend_;
vnApp = _vnApp_;
2020-02-26 12:22:52 +00:00
jest.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`, () => {
2020-02-26 12:22:52 +00:00
jest.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()', () => {
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
$httpBackend.expectGET(`Clients/${controller.client.id}/hasCustomerRole`).respond({isCustomer: 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'};
$httpBackend.expectGET(`Clients/${controller.client.id}/hasCustomerRole`).respond({isCustomer: false});
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-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', `Clients/${controller.client.id}/isValidClient`).respond(false);
$httpBackend.expectGET(`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', 'Accounts/1234').respond('done');
$httpBackend.expectPATCH('Accounts/1234', {password: 'm24x8'});
2019-10-30 15:57:14 +00:00
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;
2019-10-30 15:57:14 +00:00
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';
2019-10-30 15:57:14 +00:00
controller.onPassChange('accept');
expect(vnApp.showError).toHaveBeenCalledWith(`Passwords don't match`);
});
});
2017-08-25 06:42:53 +00:00
});
});