diff --git a/src/app/core/data/bitstream-data.service.spec.ts b/src/app/core/data/bitstream-data.service.spec.ts index 6aa75065d4..68c6b4850c 100644 --- a/src/app/core/data/bitstream-data.service.spec.ts +++ b/src/app/core/data/bitstream-data.service.spec.ts @@ -37,6 +37,8 @@ import { } from './request.models'; import { RequestService } from './request.service'; import objectContaining = jasmine.objectContaining; +import { RestResponse } from '../cache/response.models'; +import { RequestEntry } from './request-entry.model'; describe('BitstreamDataService', () => { let service: BitstreamDataService; @@ -47,6 +49,7 @@ describe('BitstreamDataService', () => { let rdbService: RemoteDataBuildService; let bundleDataService: BundleDataService; const bitstreamFormatHref = 'rest-api/bitstreamformats'; + let responseCacheEntry: RequestEntry; const bitstream1 = Object.assign(new Bitstream(), { id: 'fake-bitstream1', @@ -71,8 +74,13 @@ describe('BitstreamDataService', () => { const url = 'fake-bitstream-url'; beforeEach(() => { + responseCacheEntry = new RequestEntry(); + responseCacheEntry.request = { href: 'https://rest.api/' } as any; + responseCacheEntry.response = new RestResponse(true, 200, 'Success'); + objectCache = jasmine.createSpyObj('objectCache', { remove: jasmine.createSpy('remove'), + getByHref: observableOf(responseCacheEntry), }); requestService = getMockRequestService(); halService = Object.assign(new HALEndpointServiceStub(url)); diff --git a/src/app/core/data/bitstream-data.service.ts b/src/app/core/data/bitstream-data.service.ts index bdf01efc5c..812522ea08 100644 --- a/src/app/core/data/bitstream-data.service.ts +++ b/src/app/core/data/bitstream-data.service.ts @@ -173,9 +173,11 @@ export class BitstreamDataService extends IdentifiableDataService imp this.requestService.setStaleByHrefSubstring(bitsreamFormatUrl); // Delete also cache by uuid as the format could be cached also there this.objectCache.getByHref(bitsreamFormatUrl).pipe(take(1)).subscribe((cachedRequest) => { - const requestUuid = cachedRequest.requestUUIDs[0]; - if (this.requestService.hasByUUID(requestUuid)) { - this.requestService.setStaleByUUID(requestUuid); + if (cachedRequest.requestUUIDs && cachedRequest.requestUUIDs.length > 0){ + const requestUuid = cachedRequest.requestUUIDs[0]; + if (this.requestService.hasByUUID(requestUuid)) { + this.requestService.setStaleByUUID(requestUuid); + } } }); }