2020-03-09 08:00:03 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('component vnUserDescriptor', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
|
|
|
let user = {id: 1, name: 'foo'};
|
|
|
|
|
|
|
|
beforeEach(ngModule('account'));
|
|
|
|
|
|
|
|
beforeEach(inject(($componentController, _$httpBackend_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
2023-01-31 13:57:24 +00:00
|
|
|
$httpBackend.whenGET('Accounts/1/exists').respond({exists: true});
|
2020-03-09 08:00:03 +00:00
|
|
|
|
|
|
|
controller = $componentController('vnUserDescriptor', {$element: null}, {user});
|
|
|
|
jest.spyOn(controller, 'emit');
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('onDelete()', () => {
|
|
|
|
it('should delete entity and go to index', () => {
|
|
|
|
controller.$state.go = jest.fn();
|
|
|
|
|
2023-01-23 14:24:00 +00:00
|
|
|
$httpBackend.expectDELETE('VnUsers/1').respond();
|
2020-03-09 08:00:03 +00:00
|
|
|
controller.onDelete();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('account.index');
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onPassChange()', () => {
|
|
|
|
it('should throw an error when password is empty', () => {
|
|
|
|
expect(() => {
|
|
|
|
controller.onPassChange();
|
|
|
|
}).toThrowErrorMatchingSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw an error when repeat password not matches new password', () => {
|
|
|
|
controller.newPassword = 'foo';
|
|
|
|
controller.repeatPassword = 'bar';
|
|
|
|
|
|
|
|
expect(() => {
|
|
|
|
controller.onPassChange();
|
|
|
|
}).toThrowErrorMatchingSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should make a request when password checks passes', () => {
|
|
|
|
controller.newPassword = 'foo';
|
|
|
|
controller.repeatPassword = 'foo';
|
|
|
|
|
2023-04-15 12:24:50 +00:00
|
|
|
$httpBackend.expectPATCH('Accounts/1/setPassword').respond();
|
2020-03-09 08:00:03 +00:00
|
|
|
controller.onPassChange();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
expect(controller.emit).toHaveBeenCalledWith('change');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onEnableAccount()', () => {
|
|
|
|
it('should make request to enable account', () => {
|
2023-01-31 13:57:24 +00:00
|
|
|
$httpBackend.expectPOST('Accounts', {id: 1}).respond();
|
2020-03-09 08:00:03 +00:00
|
|
|
controller.onEnableAccount();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.hasAccount).toBeTruthy();
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
expect(controller.emit).toHaveBeenCalledWith('change');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onDisableAccount()', () => {
|
|
|
|
it('should make request to disable account', () => {
|
2023-01-31 13:57:24 +00:00
|
|
|
$httpBackend.expectDELETE('Accounts/1').respond();
|
2020-03-09 08:00:03 +00:00
|
|
|
controller.onDisableAccount();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.hasAccount).toBeFalsy();
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
expect(controller.emit).toHaveBeenCalledWith('change');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onSetActive()', () => {
|
|
|
|
it('should make request to activate/deactivate the user', () => {
|
2023-01-23 14:24:00 +00:00
|
|
|
$httpBackend.expectPATCH('VnUsers/1', {active: true}).respond();
|
2020-03-09 08:00:03 +00:00
|
|
|
controller.onSetActive(true);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.user.active).toBeTruthy();
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
expect(controller.emit).toHaveBeenCalledWith('change');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|