diff --git a/src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts b/src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts index cdc905d456..b77d2151a9 100644 --- a/src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts +++ b/src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts @@ -612,7 +612,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy { bundle$ = completedBundleRd$.pipe( map((bundleRd: RemoteData) => { if (bundleRd.hasSucceeded) { - return bundleRd.payload + return bundleRd.payload; } else { return this.bundle; } diff --git a/src/app/core/data/primary-bitstream.service.spec.ts b/src/app/core/data/primary-bitstream.service.spec.ts index 93e9882d04..00d6d7f03c 100644 --- a/src/app/core/data/primary-bitstream.service.spec.ts +++ b/src/app/core/data/primary-bitstream.service.spec.ts @@ -16,7 +16,7 @@ import { Bundle } from '../shared/bundle.model'; import { getTestScheduler } from 'jasmine-marbles'; import { of as observableOf } from 'rxjs'; -fdescribe('PrimaryBitstreamService', () => { +describe('PrimaryBitstreamService', () => { let service: PrimaryBitstreamService; let objectCache: ObjectCacheService; let requestService: RequestService; @@ -57,7 +57,7 @@ fdescribe('PrimaryBitstreamService', () => { describe('getHttpOptions', () => { 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'); }); }); @@ -118,9 +118,20 @@ fdescribe('PrimaryBitstreamService', () => { }); }); describe('delete', () => { + const testBundle = Object.assign(new Bundle(), { + _links: { + self: { + href: 'test-href' + }, + primaryBitstream: { + href: 'test-primaryBitstream-href' + } + } + }); + describe('when the delete request succeeds', () => { const testResult = createSuccessfulRemoteDataObject(new Bundle()); - const bundleServiceResult = createSuccessfulRemoteDataObject(bundle); + const bundleServiceResult = createSuccessfulRemoteDataObject(testBundle); beforeEach(() => { spyOn((service as any), 'createAndSendRequest').and.returnValue(observableOf(testResult)); @@ -128,30 +139,42 @@ fdescribe('PrimaryBitstreamService', () => { }); it('should delegate the call to createAndSendRequest', () => { - const result = service.delete(bundle); - getTestScheduler().expectObservable(result).toBe('(a|)', { a: testResult }); + const result = service.delete(testBundle); + getTestScheduler().expectObservable(result).toBe('(a|)', { a: bundleServiceResult }); + + result.subscribe(); + + expect(bundleDataService.findByHref).toHaveBeenCalledWith(testBundle.self, false); expect((service as any).createAndSendRequest).toHaveBeenCalledWith( DeleteRequest, - bundle._links.primaryBitstream.href, + testBundle._links.primaryBitstream.href, ); }); }); describe('when the delete request fails', () => { const testResult = createFailedRemoteDataObject(); + const bundleServiceResult = createSuccessfulRemoteDataObject(testBundle); beforeEach(() => { spyOn((service as any), 'createAndSendRequest').and.returnValue(observableOf(testResult)); + (bundleDataService.findByHref as jasmine.Spy).and.returnValue(observableOf(bundleServiceResult)); }); - it('should delegate the call to createAndSendRequest and retrieve the bundle from the rdbService', () => { - const result = service.delete(bundle); - getTestScheduler().expectObservable(result).toBe('(a|)', { a: bundle }); - + it('should delegate the call to createAndSendRequest and request the bundle from the bundleDataService', () => { + const result = service.delete(testBundle); + result.subscribe(); expect((service as any).createAndSendRequest).toHaveBeenCalledWith( 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 }); }); }); }); diff --git a/src/app/core/data/primary-bitstream.service.ts b/src/app/core/data/primary-bitstream.service.ts index 5c1c3c52ac..646e8271e8 100644 --- a/src/app/core/data/primary-bitstream.service.ts +++ b/src/app/core/data/primary-bitstream.service.ts @@ -122,11 +122,7 @@ export class PrimaryBitstreamService { ).pipe( getAllCompletedRemoteData(), switchMap((rd: RemoteData) => { - if (rd.hasSucceeded) { - return this.bundleDataService.findByHref(bundle.self, false); - } else { - return this.rdbService.buildSingle(bundle.self); - } + return this.bundleDataService.findByHref(bundle.self, rd.hasFailed); }) ); } diff --git a/src/app/core/shared/bundle.model.ts b/src/app/core/shared/bundle.model.ts index f37cd96545..36b7012e47 100644 --- a/src/app/core/shared/bundle.model.ts +++ b/src/app/core/shared/bundle.model.ts @@ -1,4 +1,4 @@ -import { autoserialize, deserialize, inheritSerialization } from 'cerialize'; +import { deserialize, inheritSerialization } from 'cerialize'; import { Observable } from 'rxjs';