mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-2200] fixed problem with redirection url (#2877)
* [ADF-2200] fixed wrong handling of redirectUrl * [ADF-2200] fixed problem with redirection url * [ADF-2200] fixed redirection config path * [ADF-2200] fixed wrong fdescribe test * [ADF-2200] removed authserviceMock and fixed some tests
This commit is contained in:
@@ -15,14 +15,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { async, inject, TestBed } from '@angular/core/testing';
|
||||
import { Router } from '@angular/router';
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
import { CookieServiceMock } from './../mock/cookie.service.mock';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { SettingsService } from './settings.service';
|
||||
import { AppConfigModule } from '../app-config/app-config.module';
|
||||
import { AppConfigService } from '../app-config/app-config.service';
|
||||
import { AuthGuardBpm } from './auth-guard-bpm.service';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
import { CookieService } from './cookie.service';
|
||||
@@ -30,9 +30,15 @@ import { LogService } from './log.service';
|
||||
import { StorageService } from './storage.service';
|
||||
import { TranslateLoaderService } from './translate-loader.service';
|
||||
import { UserPreferencesService } from './user-preferences.service';
|
||||
import { RouterStateSnapshot, Router } from '@angular/router';
|
||||
|
||||
describe('AuthGuardService BPM', () => {
|
||||
|
||||
let authGuard: AuthGuardBpm;
|
||||
let authService: AuthenticationService;
|
||||
let routerService: Router;
|
||||
let appConfigService: AppConfigService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
@@ -58,43 +64,58 @@ describe('AuthGuardService BPM', () => {
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
it('if the alfresco js api is logged in should canActivate be true',
|
||||
async(inject([AuthGuardBpm, Router, SettingsService, StorageService, AuthenticationService], (auth, router, settingsService, storage, authService) => {
|
||||
spyOn(router, 'navigate');
|
||||
beforeEach(() => {
|
||||
authService = TestBed.get(AuthenticationService);
|
||||
authGuard = TestBed.get(AuthGuardBpm);
|
||||
routerService = TestBed.get(Router);
|
||||
appConfigService = TestBed.get(AppConfigService);
|
||||
});
|
||||
|
||||
authService.isBpmLoggedIn = () => {
|
||||
return true;
|
||||
};
|
||||
it('if the alfresco js api is logged in should canActivate be true', async(() => {
|
||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
|
||||
const router: RouterStateSnapshot = <RouterStateSnapshot> {url : ''};
|
||||
|
||||
expect(auth.canActivate(null, { url: '' })).toBeTruthy();
|
||||
expect(router.navigate).not.toHaveBeenCalled();
|
||||
}))
|
||||
);
|
||||
expect(authGuard.canActivate(null, router)).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('if the alfresco js api is NOT logged in should canActivate be false',
|
||||
async(inject([AuthGuardBpm, Router, SettingsService, StorageService, AuthenticationService], (auth, router, settingsService, storage, authService) => {
|
||||
it('if the alfresco js api is NOT logged in should canActivate be false', async(() => {
|
||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
|
||||
spyOn(routerService, 'navigate').and.stub();
|
||||
const router: RouterStateSnapshot = <RouterStateSnapshot> { url: '' };
|
||||
|
||||
spyOn(router, 'navigate');
|
||||
expect(authGuard.canActivate(null, router)).toBeFalsy();
|
||||
}));
|
||||
|
||||
authService.isBpmLoggedIn = () => {
|
||||
return false;
|
||||
};
|
||||
it('if the alfresco js api is NOT logged in should trigger a redirect event', async(() => {
|
||||
spyOn(routerService, 'navigate');
|
||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
|
||||
const router: RouterStateSnapshot = <RouterStateSnapshot> {url : ''};
|
||||
|
||||
expect(auth.canActivate(null, { url: '' })).toBeFalsy();
|
||||
expect(router.navigate).toHaveBeenCalled();
|
||||
}))
|
||||
);
|
||||
expect(authGuard.canActivate(null, router)).toBeFalsy();
|
||||
expect(routerService.navigate).toHaveBeenCalledWith(['/login']);
|
||||
}));
|
||||
|
||||
it('should set redirect url',
|
||||
async(inject([AuthGuardBpm, Router, AuthenticationService], (auth, router, authService) => {
|
||||
const state = { url: 'some-url' };
|
||||
it('should set redirect url', async(() => {
|
||||
spyOn(authService, 'setRedirectUrl').and.callThrough();
|
||||
spyOn(routerService, 'navigate').and.stub();
|
||||
const router: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
||||
|
||||
spyOn(router, 'navigate');
|
||||
spyOn(authService, 'setRedirectUrl');
|
||||
authGuard.canActivate(null, router);
|
||||
|
||||
auth.canActivate(null , state);
|
||||
expect(authService.setRedirectUrl).toHaveBeenCalledWith({provider: 'BPM', url: 'some-url' } );
|
||||
expect(authService.getRedirectUrl('BPM')).toBe('some-url');
|
||||
}));
|
||||
|
||||
it('should get redirect url from config if there is one configured', async(() => {
|
||||
appConfigService.config.loginRoute = 'fakeLoginRoute';
|
||||
spyOn(authService, 'setRedirectUrl').and.callThrough();
|
||||
spyOn(routerService, 'navigate').and.stub();
|
||||
const router: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
||||
|
||||
authGuard.canActivate(null, router);
|
||||
|
||||
expect(authService.setRedirectUrl).toHaveBeenCalledWith({provider: 'BPM', url: 'some-url' } );
|
||||
expect(routerService.navigate).toHaveBeenCalledWith(['/fakeLoginRoute']);
|
||||
}));
|
||||
|
||||
expect(authService.setRedirectUrl).toHaveBeenCalledWith(state.url);
|
||||
}))
|
||||
);
|
||||
});
|
||||
|
Reference in New Issue
Block a user