updating tests

This commit is contained in:
Art Lowel
2017-06-20 11:22:26 +02:00
parent 145886e497
commit b69f2ff4cb
3 changed files with 50 additions and 32 deletions

View File

@@ -20,6 +20,7 @@ describe("ObjectCacheService", () => {
let store: Store<ObjectCacheState>; let store: Store<ObjectCacheState>;
const uuid = '1698f1d3-be98-4c51-9fd8-6bfedcbd59b7'; const uuid = '1698f1d3-be98-4c51-9fd8-6bfedcbd59b7';
const requestHref = 'https://rest.api/endpoint/1698f1d3-be98-4c51-9fd8-6bfedcbd59b7';
const timestamp = new Date().getTime(); const timestamp = new Date().getTime();
const msToLive = 900000; const msToLive = 900000;
const objectToCache = { const objectToCache = {
@@ -44,8 +45,8 @@ describe("ObjectCacheService", () => {
describe("add", () => { describe("add", () => {
it("should dispatch an ADD action with the object to add, the time to live, and the current timestamp", () => { it("should dispatch an ADD action with the object to add, the time to live, and the current timestamp", () => {
service.add(objectToCache, msToLive); service.add(objectToCache, msToLive, requestHref);
expect(store.dispatch).toHaveBeenCalledWith(new AddToObjectCacheAction(objectToCache, timestamp, msToLive)); expect(store.dispatch).toHaveBeenCalledWith(new AddToObjectCacheAction(objectToCache, timestamp, msToLive, requestHref));
}); });
}); });

View File

@@ -60,8 +60,8 @@ describe("DSpaceRESTv2Serializer", () => {
it("should turn a model in to a valid document", () => { it("should turn a model in to a valid document", () => {
const serializer = new DSpaceRESTv2Serializer(TestModel); const serializer = new DSpaceRESTv2Serializer(TestModel);
const doc = serializer.serialize(testModels[0]); const doc = serializer.serialize(testModels[0]);
expect(testModels[0].id).toBe(doc._embedded.id); expect(testModels[0].id).toBe(doc.id);
expect(testModels[0].name).toBe(doc._embedded.name); expect(testModels[0].name).toBe(doc.name);
}); });
}); });
@@ -72,10 +72,10 @@ describe("DSpaceRESTv2Serializer", () => {
const serializer = new DSpaceRESTv2Serializer(TestModel); const serializer = new DSpaceRESTv2Serializer(TestModel);
const doc = serializer.serializeArray(testModels); const doc = serializer.serializeArray(testModels);
expect(testModels[0].id).toBe(doc._embedded[0].id); expect(testModels[0].id).toBe(doc[0].id);
expect(testModels[0].name).toBe(doc._embedded[0].name); expect(testModels[0].name).toBe(doc[0].name);
expect(testModels[1].id).toBe(doc._embedded[1].id); expect(testModels[1].id).toBe(doc[1].id);
expect(testModels[1].name).toBe(doc._embedded[1].name); expect(testModels[1].name).toBe(doc[1].name);
}); });
}); });

View File

@@ -1,9 +1,9 @@
import { TestBed, async } from '@angular/core/testing';
import { Item } from "./item.model"; import { Item } from "./item.model";
import { Bundle } from "./bundle.model";
import { Observable } from "rxjs"; import { Observable } from "rxjs";
import { RemoteData } from "../data/remote-data"; import { RemoteData } from "../data/remote-data";
import { Bitstream } from "./bitstream.model"; import { Bitstream } from "./bitstream.model";
import { isEmpty } from "../../shared/empty.util";
import { PageInfo } from "./page-info.model";
describe('Item', () => { describe('Item', () => {
@@ -17,23 +17,25 @@ describe('Item', () => {
const bitstream2Path = "otherfile.doc"; const bitstream2Path = "otherfile.doc";
const nonExistingBundleName = "c1e568f7-d14e-496b-bdd7-07026998cc00"; const nonExistingBundleName = "c1e568f7-d14e-496b-bdd7-07026998cc00";
let remoteBundles; let bitstreams;
let thumbnailBundle; let remoteDataThumbnail;
let originalBundle; let remoteDataFiles;
let remoteDataAll;
beforeEach(() => { beforeEach(() => {
const thumbnail = { const thumbnail = {
retrieve: thumbnailPath retrieve: thumbnailPath
}; };
const bitstreams = [{ bitstreams = [{
retrieve: bitstream1Path retrieve: bitstream1Path
}, { }, {
retrieve: bitstream2Path retrieve: bitstream2Path
}]; }];
const remoteDataThumbnail = createRemoteDataObject(thumbnail); remoteDataThumbnail = createRemoteDataObject(thumbnail);
const remoteDataFiles = createRemoteDataObject(bitstreams); remoteDataFiles = createRemoteDataObject(bitstreams);
remoteDataAll = createRemoteDataObject([...bitstreams, thumbnail]);
// Create Bundles // Create Bundles
@@ -50,32 +52,30 @@ describe('Item', () => {
bitstreams: remoteDataFiles 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', () => { it('should return the bitstreams related to this item with the specified bundle name', () => {
let name: string = thumbnailBundleName; const bitObs: Observable<Bitstream[]> = item.getBitstreamsByBundleName(thumbnailBundleName);
let bundle: Observable<Bundle> = item.getBundle(name); bitObs.take(1).subscribe(bs =>
bundle.map(b => expect(b.name).toBe(name)); expect(bs.every(b => b.name === thumbnailBundleName)).toBeTruthy());
}); });
it('should return null when no bundle with this name exists for this item', () => { it('should return an empty array when no bitstreams with this bundleName exist for this item', () => {
let name: string = nonExistingBundleName; const bitstreams: Observable<Bitstream[]> = item.getBitstreamsByBundleName(nonExistingBundleName);
let bundle: Observable<Bundle> = item.getBundle(name); bitstreams.take(1).subscribe(bs => expect(isEmpty(bs)).toBeTruthy());
bundle.map(b => expect(b).toBeUndefined());
}); });
describe("get thumbnail", () => { describe("get thumbnail", () => {
beforeEach(() => { 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 path: string = thumbnailPath;
let bitstream: Observable<Bitstream> = item.getThumbnail(); let bitstream: Observable<Bitstream> = item.getThumbnail();
bitstream.map(b => expect(b.retrieve).toBe(path)); bitstream.map(b => expect(b.retrieve).toBe(path));
@@ -85,10 +85,10 @@ describe('Item', () => {
describe("get files", () => { describe("get files", () => {
beforeEach(() => { 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 paths = [bitstream1Path, bitstream2Path];
let files: Observable<Bitstream[]> = item.getFiles(); let files: Observable<Bitstream[]> = item.getFiles();
@@ -110,6 +110,23 @@ describe('Item', () => {
}); });
function createRemoteDataObject(object: Object) { 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
);
} }