101289: Fixed test issues

This commit is contained in:
lotte
2023-06-08 16:42:25 +02:00
parent a936878c96
commit 9d2fed4186
4 changed files with 37 additions and 18 deletions

View File

@@ -612,7 +612,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
bundle$ = completedBundleRd$.pipe( bundle$ = completedBundleRd$.pipe(
map((bundleRd: RemoteData<Bundle>) => { map((bundleRd: RemoteData<Bundle>) => {
if (bundleRd.hasSucceeded) { if (bundleRd.hasSucceeded) {
return bundleRd.payload return bundleRd.payload;
} else { } else {
return this.bundle; return this.bundle;
} }

View File

@@ -16,7 +16,7 @@ import { Bundle } from '../shared/bundle.model';
import { getTestScheduler } from 'jasmine-marbles'; import { getTestScheduler } from 'jasmine-marbles';
import { of as observableOf } from 'rxjs'; import { of as observableOf } from 'rxjs';
fdescribe('PrimaryBitstreamService', () => { describe('PrimaryBitstreamService', () => {
let service: PrimaryBitstreamService; let service: PrimaryBitstreamService;
let objectCache: ObjectCacheService; let objectCache: ObjectCacheService;
let requestService: RequestService; let requestService: RequestService;
@@ -57,7 +57,7 @@ fdescribe('PrimaryBitstreamService', () => {
describe('getHttpOptions', () => { describe('getHttpOptions', () => {
it('should return a HttpOptions object with text/url-list Context-Type header', () => { it('should return a HttpOptions object with text/url-list Context-Type header', () => {
const result = (service as any).getHttpOptions() const result = (service as any).getHttpOptions();
expect(result.headers.get('Content-Type')).toEqual('text/uri-list'); expect(result.headers.get('Content-Type')).toEqual('text/uri-list');
}); });
}); });
@@ -118,9 +118,20 @@ fdescribe('PrimaryBitstreamService', () => {
}); });
}); });
describe('delete', () => { describe('delete', () => {
const testBundle = Object.assign(new Bundle(), {
_links: {
self: {
href: 'test-href'
},
primaryBitstream: {
href: 'test-primaryBitstream-href'
}
}
});
describe('when the delete request succeeds', () => { describe('when the delete request succeeds', () => {
const testResult = createSuccessfulRemoteDataObject(new Bundle()); const testResult = createSuccessfulRemoteDataObject(new Bundle());
const bundleServiceResult = createSuccessfulRemoteDataObject(bundle); const bundleServiceResult = createSuccessfulRemoteDataObject(testBundle);
beforeEach(() => { beforeEach(() => {
spyOn((service as any), 'createAndSendRequest').and.returnValue(observableOf(testResult)); spyOn((service as any), 'createAndSendRequest').and.returnValue(observableOf(testResult));
@@ -128,30 +139,42 @@ fdescribe('PrimaryBitstreamService', () => {
}); });
it('should delegate the call to createAndSendRequest', () => { it('should delegate the call to createAndSendRequest', () => {
const result = service.delete(bundle); const result = service.delete(testBundle);
getTestScheduler().expectObservable(result).toBe('(a|)', { a: testResult }); getTestScheduler().expectObservable(result).toBe('(a|)', { a: bundleServiceResult });
result.subscribe();
expect(bundleDataService.findByHref).toHaveBeenCalledWith(testBundle.self, false);
expect((service as any).createAndSendRequest).toHaveBeenCalledWith( expect((service as any).createAndSendRequest).toHaveBeenCalledWith(
DeleteRequest, DeleteRequest,
bundle._links.primaryBitstream.href, testBundle._links.primaryBitstream.href,
); );
}); });
}); });
describe('when the delete request fails', () => { describe('when the delete request fails', () => {
const testResult = createFailedRemoteDataObject(); const testResult = createFailedRemoteDataObject();
const bundleServiceResult = createSuccessfulRemoteDataObject(testBundle);
beforeEach(() => { beforeEach(() => {
spyOn((service as any), 'createAndSendRequest').and.returnValue(observableOf(testResult)); spyOn((service as any), 'createAndSendRequest').and.returnValue(observableOf(testResult));
(bundleDataService.findByHref as jasmine.Spy<any>).and.returnValue(observableOf(bundleServiceResult));
}); });
it('should delegate the call to createAndSendRequest and retrieve the bundle from the rdbService', () => { it('should delegate the call to createAndSendRequest and request the bundle from the bundleDataService', () => {
const result = service.delete(bundle); const result = service.delete(testBundle);
getTestScheduler().expectObservable(result).toBe('(a|)', { a: bundle }); result.subscribe();
expect((service as any).createAndSendRequest).toHaveBeenCalledWith( expect((service as any).createAndSendRequest).toHaveBeenCalledWith(
DeleteRequest, DeleteRequest,
bundle._links.primaryBitstream.href, testBundle._links.primaryBitstream.href,
); );
expect(bundleDataService.findByHref).toHaveBeenCalledWith(testBundle.self, true);
});
it('should delegate the call to createAndSendRequest and', () => {
const result = service.delete(bundle);
getTestScheduler().expectObservable(result).toBe('(a|)', { a: bundleServiceResult });
}); });
}); });
}); });

View File

@@ -122,11 +122,7 @@ export class PrimaryBitstreamService {
).pipe( ).pipe(
getAllCompletedRemoteData(), getAllCompletedRemoteData(),
switchMap((rd: RemoteData<NoContent>) => { switchMap((rd: RemoteData<NoContent>) => {
if (rd.hasSucceeded) { return this.bundleDataService.findByHref(bundle.self, rd.hasFailed);
return this.bundleDataService.findByHref(bundle.self, false);
} else {
return this.rdbService.buildSingle<Bundle>(bundle.self);
}
}) })
); );
} }

View File

@@ -1,4 +1,4 @@
import { autoserialize, deserialize, inheritSerialization } from 'cerialize'; import { deserialize, inheritSerialization } from 'cerialize';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';