mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Added unit test for isCachedOrPending lookup by id (FindByIdRequest).
This commit is contained in:
@@ -11,6 +11,7 @@ import { UUIDService } from '../shared/uuid.service';
|
|||||||
import { RequestConfigureAction, RequestExecuteAction } from './request.actions';
|
import { RequestConfigureAction, RequestExecuteAction } from './request.actions';
|
||||||
import {
|
import {
|
||||||
DeleteRequest,
|
DeleteRequest,
|
||||||
|
FindByIDRequest,
|
||||||
GetRequest,
|
GetRequest,
|
||||||
HeadRequest,
|
HeadRequest,
|
||||||
OptionsRequest,
|
OptionsRequest,
|
||||||
@@ -21,6 +22,7 @@ import {
|
|||||||
} from './request.models';
|
} from './request.models';
|
||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
import { TestScheduler } from 'rxjs/testing';
|
import { TestScheduler } from 'rxjs/testing';
|
||||||
|
import { IdentifierType } from '../index/index.reducer';
|
||||||
|
|
||||||
describe('RequestService', () => {
|
describe('RequestService', () => {
|
||||||
let scheduler: TestScheduler;
|
let scheduler: TestScheduler;
|
||||||
@@ -38,6 +40,7 @@ describe('RequestService', () => {
|
|||||||
const testDeleteRequest = new DeleteRequest(testUUID, testHref);
|
const testDeleteRequest = new DeleteRequest(testUUID, testHref);
|
||||||
const testOptionsRequest = new OptionsRequest(testUUID, testHref);
|
const testOptionsRequest = new OptionsRequest(testUUID, testHref);
|
||||||
const testHeadRequest = new HeadRequest(testUUID, testHref);
|
const testHeadRequest = new HeadRequest(testUUID, testHref);
|
||||||
|
const testFindByIdRequest = new FindByIDRequest(testUUID, testHref, testUUID, IdentifierType.UUID);
|
||||||
const testPatchRequest = new PatchRequest(testUUID, testHref);
|
const testPatchRequest = new PatchRequest(testUUID, testHref);
|
||||||
let selectSpy;
|
let selectSpy;
|
||||||
|
|
||||||
@@ -298,13 +301,22 @@ describe('RequestService', () => {
|
|||||||
describe('in the ObjectCache', () => {
|
describe('in the ObjectCache', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
(objectCache.hasBySelfLink as any).and.returnValue(true);
|
(objectCache.hasBySelfLink as any).and.returnValue(true);
|
||||||
|
(objectCache.hasById as any).and.returnValue(true);
|
||||||
spyOn(serviceAsAny, 'hasByHref').and.returnValue(false);
|
spyOn(serviceAsAny, 'hasByHref').and.returnValue(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true', () => {
|
it('should return true for GetRequest', () => {
|
||||||
const result = serviceAsAny.isCachedOrPending(testGetRequest);
|
const result = serviceAsAny.isCachedOrPending(testGetRequest);
|
||||||
const expected = true;
|
const expected = true;
|
||||||
|
|
||||||
|
expect(result).toEqual(expected);
|
||||||
|
});
|
||||||
|
it('should return true for instance of FindByIdRequest', () => {
|
||||||
|
(objectCache.hasBySelfLink as any).and.returnValue(false);
|
||||||
|
const result = serviceAsAny.isCachedOrPending(testFindByIdRequest);
|
||||||
|
expect(objectCache.hasById).toHaveBeenCalledWith(testUUID, IdentifierType.UUID);
|
||||||
|
const expected = true;
|
||||||
|
|
||||||
expect(result).toEqual(expected);
|
expect(result).toEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -4,12 +4,12 @@ export function getMockObjectCacheService(): ObjectCacheService {
|
|||||||
return jasmine.createSpyObj('objectCacheService', [
|
return jasmine.createSpyObj('objectCacheService', [
|
||||||
'add',
|
'add',
|
||||||
'remove',
|
'remove',
|
||||||
'getByUUID',
|
'getByID',
|
||||||
'getBySelfLink',
|
'getBySelfLink',
|
||||||
'getRequestHrefBySelfLink',
|
'getRequestHrefBySelfLink',
|
||||||
'getRequestHrefByUUID',
|
'getRequestHrefByUUID',
|
||||||
'getList',
|
'getList',
|
||||||
'hasByUUID',
|
'hasById',
|
||||||
'hasBySelfLink'
|
'hasBySelfLink'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user