mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
115016: Fixed tests for 114858
This commit is contained in:
@@ -1,20 +1,18 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { UrlTree, Router } from '@angular/router';
|
import { Router, UrlTree } from '@angular/router';
|
||||||
import { Observable, of as observableOf } from 'rxjs';
|
import { Observable, of as observableOf } from 'rxjs';
|
||||||
import { AuthService } from 'src/app/core/auth/auth.service';
|
import { AuthService } from 'src/app/core/auth/auth.service';
|
||||||
import { AuthorizationDataService } from 'src/app/core/data/feature-authorization/authorization-data.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 { FeatureID } from 'src/app/core/data/feature-authorization/feature-id';
|
||||||
import {
|
import { Store, } from '@ngrx/store';
|
||||||
Store,
|
|
||||||
} from '@ngrx/store';
|
|
||||||
|
|
||||||
import { itemPageEditAuthorizationsGuard } from './item-page-edit-authorizations.guard';
|
import { itemPageEditAuthorizationsGuard } from './item-page-edit-authorizations.guard';
|
||||||
import { APP_DATA_SERVICES_MAP } from '../../../config/app-config.interface';
|
import { APP_DATA_SERVICES_MAP } from '../../../config/app-config.interface';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { getMockTranslateService } from '../../shared/mocks/translate.service.mock';
|
import { getMockTranslateService } from '../../shared/mocks/translate.service.mock';
|
||||||
import {
|
import { ItemDataService } from '../../core/data/item-data.service';
|
||||||
dsoPageSingleFeatureGuard
|
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||||
} from '../../core/data/feature-authorization/feature-authorization-guard/dso-page-single-feature.guard';
|
import { Item } from '../../core/shared/item.model';
|
||||||
|
|
||||||
describe('itemPageEditAuthorizationsGuard', () => {
|
describe('itemPageEditAuthorizationsGuard', () => {
|
||||||
let authorizationService: AuthorizationDataService;
|
let authorizationService: AuthorizationDataService;
|
||||||
@@ -23,6 +21,10 @@ describe('itemPageEditAuthorizationsGuard', () => {
|
|||||||
let route;
|
let route;
|
||||||
let parentRoute;
|
let parentRoute;
|
||||||
let store: Store;
|
let store: Store;
|
||||||
|
let itemService: ItemDataService;
|
||||||
|
let item: Item;
|
||||||
|
let uuid = '1234-abcdef-54321-fedcba';
|
||||||
|
let itemSelfLink = 'test.url/1234-abcdef-54321-fedcba';
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|
||||||
@@ -35,6 +37,7 @@ describe('itemPageEditAuthorizationsGuard', () => {
|
|||||||
});
|
});
|
||||||
router = jasmine.createSpyObj('router', {
|
router = jasmine.createSpyObj('router', {
|
||||||
parseUrl: {},
|
parseUrl: {},
|
||||||
|
navigateByUrl: undefined,
|
||||||
});
|
});
|
||||||
authService = jasmine.createSpyObj('authService', {
|
authService = jasmine.createSpyObj('authService', {
|
||||||
isAuthenticated: observableOf(true),
|
isAuthenticated: observableOf(true),
|
||||||
@@ -46,10 +49,13 @@ describe('itemPageEditAuthorizationsGuard', () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
route = {
|
route = {
|
||||||
params: {
|
params: {},
|
||||||
},
|
|
||||||
parent: parentRoute,
|
parent: parentRoute,
|
||||||
};
|
};
|
||||||
|
item = new Item();
|
||||||
|
item.uuid = uuid;
|
||||||
|
item._links = { self: { href: itemSelfLink } } as any;
|
||||||
|
itemService = jasmine.createSpyObj('itemService', { findById: createSuccessfulRemoteDataObject$(item) })
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [
|
providers: [
|
||||||
@@ -59,6 +65,7 @@ describe('itemPageEditAuthorizationsGuard', () => {
|
|||||||
{ provide: Store, useValue: store },
|
{ provide: Store, useValue: store },
|
||||||
{ provide: APP_DATA_SERVICES_MAP, useValue: {} },
|
{ provide: APP_DATA_SERVICES_MAP, useValue: {} },
|
||||||
{ provide: TranslateService, useValue: getMockTranslateService() },
|
{ provide: TranslateService, useValue: getMockTranslateService() },
|
||||||
|
{ provide: ItemDataService, useValue: itemService },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -73,8 +80,8 @@ describe('itemPageEditAuthorizationsGuard', () => {
|
|||||||
console.log('result inside subscribe:', result);
|
console.log('result inside subscribe:', result);
|
||||||
expect(authorizationService.isAuthorized).toHaveBeenCalledWith(
|
expect(authorizationService.isAuthorized).toHaveBeenCalledWith(
|
||||||
FeatureID.CanManagePolicies,
|
FeatureID.CanManagePolicies,
|
||||||
'fake-object-url',
|
itemSelfLink, // This value is retrieved from the itemDataService.findById's return item's self link
|
||||||
'fake-eperson-uuid',
|
undefined, // dsoPageSingleFeatureGuard never provides a function to retrieve a person ID
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user