Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should edit and send form with valid data', () => {
let url = [
new UrlSegment('edit', { name: 'edit' }),
new UrlSegment('file', { name: 'file' })
];
// The isEditMode needs data and that is set until the second
// ngOnChanges, that's why we delay this a little bit
route.url = Observable.of(url).delay(100);
let snapshot: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
route.snapshot = snapshot;
route.snapshot.url = url;
let data: any = {
clazz: 'com.dotcms.contenttype.model.type.ImmutableFileAssetContentType',
defaultType: false,
description: 'Hey I\'m a description',
fields: [],
fixed: false,
folder: 'SYSTEM_FOLDER',
host: 'host-identifier',
iDate: 1496963858000,
id: '1234567890',
modDate: 1496967718000,
multilingualable: false,
name: 'A content type name',
it(`should return default when page and sort and defaultSort is undefined`, inject([JhiResolvePagingParams], (service: JhiResolvePagingParams) => {
const route = new ActivatedRouteSnapshot();
route.queryParams = { page: undefined, sort: undefined };
route.data = { defaultSort: undefined };
const { page, predicate, ascending } = service.resolve(route, null);
expect(page).toEqual(1);
expect(predicate).toEqual('id');
expect(ascending).toEqual(true);
}));
constructor() {
this.snapshot = new ActivatedRouteSnapshot();
}
it('Should canActivate be false hasRealm is true and hasClientRole is false', () => {
const materialDialog = TestBed.get(MatDialog);
spyOn(materialDialog, 'closeAll');
const route: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
spyOn(jwtHelperService, 'hasRealmRoles').and.returnValue(true);
spyOn(jwtHelperService, 'hasRealmRolesForClientRole').and.returnValue(false);
route.params = { appName: 'fakeapp' };
route.data = { 'clientRoles': ['appName'], 'roles': ['role1', 'role2'] };
expect(materialDialog.closeAll).toHaveBeenCalled();
});
it('should resolve with existing lab if id is given', () => {
const existingLab = Object.assign({}, LAB_STUB);
const activatedRouteSnapshotStub = new ActivatedRouteSnapshot();
activatedRouteSnapshotStub.params = { id: 'some-id' };
spyOn(labStorageService, 'getLab').and.returnValue(of(existingLab));
labResolver.resolve(activatedRouteSnapshotStub).subscribe(lab => {
expect(labStorageService.getLab).toHaveBeenCalledWith(activatedRouteSnapshotStub.params['id']);
expect(lab).toEqual(existingLab);
});
});
it('Should canActivate return false if the data Role to check is empty', async(() => {
spyOn(jwtHelperService, 'getAccessToken').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue({ 'realm_access': { roles: ['role1', 'role3'] } });
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
expect(authGuard.canActivate(router)).toBeFalsy();
}));
it('Should canActivate be true if both Real Role and Client Role are present int the JWT token', () => {
const route: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
spyOn(jwtHelperService, 'getAccessToken').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue({
'realm_access': { roles: ['role1'] },
'resource_access': { fakeapp: { roles: ['role2'] } }
});
route.params = { appName: 'fakeapp' };
route.data = { 'clientRoles': ['appName'], 'roles': ['role1', 'role2'] };
expect(authGuard.canActivate(route)).toBeTruthy();
});
beforeEach(() => {
TestBed.configureTestingModule({
providers: [UserLabsResolver, SnackbarService, { provide: LabStorageService, useValue: labStorageStub }],
imports: [MatSnackBarModule]
});
userLabsResolver = TestBed.get(UserLabsResolver);
labStorage = TestBed.get(LabStorageService);
routeSnapshotStub = new ActivatedRouteSnapshot();
spyOn(labStorage, 'getLabsFromUser').and.returnValue(of(null));
});
(service: AuthGuardService, store$: Store) => {
const fixture = TestBed.createComponent(RoutingComponent);
const guard$ = service.canActivate(new ActivatedRouteSnapshot(), mockSnapshot);
const auth$ = store$.pipe(select(getAuth));
const merge$ = guard$.pipe(
withLatestFrom(
auth$, (g, a) => ({ result: g, auth: a.err === undefined && a.user !== undefined })));
merge$.subscribe(r => {
expect(r.result).toBe(r.auth);
});
store$.dispatch({
type: authActions.LOGIN_SUCCESS,
payload: {
token: 'xxxx',
user: { id: 'xxxx', email: 'abc@dev.local', name: 'xxxx', password: 'sssss' }
}
});
})));
constructor() {
super();
this.params = of({ key: 'key1', appName: 'app1' });
this.queryParams = of({ key: 'key1', appName: 'app1', version: 0, branch: 'master' });
this.snapshot = new ActivatedRouteSnapshot();
let project = new Project();
project.key = 'key1';
this.snapshot.data = {
project: project
};
this.snapshot.queryParams = { key: 'key1', appName: 'app1', version: 0, branch: 'master' };
this.data = of({ project: project });
}
}