diff --git a/src/app/core/cache/object-cache.service.spec.ts b/src/app/core/cache/object-cache.service.spec.ts index 827e39ab7e..dd77cab110 100644 --- a/src/app/core/cache/object-cache.service.spec.ts +++ b/src/app/core/cache/object-cache.service.spec.ts @@ -20,6 +20,7 @@ describe("ObjectCacheService", () => { let store: Store; const uuid = '1698f1d3-be98-4c51-9fd8-6bfedcbd59b7'; + const requestHref = 'https://rest.api/endpoint/1698f1d3-be98-4c51-9fd8-6bfedcbd59b7'; const timestamp = new Date().getTime(); const msToLive = 900000; const objectToCache = { @@ -44,8 +45,8 @@ describe("ObjectCacheService", () => { describe("add", () => { it("should dispatch an ADD action with the object to add, the time to live, and the current timestamp", () => { - service.add(objectToCache, msToLive); - expect(store.dispatch).toHaveBeenCalledWith(new AddToObjectCacheAction(objectToCache, timestamp, msToLive)); + service.add(objectToCache, msToLive, requestHref); + expect(store.dispatch).toHaveBeenCalledWith(new AddToObjectCacheAction(objectToCache, timestamp, msToLive, requestHref)); }); }); diff --git a/src/app/core/dspace-rest-v2/dspace-rest-v2.serializer.spec.ts b/src/app/core/dspace-rest-v2/dspace-rest-v2.serializer.spec.ts index 67914c2a92..097717b5e2 100644 --- a/src/app/core/dspace-rest-v2/dspace-rest-v2.serializer.spec.ts +++ b/src/app/core/dspace-rest-v2/dspace-rest-v2.serializer.spec.ts @@ -60,8 +60,8 @@ describe("DSpaceRESTv2Serializer", () => { it("should turn a model in to a valid document", () => { const serializer = new DSpaceRESTv2Serializer(TestModel); const doc = serializer.serialize(testModels[0]); - expect(testModels[0].id).toBe(doc._embedded.id); - expect(testModels[0].name).toBe(doc._embedded.name); + expect(testModels[0].id).toBe(doc.id); + expect(testModels[0].name).toBe(doc.name); }); }); @@ -72,10 +72,10 @@ describe("DSpaceRESTv2Serializer", () => { const serializer = new DSpaceRESTv2Serializer(TestModel); const doc = serializer.serializeArray(testModels); - expect(testModels[0].id).toBe(doc._embedded[0].id); - expect(testModels[0].name).toBe(doc._embedded[0].name); - expect(testModels[1].id).toBe(doc._embedded[1].id); - expect(testModels[1].name).toBe(doc._embedded[1].name); + expect(testModels[0].id).toBe(doc[0].id); + expect(testModels[0].name).toBe(doc[0].name); + expect(testModels[1].id).toBe(doc[1].id); + expect(testModels[1].name).toBe(doc[1].name); }); }); diff --git a/src/app/core/shared/item.model.spec.ts b/src/app/core/shared/item.model.spec.ts index e20bd6e592..d10b7d3046 100644 --- a/src/app/core/shared/item.model.spec.ts +++ b/src/app/core/shared/item.model.spec.ts @@ -1,9 +1,9 @@ -import { TestBed, async } from '@angular/core/testing'; import { Item } from "./item.model"; -import { Bundle } from "./bundle.model"; import { Observable } from "rxjs"; import { RemoteData } from "../data/remote-data"; import { Bitstream } from "./bitstream.model"; +import { isEmpty } from "../../shared/empty.util"; +import { PageInfo } from "./page-info.model"; describe('Item', () => { @@ -17,23 +17,25 @@ describe('Item', () => { const bitstream2Path = "otherfile.doc"; const nonExistingBundleName = "c1e568f7-d14e-496b-bdd7-07026998cc00"; - let remoteBundles; - let thumbnailBundle; - let originalBundle; + let bitstreams; + let remoteDataThumbnail; + let remoteDataFiles; + let remoteDataAll; beforeEach(() => { const thumbnail = { retrieve: thumbnailPath }; - const bitstreams = [{ + bitstreams = [{ retrieve: bitstream1Path }, { retrieve: bitstream2Path }]; - const remoteDataThumbnail = createRemoteDataObject(thumbnail); - const remoteDataFiles = createRemoteDataObject(bitstreams); + remoteDataThumbnail = createRemoteDataObject(thumbnail); + remoteDataFiles = createRemoteDataObject(bitstreams); + remoteDataAll = createRemoteDataObject([...bitstreams, thumbnail]); // Create Bundles @@ -50,32 +52,30 @@ describe('Item', () => { bitstreams: remoteDataFiles }]; - remoteBundles = createRemoteDataObject(bundles); - item = Object.assign(new Item(), { bundles: remoteBundles }); + item = Object.assign(new Item(), { bitstreams: remoteDataAll}); }); - it('should return the bundle with the given name of this item when the bundle exists', () => { - let name: string = thumbnailBundleName; - let bundle: Observable = item.getBundle(name); - bundle.map(b => expect(b.name).toBe(name)); + it('should return the bitstreams related to this item with the specified bundle name', () => { + const bitObs: Observable = item.getBitstreamsByBundleName(thumbnailBundleName); + bitObs.take(1).subscribe(bs => + expect(bs.every(b => b.name === thumbnailBundleName)).toBeTruthy()); }); - it('should return null when no bundle with this name exists for this item', () => { - let name: string = nonExistingBundleName; - let bundle: Observable = item.getBundle(name); - bundle.map(b => expect(b).toBeUndefined()); + it('should return an empty array when no bitstreams with this bundleName exist for this item', () => { + const bitstreams: Observable = item.getBitstreamsByBundleName(nonExistingBundleName); + bitstreams.take(1).subscribe(bs => expect(isEmpty(bs)).toBeTruthy()); }); describe("get thumbnail", () => { beforeEach(() => { - spyOn(item, 'getBundle').and.returnValue(Observable.of(thumbnailBundle)); + spyOn(item, 'getBitstreamsByBundleName').and.returnValue(Observable.of([remoteDataThumbnail])); }); - it('should return the thumbnail (the primaryBitstream in the bundle "THUMBNAIL") of this item', () => { + it('should return the thumbnail of this item', () => { let path: string = thumbnailPath; let bitstream: Observable = item.getThumbnail(); bitstream.map(b => expect(b.retrieve).toBe(path)); @@ -85,10 +85,10 @@ describe('Item', () => { describe("get files", () => { beforeEach(() => { - spyOn(item, 'getBundle').and.returnValue(Observable.of(originalBundle)); + spyOn(item, 'getBitstreamsByBundleName').and.returnValue(Observable.of(bitstreams)); }); - it('should return all files in the ORIGINAL bundle', () => { + it('should return all bitstreams with "ORIGINAL" as bundleName', () => { let paths = [bitstream1Path, bitstream2Path]; let files: Observable = item.getFiles(); @@ -110,6 +110,23 @@ describe('Item', () => { }); function createRemoteDataObject(object: Object) { - return new RemoteData("", Observable.of(false), Observable.of(false), Observable.of(true), Observable.of(undefined), Observable.of(object)); + const self = ""; + const requestPending = Observable.of(false); + const responsePending = Observable.of(false); + const isSuccessful = Observable.of(true); + const errorMessage = Observable.of(undefined); + const statusCode = Observable.of("200"); + const pageInfo = Observable.of(new PageInfo()); + const payload = Observable.of(object); + return new RemoteData( + self, + requestPending, + responsePending, + isSuccessful, + errorMessage, + statusCode, + pageInfo, + payload + ); -} \ No newline at end of file +}