Merge remote-tracking branch 'remotes/origin/main' into upgrade_angular10

# Conflicts:
#	package.json
#	server.ts
#	src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.ts
#	src/app/+admin/admin-access-control/group-registry/group-form/group-form.component.ts
#	src/app/+admin/admin-access-control/group-registry/groups-registry.component.spec.ts
#	src/app/+admin/admin-access-control/group-registry/groups-registry.component.ts
#	src/app/+collection-page/collection-page.component.ts
#	src/app/+item-page/edit-item-page/item-page-reinstate.guard.ts
#	src/app/+item-page/edit-item-page/item-page-withdraw.guard.ts
#	src/app/+item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts
#	src/app/+item-page/edit-item-page/item-relationships/item-relationships.component.ts
#	src/app/+item-page/item-page-administrator.guard.ts
#	src/app/app-routing.module.ts
#	src/app/community-list-page/community-list-service.ts
#	src/app/core/data/entity-type.service.ts
#	src/app/core/data/feature-authorization/feature-authorization-guard/dso-page-feature.guard.spec.ts
#	src/app/core/data/feature-authorization/feature-authorization-guard/feature-authorization.guard.spec.ts
#	src/app/core/data/feature-authorization/feature-authorization-guard/feature-authorization.guard.ts
#	src/app/core/data/feature-authorization/feature-authorization-guard/site-administrator.guard.ts
#	src/app/core/data/feature-authorization/feature-authorization-guard/site-register.guard.ts
#	src/app/core/data/object-updates/object-updates.reducer.ts
#	src/app/core/shared/operators.ts
#	src/app/process-page/detail/process-detail.component.ts
#	src/app/shared/comcol-forms/delete-comcol-page/delete-comcol-page.component.ts
#	src/app/shared/dso-selector/dso-selector/dso-selector.component.ts
#	src/app/shared/input-suggestions/filter-suggestions/filter-input-suggestions.component.ts
#	src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.ts
#	src/app/shared/shared.module.ts
#	yarn.lock
This commit is contained in:
Giuseppe Digilio
2020-12-04 11:36:48 +01:00
254 changed files with 4580 additions and 1029 deletions

View File

@@ -14,7 +14,7 @@ import {
getResourceLinksFromResponse,
getResponseFromEntry,
getSucceededRemoteData,
redirectOn404Or401
redirectOn4xx
} from './operators';
import { RemoteData } from '../data/remote-data';
import { RemoteDataError } from '../data/remote-data-error';
@@ -200,39 +200,67 @@ describe('Core Module - RxJS Operators', () => {
});
});
describe('redirectOn404Or401', () => {
describe('redirectOn4xx', () => {
let router;
let authService;
beforeEach(() => {
router = jasmine.createSpyObj('router', ['navigateByUrl']);
authService = jasmine.createSpyObj('authService', {
isAuthenticated: observableOf(true),
setRedirectUrl: {}
});
});
it('should call navigateByUrl to a 404 page, when the remote data contains a 404 error', () => {
const testRD = createFailedRemoteDataObject(undefined, new RemoteDataError(404, 'Not Found', 'Object was not found'));
observableOf(testRD).pipe(redirectOn404Or401(router)).subscribe();
observableOf(testRD).pipe(redirectOn4xx(router, authService)).subscribe();
expect(router.navigateByUrl).toHaveBeenCalledWith('/404', { skipLocationChange: true });
});
it('should call navigateByUrl to a 401 page, when the remote data contains a 401 error', () => {
const testRD = createFailedRemoteDataObject(undefined, new RemoteDataError(401, 'Unauthorized', 'The current user is unauthorized'));
it('should call navigateByUrl to a 403 page, when the remote data contains a 403 error', () => {
const testRD = createFailedRemoteDataObject(undefined, new RemoteDataError(403, 'Forbidden', 'Forbidden access'));
observableOf(testRD).pipe(redirectOn404Or401(router)).subscribe();
expect(router.navigateByUrl).toHaveBeenCalledWith('/401', { skipLocationChange: true });
observableOf(testRD).pipe(redirectOn4xx(router, authService)).subscribe();
expect(router.navigateByUrl).toHaveBeenCalledWith('/403', { skipLocationChange: true });
});
it('should not call navigateByUrl to a 404 or 401 page, when the remote data contains another error than a 404 or 401', () => {
it('should not call navigateByUrl to a 404, 403 or 401 page, when the remote data contains another error than a 404, 403 or 401', () => {
const testRD = createFailedRemoteDataObject(undefined, new RemoteDataError(500, 'Server Error', 'Something went wrong'));
observableOf(testRD).pipe(redirectOn404Or401(router)).subscribe();
observableOf(testRD).pipe(redirectOn4xx(router, authService)).subscribe();
expect(router.navigateByUrl).not.toHaveBeenCalled();
});
it('should not call navigateByUrl to a 404 or 401 page, when the remote data contains no error', () => {
it('should not call navigateByUrl to a 404, 403 or 401 page, when the remote data contains no error', () => {
const testRD = createSuccessfulRemoteDataObject(undefined);
observableOf(testRD).pipe(redirectOn404Or401(router)).subscribe();
observableOf(testRD).pipe(redirectOn4xx(router, authService)).subscribe();
expect(router.navigateByUrl).not.toHaveBeenCalled();
});
describe('when the user is not authenticated', () => {
beforeEach(() => {
(authService.isAuthenticated as jasmine.Spy).and.returnValue(observableOf(false));
});
it('should set the redirect url and navigate to login when the remote data contains a 401 error', () => {
const testRD = createFailedRemoteDataObject(undefined, new RemoteDataError(401, 'Unauthorized', 'The current user is unauthorized'));
observableOf(testRD).pipe(redirectOn4xx(router, authService)).subscribe();
expect(authService.setRedirectUrl).toHaveBeenCalled();
expect(router.navigateByUrl).toHaveBeenCalledWith('login');
});
it('should set the redirect url and navigate to login when the remote data contains a 403 error', () => {
const testRD = createFailedRemoteDataObject(undefined, new RemoteDataError(403, 'Forbidden', 'Forbidden access'));
observableOf(testRD).pipe(redirectOn4xx(router, authService)).subscribe();
expect(authService.setRedirectUrl).toHaveBeenCalled();
expect(router.navigateByUrl).toHaveBeenCalledWith('login');
});
});
});
describe('getResponseFromEntry', () => {