fix unit tests for bitstream-data.service.ts

This commit is contained in:
Jesiel Viana
2025-04-24 10:04:41 -03:00
parent 4f48f39f7b
commit bb536192c2
2 changed files with 13 additions and 3 deletions

View File

@@ -37,6 +37,8 @@ import {
} from './request.models'; } from './request.models';
import { RequestService } from './request.service'; import { RequestService } from './request.service';
import objectContaining = jasmine.objectContaining; import objectContaining = jasmine.objectContaining;
import { RestResponse } from '../cache/response.models';
import { RequestEntry } from './request-entry.model';
describe('BitstreamDataService', () => { describe('BitstreamDataService', () => {
let service: BitstreamDataService; let service: BitstreamDataService;
@@ -47,6 +49,7 @@ describe('BitstreamDataService', () => {
let rdbService: RemoteDataBuildService; let rdbService: RemoteDataBuildService;
let bundleDataService: BundleDataService; let bundleDataService: BundleDataService;
const bitstreamFormatHref = 'rest-api/bitstreamformats'; const bitstreamFormatHref = 'rest-api/bitstreamformats';
let responseCacheEntry: RequestEntry;
const bitstream1 = Object.assign(new Bitstream(), { const bitstream1 = Object.assign(new Bitstream(), {
id: 'fake-bitstream1', id: 'fake-bitstream1',
@@ -71,8 +74,13 @@ describe('BitstreamDataService', () => {
const url = 'fake-bitstream-url'; const url = 'fake-bitstream-url';
beforeEach(() => { beforeEach(() => {
responseCacheEntry = new RequestEntry();
responseCacheEntry.request = { href: 'https://rest.api/' } as any;
responseCacheEntry.response = new RestResponse(true, 200, 'Success');
objectCache = jasmine.createSpyObj('objectCache', { objectCache = jasmine.createSpyObj('objectCache', {
remove: jasmine.createSpy('remove'), remove: jasmine.createSpy('remove'),
getByHref: observableOf(responseCacheEntry),
}); });
requestService = getMockRequestService(); requestService = getMockRequestService();
halService = Object.assign(new HALEndpointServiceStub(url)); halService = Object.assign(new HALEndpointServiceStub(url));

View File

@@ -173,9 +173,11 @@ export class BitstreamDataService extends IdentifiableDataService<Bitstream> imp
this.requestService.setStaleByHrefSubstring(bitsreamFormatUrl); this.requestService.setStaleByHrefSubstring(bitsreamFormatUrl);
// Delete also cache by uuid as the format could be cached also there // Delete also cache by uuid as the format could be cached also there
this.objectCache.getByHref(bitsreamFormatUrl).pipe(take(1)).subscribe((cachedRequest) => { this.objectCache.getByHref(bitsreamFormatUrl).pipe(take(1)).subscribe((cachedRequest) => {
const requestUuid = cachedRequest.requestUUIDs[0]; if (cachedRequest.requestUUIDs && cachedRequest.requestUUIDs.length > 0){
if (this.requestService.hasByUUID(requestUuid)) { const requestUuid = cachedRequest.requestUUIDs[0];
this.requestService.setStaleByUUID(requestUuid); if (this.requestService.hasByUUID(requestUuid)) {
this.requestService.setStaleByUUID(requestUuid);
}
} }
}); });
} }