forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zahraa Chreim
committed
May 9, 2024
1 parent
b83b2dd
commit 16c75be
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/app/item-page/edit-item-page/item-page-edit-authorizations.guard.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { UrlTree, Router } from '@angular/router'; | ||
import { Observable, of as observableOf } from 'rxjs'; | ||
import { AuthService } from 'src/app/core/auth/auth.service'; | ||
import { AuthorizationDataService } from 'src/app/core/data/feature-authorization/authorization-data.service'; | ||
import { FeatureID } from 'src/app/core/data/feature-authorization/feature-id'; | ||
import { | ||
Store, | ||
} from '@ngrx/store'; | ||
|
||
import { itemPageEditAuthorizationsGuard } from './item-page-edit-authorizations.guard'; | ||
import { APP_DATA_SERVICES_MAP } from '../../../config/app-config.interface'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { getMockTranslateService } from '../../shared/mocks/translate.service.mock'; | ||
import { | ||
dsoPageSingleFeatureGuard | ||
} from '../../core/data/feature-authorization/feature-authorization-guard/dso-page-single-feature.guard'; | ||
|
||
describe('itemPageEditAuthorizationsGuard', () => { | ||
let authorizationService: AuthorizationDataService; | ||
let authService: AuthService; | ||
let router: Router; | ||
let route; | ||
let parentRoute; | ||
let store: Store; | ||
|
||
beforeEach(() => { | ||
|
||
store = jasmine.createSpyObj('store', { | ||
dispatch: {}, | ||
pipe: observableOf(true), | ||
}); | ||
authorizationService = jasmine.createSpyObj('authorizationService', { | ||
isAuthorized: observableOf(true), | ||
}); | ||
router = jasmine.createSpyObj('router', { | ||
parseUrl: {}, | ||
}); | ||
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 }, | ||
{ provide: Store, useValue: store }, | ||
{ provide: APP_DATA_SERVICES_MAP, useValue: {} }, | ||
{ provide: TranslateService, useValue: getMockTranslateService() }, | ||
], | ||
}); | ||
}); | ||
|
||
it('should call authorizationService.isAuthorized with the appropriate arguments', (done) => { | ||
const result$ = TestBed.runInInjectionContext(() => { | ||
return itemPageEditAuthorizationsGuard(route, { url: 'current-url' } as any); | ||
}) as Observable<boolean | UrlTree>; | ||
|
||
console.log('will subscribe'); | ||
result$.subscribe((result) => { | ||
console.log('result inside subscribe:', result); | ||
expect(authorizationService.isAuthorized).toHaveBeenCalledWith( | ||
FeatureID.CanManagePolicies, | ||
'fake-object-url', | ||
'fake-eperson-uuid', | ||
); | ||
done(); | ||
}); | ||
|
||
}); | ||
}); |