mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
ensure getByUUID still returns undefined when there's no match
This commit is contained in:
@@ -140,13 +140,21 @@ describe('RequestService', () => {
|
|||||||
describe('getByUUID', () => {
|
describe('getByUUID', () => {
|
||||||
describe('if the request with the specified UUID exists in the store', () => {
|
describe('if the request with the specified UUID exists in the store', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
selectSpy.and.callFake(() => {
|
let callCounter = 0;
|
||||||
return () => {
|
const responses = [
|
||||||
return () => hot('a', {
|
cold('a', { // A direct hit in the request cache
|
||||||
a: {
|
a: {
|
||||||
completed: true
|
completed: true
|
||||||
}
|
}
|
||||||
});
|
}),
|
||||||
|
cold('b', { b: undefined }), // No hit in the index
|
||||||
|
cold('c', { c: undefined }) // So no mapped hit in the request cache
|
||||||
|
];
|
||||||
|
selectSpy.and.callFake(() => {
|
||||||
|
return () => {
|
||||||
|
const response = responses[callCounter];
|
||||||
|
callCounter++;
|
||||||
|
return () => response;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -165,17 +173,25 @@ describe('RequestService', () => {
|
|||||||
|
|
||||||
describe(`if the request with the specified UUID doesn't exist in the store `, () => {
|
describe(`if the request with the specified UUID doesn't exist in the store `, () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
let callCounter = 0;
|
||||||
|
const responses = [
|
||||||
|
cold('a', { a: undefined }), // No direct hit in the request cache
|
||||||
|
cold('b', { b: undefined }), // No hit in the index
|
||||||
|
cold('c', { c: undefined }), // So no mapped hit in the request cache
|
||||||
|
];
|
||||||
selectSpy.and.callFake(() => {
|
selectSpy.and.callFake(() => {
|
||||||
return () => {
|
return () => {
|
||||||
return () => hot('a', { a: undefined });
|
const response = responses[callCounter];
|
||||||
|
callCounter++;
|
||||||
|
return () => response;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`it shouldn't return anything`, () => {
|
it('should return an Observable of undefined', () => {
|
||||||
const result = service.getByUUID(testUUID);
|
const result = service.getByUUID(testUUID);
|
||||||
|
|
||||||
scheduler.expectObservable(result).toBe('');
|
scheduler.expectObservable(result).toBe('a', { a: undefined });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -183,13 +199,12 @@ describe('RequestService', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
let callCounter = 0;
|
let callCounter = 0;
|
||||||
const responses = [
|
const responses = [
|
||||||
cold('a', { a: undefined }), // No hit in the request cache with that UUID
|
cold('a', { a: undefined }), // No direct hit in the request cache with that UUID
|
||||||
cold('b', { b: 'otherRequestUUID' }), // A hit in the index, which returns the uuid of the cached request
|
cold('b', { b: 'otherRequestUUID' }), // A hit in the index, which returns the uuid of the cached request
|
||||||
cold('c', { c: { // the call to retrieve the cached request using the UUID from the index
|
cold('c', { // the call to retrieve the cached request using the UUID from the index
|
||||||
c: {
|
c: {
|
||||||
completed: true
|
completed: true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
selectSpy.and.callFake(() => {
|
selectSpy.and.callFake(() => {
|
||||||
@@ -204,11 +219,10 @@ describe('RequestService', () => {
|
|||||||
it(`it should return the cached request`, () => {
|
it(`it should return the cached request`, () => {
|
||||||
const result = service.getByUUID(testUUID);
|
const result = service.getByUUID(testUUID);
|
||||||
|
|
||||||
scheduler.expectObservable(result).toBe('c', { c: {
|
scheduler.expectObservable(result).toBe('c', {
|
||||||
c: {
|
c: {
|
||||||
completed: true
|
completed: true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -2,8 +2,8 @@ import { Injectable } from '@angular/core';
|
|||||||
import { HttpHeaders } from '@angular/common/http';
|
import { HttpHeaders } from '@angular/common/http';
|
||||||
|
|
||||||
import { createSelector, MemoizedSelector, select, Store } from '@ngrx/store';
|
import { createSelector, MemoizedSelector, select, Store } from '@ngrx/store';
|
||||||
import { Observable, race as observableRace } from 'rxjs';
|
import { Observable, combineLatest as observableCombineLatest } from 'rxjs';
|
||||||
import { filter, map, mergeMap, take, switchMap } from 'rxjs/operators';
|
import { filter, map, mergeMap, take, switchMap, startWith } from 'rxjs/operators';
|
||||||
import { cloneDeep, remove } from 'lodash';
|
import { cloneDeep, remove } from 'lodash';
|
||||||
import { hasValue, isEmpty, isNotEmpty, hasValueOperator } from '../../shared/empty.util';
|
import { hasValue, isEmpty, isNotEmpty, hasValueOperator } from '../../shared/empty.util';
|
||||||
import { CacheableObject } from '../cache/object-cache.reducer';
|
import { CacheableObject } from '../cache/object-cache.reducer';
|
||||||
@@ -110,24 +110,19 @@ export class RequestService {
|
|||||||
* Retrieve a RequestEntry based on their uuid
|
* Retrieve a RequestEntry based on their uuid
|
||||||
*/
|
*/
|
||||||
getByUUID(uuid: string): Observable<RequestEntry> {
|
getByUUID(uuid: string): Observable<RequestEntry> {
|
||||||
return observableRace(
|
return observableCombineLatest([
|
||||||
this.store.pipe(
|
this.store.pipe(
|
||||||
select(entryFromUUIDSelector(uuid)),
|
select(entryFromUUIDSelector(uuid))
|
||||||
hasValueOperator()
|
|
||||||
),
|
),
|
||||||
this.store.pipe(
|
this.store.pipe(
|
||||||
select(originalRequestUUIDFromRequestUUIDSelector(uuid)),
|
select(originalRequestUUIDFromRequestUUIDSelector(uuid)),
|
||||||
switchMap((originalUUID) => {
|
switchMap((originalUUID) => {
|
||||||
if (hasValue(originalUUID)) {
|
|
||||||
return this.store.pipe(select(entryFromUUIDSelector(originalUUID)))
|
return this.store.pipe(select(entryFromUUIDSelector(originalUUID)))
|
||||||
} else {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
hasValueOperator()
|
),
|
||||||
)
|
]).pipe(
|
||||||
).pipe(
|
map((entries: RequestEntry[]) => entries.find((entry: RequestEntry) => hasValue(entry))),
|
||||||
map((entry: RequestEntry) => {
|
map((entry: RequestEntry) => {
|
||||||
// Headers break after being retrieved from the store (because of lazy initialization)
|
// Headers break after being retrieved from the store (because of lazy initialization)
|
||||||
// Combining them with a new object fixes this issue
|
// Combining them with a new object fixes this issue
|
||||||
|
Reference in New Issue
Block a user