mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Cache redesign part 1, and add support for alternative links
This commit is contained in:
@@ -6,18 +6,14 @@ import { RequestEntry } from '../data/request.reducer';
|
||||
import { RequestService } from '../data/request.service';
|
||||
import {
|
||||
configureRequest,
|
||||
filterSuccessfulResponses,
|
||||
getAllSucceededRemoteData,
|
||||
getRemoteDataPayload,
|
||||
getRequestFromRequestHref,
|
||||
getRequestFromRequestUUID,
|
||||
getResourceLinksFromResponse,
|
||||
getResponseFromEntry,
|
||||
getSucceededRemoteData,
|
||||
getFirstSucceededRemoteData,
|
||||
redirectOn4xx
|
||||
} from './operators';
|
||||
import { RemoteData } from '../data/remote-data';
|
||||
import { RemoteDataError } from '../data/remote-data-error';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import {
|
||||
createFailedRemoteDataObject,
|
||||
@@ -118,29 +114,6 @@ describe('Core Module - RxJS Operators', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('filterSuccessfulResponses', () => {
|
||||
it('should only return responses for which isSuccessful === true', () => {
|
||||
const source = hot('abcde', testRCEs);
|
||||
const result = source.pipe(filterSuccessfulResponses());
|
||||
const expected = cold('a--d-', testResponses);
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getResourceLinksFromResponse', () => {
|
||||
it('should return the resourceSelfLinks for all successful responses', () => {
|
||||
const source = hot('abcde', testRCEs);
|
||||
const result = source.pipe(getResourceLinksFromResponse());
|
||||
const expected = cold('a--d-', {
|
||||
a: testRCEs.a.response.resourceSelfLinks,
|
||||
d: testRCEs.d.response.resourceSelfLinks
|
||||
});
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('configureRequest', () => {
|
||||
it('should call requestService.configure with the source request', () => {
|
||||
requestService = getMockRequestService();
|
||||
@@ -182,20 +155,19 @@ describe('Core Module - RxJS Operators', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSucceededRemoteData', () => {
|
||||
describe('getFirstSucceededRemoteData', () => {
|
||||
it('should return the first() hasSucceeded RemoteData Observable', () => {
|
||||
const testRD = {
|
||||
a: createSuccessfulRemoteDataObject(undefined),
|
||||
b: createFailedRemoteDataObject( 'b'),
|
||||
c: new RemoteData(false, false, undefined, null, 'c'),
|
||||
a: createFailedRemoteDataObject(),
|
||||
b: createFailedRemoteDataObject(),
|
||||
c: createSuccessfulRemoteDataObject('c'),
|
||||
d: createSuccessfulRemoteDataObject('d'),
|
||||
e: createSuccessfulRemoteDataObject('e'),
|
||||
};
|
||||
const source = hot('abcde', testRD);
|
||||
const result = source.pipe(getSucceededRemoteData());
|
||||
const source = hot('abcd', testRD);
|
||||
const result = source.pipe(getFirstSucceededRemoteData());
|
||||
const expected = cold('--(c|)', testRD);
|
||||
|
||||
result.subscribe((value) => expect(value)
|
||||
.toEqual(createSuccessfulRemoteDataObject('d')));
|
||||
expect(result).toBeObservable(expected);
|
||||
|
||||
});
|
||||
});
|
||||
@@ -213,21 +185,21 @@ describe('Core Module - RxJS Operators', () => {
|
||||
});
|
||||
|
||||
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'));
|
||||
const testRD = createFailedRemoteDataObject('Object was not found', 404);
|
||||
|
||||
observableOf(testRD).pipe(redirectOn4xx(router, authService)).subscribe();
|
||||
expect(router.navigateByUrl).toHaveBeenCalledWith('/404', { skipLocationChange: true });
|
||||
});
|
||||
|
||||
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'));
|
||||
it('should call navigateByUrl to a 401 page, when the remote data contains a 403 error', () => {
|
||||
const testRD = createFailedRemoteDataObject('Forbidden', 403);
|
||||
|
||||
observableOf(testRD).pipe(redirectOn4xx(router, authService)).subscribe();
|
||||
expect(router.navigateByUrl).toHaveBeenCalledWith('/403', { skipLocationChange: true });
|
||||
});
|
||||
|
||||
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'));
|
||||
const testRD = createFailedRemoteDataObject('Something went wrong', 500);
|
||||
|
||||
observableOf(testRD).pipe(redirectOn4xx(router, authService)).subscribe();
|
||||
expect(router.navigateByUrl).not.toHaveBeenCalled();
|
||||
@@ -246,7 +218,7 @@ describe('Core Module - RxJS Operators', () => {
|
||||
});
|
||||
|
||||
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'));
|
||||
const testRD = createFailedRemoteDataObject('The current user is unauthorized', 401);
|
||||
|
||||
observableOf(testRD).pipe(redirectOn4xx(router, authService)).subscribe();
|
||||
expect(authService.setRedirectUrl).toHaveBeenCalled();
|
||||
@@ -254,7 +226,7 @@ describe('Core Module - RxJS Operators', () => {
|
||||
});
|
||||
|
||||
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'));
|
||||
const testRD = createFailedRemoteDataObject('Forbidden', 403);
|
||||
|
||||
observableOf(testRD).pipe(redirectOn4xx(router, authService)).subscribe();
|
||||
expect(authService.setRedirectUrl).toHaveBeenCalled();
|
||||
@@ -282,15 +254,14 @@ describe('Core Module - RxJS Operators', () => {
|
||||
describe('getAllSucceededRemoteData', () => {
|
||||
it('should return all hasSucceeded RemoteData Observables', () => {
|
||||
const testRD = {
|
||||
a: createSuccessfulRemoteDataObject(undefined),
|
||||
b: createFailedRemoteDataObject('b'),
|
||||
c: new RemoteData(false, false, undefined, null, 'c'),
|
||||
a: createFailedRemoteDataObject(),
|
||||
b: createFailedRemoteDataObject(),
|
||||
c: createSuccessfulRemoteDataObject('c'),
|
||||
d: createSuccessfulRemoteDataObject('d'),
|
||||
e: createSuccessfulRemoteDataObject('e'),
|
||||
};
|
||||
const source = hot('abcde', testRD);
|
||||
const source = hot('abcd', testRD);
|
||||
const result = source.pipe(getAllSucceededRemoteData());
|
||||
const expected = cold('---de', testRD);
|
||||
const expected = cold('--cd', testRD);
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
|
||||
|
Reference in New Issue
Block a user