Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/app/core/data/bitstream-data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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',
Expand All @@ -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));
Expand Down
17 changes: 15 additions & 2 deletions src/app/core/data/bitstream-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,25 @@
sendRequest(this.requestService),
take(1),
).subscribe(() => {
this.requestService.removeByHrefSubstring(bitstream.self + '/format');
this.deleteFormatCache(bitstream);
});

return this.rdbService.buildFromRequestUUID(requestId);
}

private deleteFormatCache(bitstream: Bitstream) {
const bitsreamFormatUrl = bitstream.self + '/format';
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) => {
if (cachedRequest.requestUUIDs && cachedRequest.requestUUIDs.length > 0){
const requestUuid = cachedRequest.requestUUIDs[0];

Check warning on line 177 in src/app/core/data/bitstream-data.service.ts

View check run for this annotation

Codecov / codecov/patch

src/app/core/data/bitstream-data.service.ts#L177

Added line #L177 was not covered by tests
if (this.requestService.hasByUUID(requestUuid)) {
this.requestService.setStaleByUUID(requestUuid);

Check warning on line 179 in src/app/core/data/bitstream-data.service.ts

View check run for this annotation

Codecov / codecov/patch

src/app/core/data/bitstream-data.service.ts#L179

Added line #L179 was not covered by tests
}
}
});
}

/**
* Returns an observable of {@link RemoteData} of a {@link Bitstream}, based on a handle and an
* optional sequenceId or filename, with a list of {@link FollowLinkConfig}, to automatically
Expand Down
Loading