diff --git a/src/app/access-control/group-registry/group-page.guard.spec.ts b/src/app/access-control/group-registry/group-page.guard.spec.ts index b1bfd82c27..9a301faab0 100644 --- a/src/app/access-control/group-registry/group-page.guard.spec.ts +++ b/src/app/access-control/group-registry/group-page.guard.spec.ts @@ -1,83 +1,100 @@ -// import { GroupPageGuard } from './group-page.guard'; -// import { HALEndpointService } from '../../core/shared/hal-endpoint.service'; -// import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service'; -// import { ActivatedRouteSnapshot, Router } from '@angular/router'; -// import { of as observableOf } from 'rxjs'; -// import { AuthService } from '../../core/auth/auth.service'; -// import { FeatureID } from '../../core/data/feature-authorization/feature-id'; -// -// describe('GroupPageGuard', () => { -// const groupsEndpointUrl = 'https://test.org/api/eperson/groups'; -// const groupUuid = '0d6f89df-f95a-4829-943c-f21f434fb892'; -// const groupEndpointUrl = `${groupsEndpointUrl}/${groupUuid}`; -// const routeSnapshotWithGroupId = { -// params: { -// groupId: groupUuid, -// } -// } as unknown as ActivatedRouteSnapshot; -// -// let guard: GroupPageGuard; -// let halEndpointService: HALEndpointService; -// let authorizationService: AuthorizationDataService; -// let router: Router; -// let authService: AuthService; -// -// beforeEach(() => { -// halEndpointService = jasmine.createSpyObj(['getEndpoint']); -// (halEndpointService as any).getEndpoint.and.returnValue(observableOf(groupsEndpointUrl)); -// -// authorizationService = jasmine.createSpyObj(['isAuthorized']); -// // NOTE: value is set in beforeEach -// -// router = jasmine.createSpyObj(['parseUrl']); -// (router as any).parseUrl.and.returnValue = {}; -// -// authService = jasmine.createSpyObj(['isAuthenticated']); -// (authService as any).isAuthenticated.and.returnValue(observableOf(true)); -// -// guard = new GroupPageGuard(halEndpointService, authorizationService, router, authService); -// }); -// -// it('should be created', () => { -// expect(guard).toBeTruthy(); -// }); -// -// describe('canActivate', () => { -// describe('when the current user can manage the group', () => { -// beforeEach(() => { -// (authorizationService as any).isAuthorized.and.returnValue(observableOf(true)); -// }); -// -// it('should return true', (done) => { -// guard.canActivate( -// routeSnapshotWithGroupId, { url: 'current-url'} as any -// ).subscribe((result) => { -// expect(authorizationService.isAuthorized).toHaveBeenCalledWith( -// FeatureID.CanManageGroup, groupEndpointUrl, undefined -// ); -// expect(result).toBeTrue(); -// done(); -// }); -// }); -// }); -// -// describe('when the current user can not manage the group', () => { -// beforeEach(() => { -// (authorizationService as any).isAuthorized.and.returnValue(observableOf(false)); -// }); -// -// it('should not return true', (done) => { -// guard.canActivate( -// routeSnapshotWithGroupId, { url: 'current-url'} as any -// ).subscribe((result) => { -// expect(authorizationService.isAuthorized).toHaveBeenCalledWith( -// FeatureID.CanManageGroup, groupEndpointUrl, undefined -// ); -// expect(result).not.toBeTrue(); -// done(); -// }); -// }); -// }); -// }); -// -// }); +import { HALEndpointService } from '../../core/shared/hal-endpoint.service'; +import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service'; +import { ActivatedRouteSnapshot, Router, UrlTree } from '@angular/router'; +import { of as observableOf, Observable } from 'rxjs'; +import { AuthService } from '../../core/auth/auth.service'; +import { TestBed, waitForAsync } from '@angular/core/testing'; +import { groupPageGuard } from './group-page.guard'; +import { FeatureID } from '../../core/data/feature-authorization/feature-id'; +jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; // Increase timeout to 10 seconds + +describe('GroupPageGuard', () => { + const groupsEndpointUrl = 'https://test.org/api/eperson/groups'; + const groupUuid = '0d6f89df-f95a-4829-943c-f21f434fb892'; + const groupEndpointUrl = `${groupsEndpointUrl}/${groupUuid}`; + const routeSnapshotWithGroupId = { + params: { + groupId: groupUuid, + } + } as unknown as ActivatedRouteSnapshot; + + let halEndpointService: HALEndpointService; + let authorizationService: AuthorizationDataService; + let router: Router; + let authService: AuthService; + + function init() { + halEndpointService = jasmine.createSpyObj(['getEndpoint']); + ( halEndpointService as any ).getEndpoint.and.returnValue(observableOf(groupsEndpointUrl)); + + authorizationService = jasmine.createSpyObj(['isAuthorized']); + // NOTE: value is set in beforeEach + + router = jasmine.createSpyObj(['parseUrl']); + ( router as any ).parseUrl.and.returnValue = {}; + + authService = jasmine.createSpyObj(['isAuthenticated']); + ( authService as any ).isAuthenticated.and.returnValue(observableOf(true)); + + TestBed.configureTestingModule({ + providers: [ + { provide: AuthorizationDataService, useValue: authorizationService }, + { provide: Router, useValue: router }, + { provide: AuthService, useValue: authService }, + { provide: HALEndpointService, useValue: halEndpointService }, + ] + }); + } + + beforeEach(waitForAsync(() => { + init(); + })); + + it('should be created', () => { + expect(groupPageGuard).toBeTruthy(); + }); + + describe('canActivate', () => { + describe('when the current user can manage the group', () => { + beforeEach(() => { + ( authorizationService as any ).isAuthorized.and.returnValue(observableOf(true)); + }); + + it('should return true', (done) => { + const result$ = TestBed.runInInjectionContext(() => { + return groupPageGuard()(routeSnapshotWithGroupId, { url: 'current-url' } as any); + }) as Observable; + + result$.subscribe((result) => { + expect(authorizationService.isAuthorized).toHaveBeenCalledWith( + FeatureID.CanManageGroup, groupEndpointUrl, undefined + ); + expect(result).toBeTrue(); + done(); + }); + }); + }); + + describe('when the current user can not manage the group', () => { + beforeEach(() => { + (authorizationService as any).isAuthorized.and.returnValue(observableOf(false)); + }); + + it('should not return true', (done) => { + const result$ = TestBed.runInInjectionContext(() => { + return groupPageGuard()(routeSnapshotWithGroupId, { url: 'current-url' } as any); + }) as Observable; + + result$.subscribe((result) => { + expect(authorizationService.isAuthorized).toHaveBeenCalledWith( + FeatureID.CanManageGroup, groupEndpointUrl, undefined + ); + expect(result).not.toBeTrue(); + done(); + }); + + }); + }); + }); + +}); diff --git a/src/app/access-control/group-registry/group-page.guard.ts b/src/app/access-control/group-registry/group-page.guard.ts index b5e39bdff5..ef49088a76 100644 --- a/src/app/access-control/group-registry/group-page.guard.ts +++ b/src/app/access-control/group-registry/group-page.guard.ts @@ -4,7 +4,7 @@ import { inject } from '@angular/core'; import { map } from 'rxjs/operators'; import { HALEndpointService } from '../../core/shared/hal-endpoint.service'; import { - StringGuardParamFn, someFeatureAuthorizationGuard, SomeFeatureGuardParamFn + StringGuardParamFn, someFeatureAuthorizationGuard } from '../../core/data/feature-authorization/feature-authorization-guard/some-feature-authorization.guard'; import { FeatureID } from '../../core/data/feature-authorization/feature-id'; @@ -21,7 +21,6 @@ const defaultGroupPageGetObjectUrl: StringGuardParamFn = ( }; export const groupPageGuard = ( - getFeatureIDs: SomeFeatureGuardParamFn, getObjectUrl = defaultGroupPageGetObjectUrl, getEPersonUuid?: StringGuardParamFn, ): CanActivateFn => someFeatureAuthorizationGuard( diff --git a/src/app/core/data/feature-authorization/feature-authorization-guard/dso-page-single-feature.guard.spec.ts b/src/app/core/data/feature-authorization/feature-authorization-guard/dso-page-single-feature.guard.spec.ts index fdd173ab4d..0d967fc03d 100644 --- a/src/app/core/data/feature-authorization/feature-authorization-guard/dso-page-single-feature.guard.spec.ts +++ b/src/app/core/data/feature-authorization/feature-authorization-guard/dso-page-single-feature.guard.spec.ts @@ -1,87 +1,89 @@ -// import { AuthorizationDataService } from '../authorization-data.service'; -// import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router'; -// import { RemoteData } from '../../remote-data'; -// import { Observable, of as observableOf } from 'rxjs'; -// import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils'; -// import { DSpaceObject } from '../../../shared/dspace-object.model'; -// import { DsoPageSingleFeatureGuard } from './dso-page-single-feature.guard'; -// import { FeatureID } from '../feature-id'; -// import { AuthService } from '../../../auth/auth.service'; -// -// /** -// * Test implementation of abstract class DsoPageSingleFeatureGuard -// */ -// class DsoPageSingleFeatureGuardImpl extends DsoPageSingleFeatureGuard { -// constructor(protected resolver: Resolve>, -// protected authorizationService: AuthorizationDataService, -// protected router: Router, -// protected authService: AuthService, -// protected featureID: FeatureID) { -// super(resolver, authorizationService, router, authService); -// } -// -// getFeatureID(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { -// return observableOf(this.featureID); -// } -// } -// -// describe('DsoPageSingleFeatureGuard', () => { -// let guard: DsoPageSingleFeatureGuard; -// let authorizationService: AuthorizationDataService; -// let router: Router; -// let authService: AuthService; -// let resolver: Resolve>; -// let object: DSpaceObject; -// let route; -// let parentRoute; -// -// function init() { -// object = { -// self: 'test-selflink' -// } as DSpaceObject; -// -// authorizationService = jasmine.createSpyObj('authorizationService', { -// isAuthorized: observableOf(true) -// }); -// router = jasmine.createSpyObj('router', { -// parseUrl: {} -// }); -// resolver = jasmine.createSpyObj('resolver', { -// resolve: createSuccessfulRemoteDataObject$(object) -// }); -// authService = jasmine.createSpyObj('authService', { -// isAuthenticated: observableOf(true) -// }); -// parentRoute = { -// params: { -// id: '3e1a5327-dabb-41ff-af93-e6cab9d032f0' -// } -// }; -// route = { -// params: { -// }, -// parent: parentRoute -// }; -// guard = new DsoPageSingleFeatureGuardImpl(resolver, authorizationService, router, authService, undefined); -// } -// -// beforeEach(() => { -// init(); -// }); -// -// describe('getObjectUrl', () => { -// it('should return the resolved object\'s selflink', (done) => { -// guard.getObjectUrl(route, undefined).subscribe((selflink) => { -// expect(selflink).toEqual(object.self); -// done(); -// }); -// }); -// }); -// -// describe('getRouteWithDSOId', () => { -// it('should return the route that has the UUID of the DSO', () => { -// const foundRoute = (guard as any).getRouteWithDSOId(route); -// expect(foundRoute).toBe(parentRoute); -// }); -// }); -// }); +import { AuthorizationDataService } from '../authorization-data.service'; +import { Router, UrlTree, ResolveFn } from '@angular/router'; +import { RemoteData } from '../../remote-data'; +import { Observable, of as observableOf } from 'rxjs'; +import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils'; +import { DSpaceObject } from '../../../shared/dspace-object.model'; +import { AuthService } from '../../../auth/auth.service'; +import { TestBed } from '@angular/core/testing'; +import { dsoPageSingleFeatureGuard } from './dso-page-single-feature.guard'; +import { FeatureID } from '../feature-id'; + + +describe('DsoPageSingleFeatureGuard', () => { + let authorizationService: AuthorizationDataService; + let router: Router; + let authService: AuthService; + let resolver: ResolveFn>>; + // let resolver: jasmine.SpyObj<() => Observable>>; + let object: DSpaceObject; + let route; + let parentRoute; + + let featureId: FeatureID; + + function init() { + object = { + self: 'test-selflink' + } as DSpaceObject; + + authorizationService = jasmine.createSpyObj('authorizationService', { + isAuthorized: observableOf(true) + }); + router = jasmine.createSpyObj('router', { + parseUrl: {} + }); + resolver = jasmine.createSpyObj('resolver', { + resolve: createSuccessfulRemoteDataObject$(object) + }); + // resolver = jasmine.createSpy('resolver') // Mocking the resolver function + // .and.returnValue(observableOf({})); // Returning an observable directly + authService = jasmine.createSpyObj('authService', { + isAuthenticated: observableOf(true) + }); + parentRoute = { + params: { + id: '3e1a5327-dabb-41ff-af93-e6cab9d032f0' + } + }; + route = { + params: { + }, + parent: parentRoute + }; + + featureId = FeatureID.LoginOnBehalfOf; + + TestBed.configureTestingModule({ + providers: [ + { provide: AuthorizationDataService, useValue: authorizationService }, + { provide: Router, useValue: router }, + { provide: AuthService, useValue: authService }, + ] + }); + } + + beforeEach(() => { + init(); + }); + + describe('canActivate', () => { + it('should call authorizationService.isAuthenticated with the appropriate arguments', (done) => { + const result$ = TestBed.runInInjectionContext(() => { + return dsoPageSingleFeatureGuard( + () => resolver, () => observableOf(featureId) + )(route, { url: 'current-url' } as any); + }) as Observable; + + console.log('result$', result$); + + result$.subscribe(() => { + expect(authorizationService.isAuthorized).toHaveBeenCalledWith(featureId); + done(); + }); + + // expect(authorizationService.isAuthorized).toHaveBeenCalledWith(featureId); + // done(); + }); + }); +}); diff --git a/src/app/core/data/feature-authorization/feature-authorization-guard/dso-page-some-feature.guard.spec.ts b/src/app/core/data/feature-authorization/feature-authorization-guard/dso-page-some-feature.guard.spec.ts index 8735aa9293..f0f5e5e63f 100644 --- a/src/app/core/data/feature-authorization/feature-authorization-guard/dso-page-some-feature.guard.spec.ts +++ b/src/app/core/data/feature-authorization/feature-authorization-guard/dso-page-some-feature.guard.spec.ts @@ -1,87 +1,96 @@ -// import { AuthorizationDataService } from '../authorization-data.service'; -// import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router'; -// import { RemoteData } from '../../remote-data'; -// import { Observable, of as observableOf } from 'rxjs'; -// import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils'; -// import { DSpaceObject } from '../../../shared/dspace-object.model'; -// import { FeatureID } from '../feature-id'; -// import { AuthService } from '../../../auth/auth.service'; -// import { DsoPageSomeFeatureGuard } from './dso-page-some-feature.guard'; -// -// /** -// * Test implementation of abstract class DsoPageSomeFeatureGuard -// */ -// class DsoPageSomeFeatureGuardImpl extends DsoPageSomeFeatureGuard { -// constructor(protected resolver: Resolve>, -// protected authorizationService: AuthorizationDataService, -// protected router: Router, -// protected authService: AuthService, -// protected featureIDs: FeatureID[]) { -// super(resolver, authorizationService, router, authService); -// } -// -// getFeatureIDs(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { -// return observableOf(this.featureIDs); -// } -// } -// -// describe('DsoPageSomeFeatureGuard', () => { -// let guard: DsoPageSomeFeatureGuard; -// let authorizationService: AuthorizationDataService; -// let router: Router; -// let authService: AuthService; -// let resolver: Resolve>; -// let object: DSpaceObject; -// let route; -// let parentRoute; -// -// function init() { -// object = { -// self: 'test-selflink' -// } as DSpaceObject; -// -// authorizationService = jasmine.createSpyObj('authorizationService', { -// isAuthorized: observableOf(true) -// }); -// router = jasmine.createSpyObj('router', { -// parseUrl: {} -// }); -// resolver = jasmine.createSpyObj('resolver', { -// resolve: createSuccessfulRemoteDataObject$(object) -// }); -// authService = jasmine.createSpyObj('authService', { -// isAuthenticated: observableOf(true) -// }); -// parentRoute = { -// params: { -// id: '3e1a5327-dabb-41ff-af93-e6cab9d032f0' -// } -// }; -// route = { -// params: { -// }, -// parent: parentRoute -// }; -// guard = new DsoPageSomeFeatureGuardImpl(resolver, authorizationService, router, authService, []); -// } -// -// beforeEach(() => { -// init(); -// }); -// -// describe('getObjectUrl', () => { -// it('should return the resolved object\'s selflink', (done) => { -// guard.getObjectUrl(route, undefined).subscribe((selflink) => { -// expect(selflink).toEqual(object.self); -// done(); -// }); -// }); -// }); -// -// describe('getRouteWithDSOId', () => { -// it('should return the route that has the UUID of the DSO', () => { -// const foundRoute = (guard as any).getRouteWithDSOId(route); -// expect(foundRoute).toBe(parentRoute); -// }); -// }); -// }); +import { AuthorizationDataService } from '../authorization-data.service'; +import { Resolve, Router, UrlTree, ResolveFn } from '@angular/router'; +import { RemoteData } from '../../remote-data'; +import { Observable, of as observableOf } from 'rxjs'; +import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils'; +import { DSpaceObject } from '../../../shared/dspace-object.model'; +import { AuthService } from '../../../auth/auth.service'; +import { dsoPageSomeFeatureGuard } from './dso-page-some-feature.guard'; +import { TestBed } from '@angular/core/testing'; +import { FeatureID } from '../feature-id'; + + +describe('DsoPageSomeFeatureGuard', () => { + let authorizationService: AuthorizationDataService; + let router: Router; + let authService: AuthService; + // let resolver: Resolve>; + let resolver: ResolveFn>>; + let object: DSpaceObject; + let route; + let parentRoute; + + let featureIds: FeatureID[]; + + function init() { + object = { + self: 'test-selflink' + } as DSpaceObject; + + authorizationService = jasmine.createSpyObj('authorizationService', { + isAuthorized: observableOf(true) + }); + router = jasmine.createSpyObj('router', { + parseUrl: {} + }); + // resolver = jasmine.createSpyObj('resolver', { + // resolve: createSuccessfulRemoteDataObject$(object) + // }); + authService = jasmine.createSpyObj('authService', { + isAuthenticated: observableOf(true) + }); + parentRoute = { + params: { + id: '3e1a5327-dabb-41ff-af93-e6cab9d032f0' + } + }; + route = { + params: { + }, + parent: parentRoute + }; + + TestBed.configureTestingModule({ + providers: [ + { provide: AuthorizationDataService, useValue: authorizationService }, + { provide: Router, useValue: router }, + { provide: AuthService, useValue: authService }, + ] + }); + + } + + beforeEach(() => { + init(); + }); + + describe('getObjectUrl', () => { + it('should return the resolved object\'s selflink', (done) => { + + const result$ = TestBed.runInInjectionContext(() => { + return dsoPageSomeFeatureGuard( + () => resolver, () => observableOf(featureIds) + )(route, { url: 'current-url' } as any); + }) as Observable; + + console.log('result$', result$); + + result$.subscribe(() => { + expect(authorizationService.isAuthorized).toHaveBeenCalledWith(featureIds[0]); + done(); + }); + + // guard.getObjectUrl(route, undefined).subscribe((selflink) => { + // expect(selflink).toEqual(object.self); + // done(); + // }); + }); + }); + + // describe('getRouteWithDSOId', () => { + // it('should return the route that has the UUID of the DSO', () => { + // const foundRoute = (guard as any).getRouteWithDSOId(route); + // expect(foundRoute).toBe(parentRoute); + // }); + // }); +}); diff --git a/src/app/core/data/feature-authorization/feature-authorization-guard/single-feature-authorization.guard.spec.ts b/src/app/core/data/feature-authorization/feature-authorization-guard/single-feature-authorization.guard.spec.ts index fc631ee9ac..dc518ddaff 100644 --- a/src/app/core/data/feature-authorization/feature-authorization-guard/single-feature-authorization.guard.spec.ts +++ b/src/app/core/data/feature-authorization/feature-authorization-guard/single-feature-authorization.guard.spec.ts @@ -6,9 +6,7 @@ import { AuthService } from '../../../auth/auth.service'; import { singleFeatureAuthorizationGuard } from './single-feature-authorization.guard'; import { waitForAsync, TestBed } from '@angular/core/testing'; - describe('singleFeatureAuthorizationGuard', () => { - let guard: any; let authorizationService: AuthorizationDataService; let router: Router; let authService: AuthService; @@ -45,21 +43,22 @@ describe('singleFeatureAuthorizationGuard', () => { init(); })); - it('should call authorizationService.isAuthenticated with the appropriate arguments', (done: DoneFn) => { - const result$ = TestBed.runInInjectionContext(() => { - return singleFeatureAuthorizationGuard( - () => observableOf(featureId), - () => observableOf(objectUrl), - () => observableOf(ePersonUuid), - )(undefined, { url: 'current-url' } as any) - }) as Observable; + describe('canActivate', () => { + it('should call authorizationService.isAuthenticated with the appropriate arguments', (done: DoneFn) => { + const result$ = TestBed.runInInjectionContext(() => { + return singleFeatureAuthorizationGuard( + () => observableOf(featureId), + () => observableOf(objectUrl), + () => observableOf(ePersonUuid), + )(undefined, { url: 'current-url' } as any); + }) as Observable; - result$.subscribe(() => { - expect(authorizationService.isAuthorized).toHaveBeenCalledWith(featureId, objectUrl, ePersonUuid); - done(); - }) + result$.subscribe(() => { + expect(authorizationService.isAuthorized).toHaveBeenCalledWith(featureId, objectUrl, ePersonUuid); + done(); + }); + }); + }); - }); - diff --git a/src/app/core/data/feature-authorization/feature-authorization-guard/some-feature-authorization.guard.spec.ts b/src/app/core/data/feature-authorization/feature-authorization-guard/some-feature-authorization.guard.spec.ts index 8f95cd2ee2..c12668d6a5 100644 --- a/src/app/core/data/feature-authorization/feature-authorization-guard/some-feature-authorization.guard.spec.ts +++ b/src/app/core/data/feature-authorization/feature-authorization-guard/some-feature-authorization.guard.spec.ts @@ -1,13 +1,12 @@ import { AuthorizationDataService } from '../authorization-data.service'; import { FeatureID } from '../feature-id'; import { Observable, of as observableOf } from 'rxjs'; -import { Router, UrlTree, CanActivateFn } from '@angular/router'; +import { Router, UrlTree } from '@angular/router'; import { AuthService } from '../../../auth/auth.service'; -import { waitForAsync, TestBed } from '@angular/core/testing'; import { someFeatureAuthorizationGuard } from './some-feature-authorization.guard'; +import { TestBed, waitForAsync } from '@angular/core/testing'; -describe('someFeatureAuthorizationGuard', () => { - let guard: CanActivateFn; +describe('SomeFeatureAuthorizationGuard', () => { let authorizationService: AuthorizationDataService; let router: Router; let authService: AuthService; @@ -28,9 +27,11 @@ describe('someFeatureAuthorizationGuard', () => { return observableOf(authorizedFeatureIds.indexOf(featureId) > -1); } }); + router = jasmine.createSpyObj('router', { parseUrl: {} }); + authService = jasmine.createSpyObj('authService', { isAuthenticated: observableOf(true) }); @@ -42,65 +43,76 @@ describe('someFeatureAuthorizationGuard', () => { { provide: AuthService, useValue: authService }, ] }); - - guard = someFeatureAuthorizationGuard( - () => observableOf(featureIds), - () => observableOf(objectUrl), - () => observableOf(ePersonUuid), - ); } beforeEach(waitForAsync(() => { init(); })); - describe('when the user isn\'t authorized', () => { - beforeEach(() => { - authorizedFeatureIds = []; - }); + describe('canActivate', () => { + describe('when the user isn\'t authorized', () => { + beforeEach(() => { + authorizedFeatureIds = []; + }); - it('should not return true', (done: DoneFn) => { - const result$ = TestBed.runInInjectionContext(() => { - return guard(undefined, { url: 'current-url' } as any) - }) as Observable; + it('should not return true', (done) => { - result$.subscribe((result) => { - expect(result).not.toEqual(true); - done(); + const result$ = TestBed.runInInjectionContext(() => { + return someFeatureAuthorizationGuard( + () => observableOf(featureIds), + () => observableOf(objectUrl), + () => observableOf(ePersonUuid), + )(undefined, { url: 'current-url' } as any); + }) as Observable; + + result$.subscribe((result) => { + expect(result).not.toEqual(true); + done(); + }); }); }); - }); - describe('when the user is authorized for at least one of the guard\'s features', () => { - beforeEach(() => { - authorizedFeatureIds = [featureIds[0]]; - }); + describe('when the user is authorized for at least one of the guard\'s features', () => { + beforeEach(() => { + authorizedFeatureIds = [featureIds[0]]; + }); - it('should return true', (done) => { - const result$ = TestBed.runInInjectionContext(() => { - return guard(undefined, { url: 'current-url' } as any) - }) as Observable; + it('should return true', (done) => { - result$.subscribe((result) => { - expect(result).toEqual(true); - done(); + const result$ = TestBed.runInInjectionContext(() => { + return someFeatureAuthorizationGuard( + () => observableOf(featureIds), + () => observableOf(objectUrl), + () => observableOf(ePersonUuid), + )(undefined, { url: 'current-url' } as any); + }) as Observable; + + result$.subscribe((result) => { + expect(result).toEqual(true); + done(); + }); }); }); - }); - describe('when the user is authorized for all of the guard\'s features', () => { - beforeEach(() => { - authorizedFeatureIds = featureIds; - }); + describe('when the user is authorized for all of the guard\'s features', () => { + beforeEach(() => { + authorizedFeatureIds = featureIds; + }); - it('should return true', (done) => { - const result$ = TestBed.runInInjectionContext(() => { - return guard(undefined, { url: 'current-url' } as any) - }) as Observable; + it('should return true', (done) => { - result$.subscribe((result) => { - expect(result).toEqual(true); - done(); + const result$ = TestBed.runInInjectionContext(() => { + return someFeatureAuthorizationGuard( + () => observableOf(featureIds), + () => observableOf(objectUrl), + () => observableOf(ePersonUuid), + )(undefined, { url: 'current-url' } as any); + }) as Observable; + + result$.subscribe((result) => { + expect(result).toEqual(true); + done(); + }); }); }); });