11import { TestBed } from '@angular/core/testing' ;
2- import { UrlTree , Router } from '@angular/router' ;
2+ import { Router , UrlTree } from '@angular/router' ;
33import { Observable , of as observableOf } from 'rxjs' ;
44import { AuthService } from 'src/app/core/auth/auth.service' ;
55import { AuthorizationDataService } from 'src/app/core/data/feature-authorization/authorization-data.service' ;
66import { FeatureID } from 'src/app/core/data/feature-authorization/feature-id' ;
7- import {
8- Store ,
9- } from '@ngrx/store' ;
7+ import { Store , } from '@ngrx/store' ;
108
119import { itemPageEditAuthorizationsGuard } from './item-page-edit-authorizations.guard' ;
1210import { APP_DATA_SERVICES_MAP } from '../../../config/app-config.interface' ;
1311import { TranslateService } from '@ngx-translate/core' ;
1412import { getMockTranslateService } from '../../shared/mocks/translate.service.mock' ;
15- import {
16- dsoPageSingleFeatureGuard
17- } from '../../core/data/feature-authorization/feature-authorization-guard/dso-page-single-feature.guard ' ;
13+ import { ItemDataService } from '../../core/data/item-data.service' ;
14+ import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils' ;
15+ import { Item } from '../../core/shared/item.model ' ;
1816
1917describe ( 'itemPageEditAuthorizationsGuard' , ( ) => {
2018 let authorizationService : AuthorizationDataService ;
@@ -23,6 +21,10 @@ describe('itemPageEditAuthorizationsGuard', () => {
2321 let route ;
2422 let parentRoute ;
2523 let store : Store ;
24+ let itemService : ItemDataService ;
25+ let item : Item ;
26+ let uuid = '1234-abcdef-54321-fedcba' ;
27+ let itemSelfLink = 'test.url/1234-abcdef-54321-fedcba' ;
2628
2729 beforeEach ( ( ) => {
2830
@@ -35,6 +37,7 @@ describe('itemPageEditAuthorizationsGuard', () => {
3537 } ) ;
3638 router = jasmine . createSpyObj ( 'router' , {
3739 parseUrl : { } ,
40+ navigateByUrl : undefined ,
3841 } ) ;
3942 authService = jasmine . createSpyObj ( 'authService' , {
4043 isAuthenticated : observableOf ( true ) ,
@@ -46,10 +49,13 @@ describe('itemPageEditAuthorizationsGuard', () => {
4649 } ,
4750 } ;
4851 route = {
49- params : {
50- } ,
52+ params : { } ,
5153 parent : parentRoute ,
5254 } ;
55+ item = new Item ( ) ;
56+ item . uuid = uuid ;
57+ item . _links = { self : { href : itemSelfLink } } as any ;
58+ itemService = jasmine . createSpyObj ( 'itemService' , { findById : createSuccessfulRemoteDataObject$ ( item ) } )
5359
5460 TestBed . configureTestingModule ( {
5561 providers : [
@@ -59,6 +65,7 @@ describe('itemPageEditAuthorizationsGuard', () => {
5965 { provide : Store , useValue : store } ,
6066 { provide : APP_DATA_SERVICES_MAP , useValue : { } } ,
6167 { provide : TranslateService , useValue : getMockTranslateService ( ) } ,
68+ { provide : ItemDataService , useValue : itemService } ,
6269 ] ,
6370 } ) ;
6471 } ) ;
@@ -73,8 +80,8 @@ describe('itemPageEditAuthorizationsGuard', () => {
7380 console . log ( 'result inside subscribe:' , result ) ;
7481 expect ( authorizationService . isAuthorized ) . toHaveBeenCalledWith (
7582 FeatureID . CanManagePolicies ,
76- 'fake-object-url' ,
77- 'fake-eperson-uuid' ,
83+ itemSelfLink , // This value is retrieved from the itemDataService.findById's return item's self link
84+ undefined , // dsoPageSingleFeatureGuard never provides a function to retrieve a person ID
7885 ) ;
7986 done ( ) ;
8087 } ) ;
0 commit comments