Skip to content

Commit

Permalink
115016: Fixed tests for 114858
Browse files Browse the repository at this point in the history
  • Loading branch information
LotteHofstede committed May 10, 2024
1 parent 16c75be commit 0eb61dd
Showing 1 changed file with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
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 { 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 { 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';
import { ItemDataService } from '../../core/data/item-data.service';
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
import { Item } from '../../core/shared/item.model';

describe('itemPageEditAuthorizationsGuard', () => {
let authorizationService: AuthorizationDataService;
Expand All @@ -23,6 +21,10 @@ describe('itemPageEditAuthorizationsGuard', () => {
let route;
let parentRoute;
let store: Store;
let itemService: ItemDataService;
let item: Item;
let uuid = '1234-abcdef-54321-fedcba';
let itemSelfLink = 'test.url/1234-abcdef-54321-fedcba';

beforeEach(() => {

Expand All @@ -35,6 +37,7 @@ describe('itemPageEditAuthorizationsGuard', () => {
});
router = jasmine.createSpyObj('router', {
parseUrl: {},
navigateByUrl: undefined,
});
authService = jasmine.createSpyObj('authService', {
isAuthenticated: observableOf(true),
Expand All @@ -46,10 +49,13 @@ describe('itemPageEditAuthorizationsGuard', () => {
},
};
route = {
params: {
},
params: {},
parent: parentRoute,
};
item = new Item();
item.uuid = uuid;
item._links = { self: { href: itemSelfLink } } as any;
itemService = jasmine.createSpyObj('itemService', { findById: createSuccessfulRemoteDataObject$(item) })

TestBed.configureTestingModule({
providers: [
Expand All @@ -59,6 +65,7 @@ describe('itemPageEditAuthorizationsGuard', () => {
{ provide: Store, useValue: store },
{ provide: APP_DATA_SERVICES_MAP, useValue: {} },
{ provide: TranslateService, useValue: getMockTranslateService() },
{ provide: ItemDataService, useValue: itemService },
],
});
});
Expand All @@ -73,8 +80,8 @@ describe('itemPageEditAuthorizationsGuard', () => {
console.log('result inside subscribe:', result);
expect(authorizationService.isAuthorized).toHaveBeenCalledWith(
FeatureID.CanManagePolicies,
'fake-object-url',
'fake-eperson-uuid',
itemSelfLink, // This value is retrieved from the itemDataService.findById's return item's self link
undefined, // dsoPageSingleFeatureGuard never provides a function to retrieve a person ID
);
done();
});
Expand Down

0 comments on commit 0eb61dd

Please sign in to comment.