mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
fixed lint errors
This commit is contained in:
63
src/app/core/cache/object-cache.service.spec.ts
vendored
63
src/app/core/cache/object-cache.service.spec.ts
vendored
@@ -1,9 +1,9 @@
|
||||
import { Store } from "@ngrx/store";
|
||||
import { Observable } from "rxjs";
|
||||
import { Store } from '@ngrx/store';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
|
||||
import { ObjectCacheService } from "./object-cache.service";
|
||||
import { ObjectCacheState, CacheableObject } from "./object-cache.reducer";
|
||||
import { AddToObjectCacheAction, RemoveFromObjectCacheAction } from "./object-cache.actions";
|
||||
import { ObjectCacheService } from './object-cache.service';
|
||||
import { ObjectCacheState, CacheableObject } from './object-cache.reducer';
|
||||
import { AddToObjectCacheAction, RemoveFromObjectCacheAction } from './object-cache.actions';
|
||||
|
||||
class TestClass implements CacheableObject {
|
||||
constructor(
|
||||
@@ -16,7 +16,7 @@ class TestClass implements CacheableObject {
|
||||
}
|
||||
}
|
||||
|
||||
describe("ObjectCacheService", () => {
|
||||
describe('ObjectCacheService', () => {
|
||||
let service: ObjectCacheService;
|
||||
let store: Store<ObjectCacheState>;
|
||||
|
||||
@@ -40,65 +40,65 @@ describe("ObjectCacheService", () => {
|
||||
spyOn(store, 'dispatch');
|
||||
service = new ObjectCacheService(store);
|
||||
|
||||
spyOn(Date.prototype, 'getTime').and.callFake(function() {
|
||||
spyOn(Date.prototype, 'getTime').and.callFake(() => {
|
||||
return timestamp;
|
||||
});
|
||||
});
|
||||
|
||||
describe("add", () => {
|
||||
it("should dispatch an ADD action with the object to add, the time to live, and the current timestamp", () => {
|
||||
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, requestHref);
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new AddToObjectCacheAction(objectToCache, timestamp, msToLive, requestHref));
|
||||
});
|
||||
});
|
||||
|
||||
describe("remove", () => {
|
||||
it("should dispatch a REMOVE action with the UUID of the object to remove", () => {
|
||||
describe('remove', () => {
|
||||
it('should dispatch a REMOVE action with the UUID of the object to remove', () => {
|
||||
service.remove(uuid);
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new RemoveFromObjectCacheAction(uuid));
|
||||
});
|
||||
});
|
||||
|
||||
describe("get", () => {
|
||||
it("should return an observable of the cached object with the specified UUID and type", () => {
|
||||
describe('get', () => {
|
||||
it('should return an observable of the cached object with the specified UUID and type', () => {
|
||||
spyOn(store, 'select').and.returnValue(Observable.of(cacheEntry));
|
||||
|
||||
let testObj: any;
|
||||
//due to the implementation of spyOn above, this subscribe will be synchronous
|
||||
service.get(uuid, TestClass).take(1).subscribe(o => testObj = o);
|
||||
// due to the implementation of spyOn above, this subscribe will be synchronous
|
||||
service.get(uuid, TestClass).take(1).subscribe((o) => testObj = o);
|
||||
expect(testObj.uuid).toBe(uuid);
|
||||
expect(testObj.foo).toBe("bar");
|
||||
expect(testObj.foo).toBe('bar');
|
||||
// this only works if testObj is an instance of TestClass
|
||||
expect(testObj.test()).toBe("bar" + uuid);
|
||||
expect(testObj.test()).toBe('bar' + uuid);
|
||||
});
|
||||
|
||||
it("should not return a cached object that has exceeded its time to live", () => {
|
||||
it('should not return a cached object that has exceeded its time to live', () => {
|
||||
spyOn(store, 'select').and.returnValue(Observable.of(invalidCacheEntry));
|
||||
|
||||
let getObsHasFired = false;
|
||||
const subscription = service.get(uuid, TestClass).subscribe(o => getObsHasFired = true);
|
||||
const subscription = service.get(uuid, TestClass).subscribe((o) => getObsHasFired = true);
|
||||
expect(getObsHasFired).toBe(false);
|
||||
subscription.unsubscribe();
|
||||
});
|
||||
});
|
||||
|
||||
describe("getList", () => {
|
||||
it("should return an observable of the array of cached objects with the specified UUID and type", () => {
|
||||
spyOn(service, 'get').and.returnValue(Observable.of(new TestClass(uuid, "bar")));
|
||||
describe('getList', () => {
|
||||
it('should return an observable of the array of cached objects with the specified UUID and type', () => {
|
||||
spyOn(service, 'get').and.returnValue(Observable.of(new TestClass(uuid, 'bar')));
|
||||
|
||||
let testObjs: Array<any>;
|
||||
service.getList([uuid, uuid], TestClass).take(1).subscribe(arr => testObjs = arr);
|
||||
let testObjs: any[];
|
||||
service.getList([uuid, uuid], TestClass).take(1).subscribe((arr) => testObjs = arr);
|
||||
expect(testObjs[0].uuid).toBe(uuid);
|
||||
expect(testObjs[0].foo).toBe("bar");
|
||||
expect(testObjs[0].test()).toBe("bar" + uuid);
|
||||
expect(testObjs[0].foo).toBe('bar');
|
||||
expect(testObjs[0].test()).toBe('bar' + uuid);
|
||||
expect(testObjs[1].uuid).toBe(uuid);
|
||||
expect(testObjs[1].foo).toBe("bar");
|
||||
expect(testObjs[1].test()).toBe("bar" + uuid);
|
||||
expect(testObjs[1].foo).toBe('bar');
|
||||
expect(testObjs[1].test()).toBe('bar' + uuid);
|
||||
});
|
||||
});
|
||||
|
||||
describe("has", () => {
|
||||
it("should return true if the object with the supplied UUID is cached and still valid", () => {
|
||||
describe('has', () => {
|
||||
it('should return true if the object with the supplied UUID is cached and still valid', () => {
|
||||
spyOn(store, 'select').and.returnValue(Observable.of(cacheEntry));
|
||||
|
||||
expect(service.has(uuid)).toBe(true);
|
||||
@@ -110,10 +110,11 @@ describe("ObjectCacheService", () => {
|
||||
expect(service.has(uuid)).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false if the object with the supplied UUID is cached but has exceeded its time to live", () => {
|
||||
it('should return false if the object with the supplied UUID is cached but has exceeded its time to live', () => {
|
||||
spyOn(store, 'select').and.returnValue(Observable.of(invalidCacheEntry));
|
||||
|
||||
expect(service.has(uuid)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user