refactored tests

This commit is contained in:
Art Lowel
2018-01-19 12:47:29 +01:00
parent b771503cf7
commit 1d48172ecd
10 changed files with 147 additions and 128 deletions

View File

@@ -1,4 +1,5 @@
import { initMockRequestService } from '../../shared/mocks/mock-request.service'; import { getMockRequestService } from '../../shared/mocks/mock-request.service';
import { getMockResponseCacheService } from '../../shared/mocks/mock-response-cache.service';
import { BrowseService } from './browse.service'; import { BrowseService } from './browse.service';
import { ResponseCacheService } from '../cache/response-cache.service'; import { ResponseCacheService } from '../cache/response-cache.service';
import { RequestService } from '../data/request.service'; import { RequestService } from '../data/request.service';
@@ -74,16 +75,16 @@ describe('BrowseService', () => {
]; ];
function initMockResponseCacheService(isSuccessful: boolean) { function initMockResponseCacheService(isSuccessful: boolean) {
return jasmine.createSpyObj('responseCache', { const rcs = getMockResponseCacheService();
get: cold('b-', { (rcs.get as any).and.returnValue(cold('b-', {
b: { b: {
response: { response: {
isSuccessful, isSuccessful,
browseDefinitions, browseDefinitions,
}
} }
}) }
}); }));
return rcs;
} }
function initTestService() { function initTestService() {
@@ -103,7 +104,7 @@ describe('BrowseService', () => {
describe('if getEndpoint fires', () => { describe('if getEndpoint fires', () => {
beforeEach(() => { beforeEach(() => {
responseCache = initMockResponseCacheService(true); responseCache = initMockResponseCacheService(true);
requestService = initMockRequestService(); requestService = getMockRequestService();
service = initTestService(); service = initTestService();
spyOn(service, 'getEndpoint').and spyOn(service, 'getEndpoint').and
.returnValue(hot('--a-', { a: browsesEndpointURL })); .returnValue(hot('--a-', { a: browsesEndpointURL }));
@@ -168,7 +169,7 @@ describe('BrowseService', () => {
describe('if getEndpoint doesn\'t fire', () => { describe('if getEndpoint doesn\'t fire', () => {
it('should return undefined', () => { it('should return undefined', () => {
responseCache = initMockResponseCacheService(true); responseCache = initMockResponseCacheService(true);
requestService = initMockRequestService(); requestService = getMockRequestService();
service = initTestService(); service = initTestService();
spyOn(service, 'getEndpoint').and spyOn(service, 'getEndpoint').and
.returnValue(hot('----')); .returnValue(hot('----'));
@@ -185,7 +186,7 @@ describe('BrowseService', () => {
describe('if the browses endpoint can\'t be retrieved', () => { describe('if the browses endpoint can\'t be retrieved', () => {
it('should throw an error', () => { it('should throw an error', () => {
responseCache = initMockResponseCacheService(false); responseCache = initMockResponseCacheService(false);
requestService = initMockRequestService(); requestService = getMockRequestService();
service = initTestService(); service = initTestService();
spyOn(service, 'getEndpoint').and spyOn(service, 'getEndpoint').and
.returnValue(hot('--a-', { a: browsesEndpointURL })); .returnValue(hot('--a-', { a: browsesEndpointURL }));

View File

@@ -1,7 +1,7 @@
import { cold, getTestScheduler, hot } from 'jasmine-marbles'; import { cold, getTestScheduler, hot } from 'jasmine-marbles';
import { TestScheduler } from 'rxjs/Rx'; import { TestScheduler } from 'rxjs/Rx';
import { GlobalConfig } from '../../../config'; import { GlobalConfig } from '../../../config';
import { initMockRequestService } from '../../shared/mocks/mock-request.service'; import { getMockRequestService } from '../../shared/mocks/mock-request.service';
import { ResponseCacheService } from '../cache/response-cache.service'; import { ResponseCacheService } from '../cache/response-cache.service';
import { ConfigService } from './config.service'; import { ConfigService } from './config.service';
import { RequestService } from '../data/request.service'; import { RequestService } from '../data/request.service';
@@ -57,7 +57,7 @@ describe('ConfigService', () => {
beforeEach(() => { beforeEach(() => {
responseCache = initMockResponseCacheService(true); responseCache = initMockResponseCacheService(true);
requestService = initMockRequestService(); requestService = getMockRequestService();
service = initTestService(); service = initTestService();
scheduler = getTestScheduler(); scheduler = getTestScheduler();
spyOn(service, 'getEndpoint').and spyOn(service, 'getEndpoint').and

View File

@@ -2,7 +2,7 @@ import { Store } from '@ngrx/store';
import { cold, getTestScheduler, hot } from 'jasmine-marbles'; import { cold, getTestScheduler, hot } from 'jasmine-marbles';
import { TestScheduler } from 'rxjs/Rx'; import { TestScheduler } from 'rxjs/Rx';
import { GlobalConfig } from '../../../config'; import { GlobalConfig } from '../../../config';
import { initMockRequestService } from '../../shared/mocks/mock-request.service'; import { getMockRequestService } from '../../shared/mocks/mock-request.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { NormalizedCommunity } from '../cache/models/normalized-community.model'; import { NormalizedCommunity } from '../cache/models/normalized-community.model';
import { CacheableObject } from '../cache/object-cache.reducer'; import { CacheableObject } from '../cache/object-cache.reducer';
@@ -102,7 +102,7 @@ describe('ComColDataService', () => {
it('should configure a new FindByIDRequest for the scope Community', () => { it('should configure a new FindByIDRequest for the scope Community', () => {
cds = initMockCommunityDataService(); cds = initMockCommunityDataService();
requestService = initMockRequestService(); requestService = getMockRequestService();
objectCache = initMockObjectCacheService(); objectCache = initMockObjectCacheService();
responseCache = initMockResponseCacheService(true); responseCache = initMockResponseCacheService(true);
service = initTestService(); service = initTestService();
@@ -118,7 +118,7 @@ describe('ComColDataService', () => {
describe('if the scope Community can be found', () => { describe('if the scope Community can be found', () => {
beforeEach(() => { beforeEach(() => {
cds = initMockCommunityDataService(); cds = initMockCommunityDataService();
requestService = initMockRequestService(); requestService = getMockRequestService();
objectCache = initMockObjectCacheService(); objectCache = initMockObjectCacheService();
responseCache = initMockResponseCacheService(true); responseCache = initMockResponseCacheService(true);
service = initTestService(); service = initTestService();
@@ -141,7 +141,7 @@ describe('ComColDataService', () => {
describe('if the scope Community can\'t be found', () => { describe('if the scope Community can\'t be found', () => {
beforeEach(() => { beforeEach(() => {
cds = initMockCommunityDataService(); cds = initMockCommunityDataService();
requestService = initMockRequestService(); requestService = getMockRequestService();
objectCache = initMockObjectCacheService(); objectCache = initMockObjectCacheService();
responseCache = initMockResponseCacheService(false); responseCache = initMockResponseCacheService(false);
service = initTestService(); service = initTestService();
@@ -158,7 +158,7 @@ describe('ComColDataService', () => {
describe('if the scope is not specified', () => { describe('if the scope is not specified', () => {
beforeEach(() => { beforeEach(() => {
cds = initMockCommunityDataService(); cds = initMockCommunityDataService();
requestService = initMockRequestService(); requestService = getMockRequestService();
objectCache = initMockObjectCacheService(); objectCache = initMockObjectCacheService();
responseCache = initMockResponseCacheService(true); responseCache = initMockResponseCacheService(true);
service = initTestService(); service = initTestService();

View File

@@ -1,9 +1,10 @@
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { cold, hot } from 'jasmine-marbles'; import { cold, hot } from 'jasmine-marbles';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { initMockObjectCacheService } from '../../shared/mocks/mock-object-cache.service'; import { getMockObjectCacheService } from '../../shared/mocks/mock-object-cache.service';
import { initMockStore } from '../../shared/mocks/mock-store'; import { getMockResponseCacheService } from '../../shared/mocks/mock-response-cache.service';
import { defaultUUID, initMockUUIDService } from '../../shared/mocks/mock-uuid.service'; import { getMockStore } from '../../shared/mocks/mock-store';
import { defaultUUID, getMockUUIDService } from '../../shared/mocks/mock-uuid.service';
import { ObjectCacheService } from '../cache/object-cache.service'; import { ObjectCacheService } from '../cache/object-cache.service';
import { ResponseCacheService } from '../cache/response-cache.service'; import { ResponseCacheService } from '../cache/response-cache.service';
import { CoreState } from '../core.reducers'; import { CoreState } from '../core.reducers';
@@ -16,7 +17,7 @@ import {
OptionsRequest, OptionsRequest,
PatchRequest, PatchRequest,
PostRequest, PostRequest,
PutRequest PutRequest, RestRequest
} from './request.models'; } from './request.models';
import { RequestService } from './request.service'; import { RequestService } from './request.service';
@@ -38,45 +39,29 @@ describe('RequestService', () => {
const testHeadRequest = new HeadRequest(testUUID, testHref); const testHeadRequest = new HeadRequest(testUUID, testHref);
const testPatchRequest = new PatchRequest(testUUID, testHref); const testPatchRequest = new PatchRequest(testUUID, testHref);
const defaultSelectResult = Observable.of(undefined); beforeEach(() => {
const defaultHasResponse = false; objectCache = getMockObjectCacheService();
const defaultGetResponse = Observable.of(undefined); (objectCache.hasBySelfLink as any).and.returnValue(false);
const defaultHasObjectCache = false;
function initMockResponseCacheService(hasResponse, getResponse) { responseCache = getMockResponseCacheService();
return jasmine.createSpyObj('responseCache', { (responseCache.has as any).and.returnValue(false);
has: hasResponse, (responseCache.get as any).and.returnValue(Observable.of(undefined));
get: getResponse
});
}
function initTestService() { uuidService = getMockUUIDService();
return new RequestService(
store = getMockStore<CoreState>();
(store.select as any).and.returnValue(Observable.of(undefined));
service = new RequestService(
objectCache, objectCache,
responseCache, responseCache,
uuidService, uuidService,
store store
); );
}
function initServices(selectResult = defaultSelectResult, hasResponse = defaultHasResponse, getResponse = defaultGetResponse, hasObjectCache: boolean | boolean[] = defaultHasObjectCache) {
if (!Array.isArray(hasObjectCache)) {
hasObjectCache = [hasObjectCache];
}
objectCache = initMockObjectCacheService();
(objectCache.hasBySelfLink as any).and.returnValues(...hasObjectCache);
responseCache = initMockResponseCacheService(hasResponse, getResponse);
uuidService = initMockUUIDService();
store = initMockStore<CoreState>(selectResult);
service = initTestService();
serviceAsAny = service as any; serviceAsAny = service as any;
} });
describe('generateRequestId', () => { describe('generateRequestId', () => {
beforeEach(() => {
initServices();
});
it('should generate a new request ID', () => { it('should generate a new request ID', () => {
const result = service.generateRequestId(); const result = service.generateRequestId();
const expected = `client/${defaultUUID}`; const expected = `client/${defaultUUID}`;
@@ -88,7 +73,7 @@ describe('RequestService', () => {
describe('isPending', () => { describe('isPending', () => {
describe('before the request is configured', () => { describe('before the request is configured', () => {
beforeEach(() => { beforeEach(() => {
initServices(); spyOn(service, 'getByHref').and.returnValue(Observable.of(undefined));
}); });
it('should return false', () => { it('should return false', () => {
@@ -101,11 +86,11 @@ describe('RequestService', () => {
describe('when the request has been configured but hasn\'t reached the store yet', () => { describe('when the request has been configured but hasn\'t reached the store yet', () => {
beforeEach(() => { beforeEach(() => {
initServices(); spyOn(service, 'getByHref').and.returnValue(Observable.of(undefined));
serviceAsAny.requestsOnTheirWayToTheStore = [testHref];
}); });
it('should return true', () => { it('should return true', () => {
serviceAsAny.requestsOnTheirWayToTheStore = [testHref];
const result = service.isPending(testGetRequest); const result = service.isPending(testGetRequest);
const expected = true; const expected = true;
@@ -115,9 +100,9 @@ describe('RequestService', () => {
describe('when the request has reached the store, before the server responds', () => { describe('when the request has reached the store, before the server responds', () => {
beforeEach(() => { beforeEach(() => {
initServices(Observable.of({ spyOn(service, 'getByHref').and.returnValue(Observable.of({
completed: false completed: false
})); }))
}); });
it('should return true', () => { it('should return true', () => {
@@ -130,7 +115,7 @@ describe('RequestService', () => {
describe('after the server responds', () => { describe('after the server responds', () => {
beforeEach(() => { beforeEach(() => {
initServices(Observable.of({ spyOn(service, 'getByHref').and.returnValues(Observable.of({
completed: true completed: true
})); }));
}); });
@@ -147,13 +132,15 @@ describe('RequestService', () => {
describe('getByUUID', () => { describe('getByUUID', () => {
describe('if the request with the specified UUID exists in the store', () => { describe('if the request with the specified UUID exists in the store', () => {
it('should return an Observable of the RequestEntry', () => { beforeEach(() => {
initServices(hot('a', { (store.select as any).and.returnValues(hot('a', {
a: { a: {
completed: true completed: true
} }
})); }));
});
it('should return an Observable of the RequestEntry', () => {
const result = service.getByUUID(testUUID); const result = service.getByUUID(testUUID);
const expected = cold('b', { const expected = cold('b', {
b: { b: {
@@ -166,11 +153,13 @@ describe('RequestService', () => {
}); });
describe('if the request with the specified UUID doesn\'t exist in the store', () => { describe('if the request with the specified UUID doesn\'t exist in the store', () => {
it('should return an Observable of undefined', () => { beforeEach(() => {
initServices(hot('a', { (store.select as any).and.returnValues(hot('a', {
a: undefined a: undefined
})); }));
});
it('should return an Observable of undefined', () => {
const result = service.getByUUID(testUUID); const result = service.getByUUID(testUUID);
const expected = cold('b', { const expected = cold('b', {
b: undefined b: undefined
@@ -183,9 +172,9 @@ describe('RequestService', () => {
}); });
describe('getByHref', () => { describe('getByHref', () => {
describe('if the request with the specified href exists in the store', () => { describe('when the request with the specified href exists in the store', () => {
it('should return an Observable of the RequestEntry', () => { beforeEach(() => {
initServices(hot('a', { (store.select as any).and.returnValues(hot('a', {
a: testUUID a: testUUID
})); }));
spyOn(service, 'getByUUID').and.returnValue(cold('b', { spyOn(service, 'getByUUID').and.returnValue(cold('b', {
@@ -193,7 +182,9 @@ describe('RequestService', () => {
completed: true completed: true
} }
})); }));
});
it('should return an Observable of the RequestEntry', () => {
const result = service.getByHref(testHref); const result = service.getByHref(testHref);
const expected = cold('c', { const expected = cold('c', {
c: { c: {
@@ -205,15 +196,17 @@ describe('RequestService', () => {
}); });
}); });
describe('if the request with the specified href doesn\'t exist in the store', () => { describe('when the request with the specified href doesn\'t exist in the store', () => {
it('should return an Observable of undefined', () => { beforeEach(() => {
initServices(hot('a', { (store.select as any).and.returnValues(hot('a', {
a: undefined a: undefined
})); }));
spyOn(service, 'getByUUID').and.returnValue(cold('b', { spyOn(service, 'getByUUID').and.returnValue(cold('b', {
b: undefined b: undefined
})); }));
});
it('should return an Observable of undefined', () => {
const result = service.getByHref(testHref); const result = service.getByHref(testHref);
const expected = cold('c', { const expected = cold('c', {
c: undefined c: undefined
@@ -225,34 +218,41 @@ describe('RequestService', () => {
}); });
describe('configure', () => { describe('configure', () => {
describe('if the request is a GET request', () => { beforeEach(() => {
describe('and it isn\'t already cached', () => { spyOn(serviceAsAny, 'dispatchRequest');
it('should dispatch the request', () => { });
initServices();
spyOn(serviceAsAny, 'dispatchRequest');
spyOn(serviceAsAny, 'isCachedOrPending').and.returnValue(false);
service.configure(testGetRequest); describe('when the request is a GET request', () => {
expect(serviceAsAny.dispatchRequest).toHaveBeenCalledWith(testGetRequest); let request: RestRequest;
beforeEach(() => {
request = testGetRequest;
});
describe('and it isn\'t cached or pending', () => {
beforeEach(() => {
spyOn(serviceAsAny, 'isCachedOrPending').and.returnValue(false);
});
it('should dispatch the request', () => {
service.configure(request);
expect(serviceAsAny.dispatchRequest).toHaveBeenCalledWith(request);
}); });
}); });
describe('and it is already cached or pending', () => { describe('and it is already cached or pending', () => {
it('shouldn\'t dispatch the request', () => { beforeEach(() => {
initServices();
spyOn(serviceAsAny, 'dispatchRequest');
spyOn(serviceAsAny, 'isCachedOrPending').and.returnValue(true); spyOn(serviceAsAny, 'isCachedOrPending').and.returnValue(true);
});
service.configure(testGetRequest); it('shouldn\'t dispatch the request', () => {
service.configure(request);
expect(serviceAsAny.dispatchRequest).not.toHaveBeenCalled(); expect(serviceAsAny.dispatchRequest).not.toHaveBeenCalled();
}); });
}); });
}); });
describe('if the request isn\'t a GET request', () => { describe('when the request isn\'t a GET request', () => {
it('should dispatch the request', () => { it('should dispatch the request', () => {
initServices();
spyOn(serviceAsAny, 'dispatchRequest');
service.configure(testPostRequest); service.configure(testPostRequest);
expect(serviceAsAny.dispatchRequest).toHaveBeenCalledWith(testPostRequest); expect(serviceAsAny.dispatchRequest).toHaveBeenCalledWith(testPostRequest);
@@ -277,14 +277,11 @@ describe('RequestService', () => {
describe('isCachedOrPending', () => { describe('isCachedOrPending', () => {
describe('when the request is cached', () => { describe('when the request is cached', () => {
describe('in the ObjectCache', () => { describe('in the ObjectCache', () => {
it('should return true', () => { beforeEach(() => {
initServices(defaultSelectResult, true, Observable.of({ (objectCache.hasBySelfLink as any).and.returnValues(true);
response: { });
isSuccessful: true
}
}
), true);
it('should return true', () => {
const result = serviceAsAny.isCachedOrPending(testGetRequest); const result = serviceAsAny.isCachedOrPending(testGetRequest);
const expected = true; const expected = true;
@@ -292,9 +289,13 @@ describe('RequestService', () => {
}); });
}); });
describe('in the responseCache', () => { describe('in the responseCache', () => {
beforeEach(() => {
(responseCache.has as any).and.returnValues(true);
});
describe('and it\'s a DSOSuccessResponse', () => { describe('and it\'s a DSOSuccessResponse', () => {
it('should return true if all top level links in the response are cached in the object cache', () => { beforeEach(() => {
initServices(defaultSelectResult, true, Observable.of({ (responseCache.get as any).and.returnValues(Observable.of({
response: { response: {
isSuccessful: true, isSuccessful: true,
resourceSelfLinks: [ resourceSelfLinks: [
@@ -303,7 +304,11 @@ describe('RequestService', () => {
] ]
} }
} }
), [false, true, true]); ));
});
it('should return true if all top level links in the response are cached in the object cache', () => {
(objectCache.hasBySelfLink as any).and.returnValues(false, true, true);
const result = serviceAsAny.isCachedOrPending(testGetRequest); const result = serviceAsAny.isCachedOrPending(testGetRequest);
const expected = true; const expected = true;
@@ -311,16 +316,7 @@ describe('RequestService', () => {
expect(result).toEqual(expected); expect(result).toEqual(expected);
}); });
it('should return false if not all top level links in the response are cached in the object cache', () => { it('should return false if not all top level links in the response are cached in the object cache', () => {
initServices(defaultSelectResult, true, Observable.of({ (objectCache.hasBySelfLink as any).and.returnValues(false, true, false);
response: {
isSuccessful: true,
resourceSelfLinks: [
'https://rest.api/endpoint/selfLink1',
'https://rest.api/endpoint/selfLink2'
]
}
}
), [false, true, false]);
const result = serviceAsAny.isCachedOrPending(testGetRequest); const result = serviceAsAny.isCachedOrPending(testGetRequest);
const expected = false; const expected = false;
@@ -329,14 +325,18 @@ describe('RequestService', () => {
}); });
}); });
describe('and it isn\'t a DSOSuccessResponse', () => { describe('and it isn\'t a DSOSuccessResponse', () => {
it('should return true', () => { beforeEach(() => {
initServices(defaultSelectResult, true, Observable.of({ (objectCache.hasBySelfLink as any).and.returnValues(false);
(responseCache.has as any).and.returnValues(true);
(responseCache.get as any).and.returnValues(Observable.of({
response: { response: {
isSuccessful: true isSuccessful: true
} }
} }
), false); ));
});
it('should return true', () => {
const result = serviceAsAny.isCachedOrPending(testGetRequest); const result = serviceAsAny.isCachedOrPending(testGetRequest);
const expected = true; const expected = true;
@@ -347,10 +347,11 @@ describe('RequestService', () => {
}); });
describe('when the request is pending', () => { describe('when the request is pending', () => {
it('should return true', () => { beforeEach(() => {
initServices();
spyOn(service, 'isPending').and.returnValue(true); spyOn(service, 'isPending').and.returnValue(true);
});
it('should return true', () => {
const result = serviceAsAny.isCachedOrPending(testGetRequest); const result = serviceAsAny.isCachedOrPending(testGetRequest);
const expected = true; const expected = true;
@@ -360,8 +361,6 @@ describe('RequestService', () => {
describe('when the request is neither cached nor pending', () => { describe('when the request is neither cached nor pending', () => {
it('should return false', () => { it('should return false', () => {
initServices();
const result = serviceAsAny.isCachedOrPending(testGetRequest); const result = serviceAsAny.isCachedOrPending(testGetRequest);
const expected = false; const expected = false;
@@ -371,27 +370,31 @@ describe('RequestService', () => {
}); });
describe('dispatchRequest', () => { describe('dispatchRequest', () => {
beforeEach(() => {
initServices();
});
it('should dispatch a RequestConfigureAction', () => { it('should dispatch a RequestConfigureAction', () => {
const request = testGetRequest; const request = testGetRequest;
serviceAsAny.dispatchRequest(request); serviceAsAny.dispatchRequest(request);
expect(store.dispatch).toHaveBeenCalledWith(new RequestConfigureAction(request)); expect(store.dispatch).toHaveBeenCalledWith(new RequestConfigureAction(request));
}); });
it('should dispatch a RequestExecuteAction', () => { it('should dispatch a RequestExecuteAction', () => {
const request = testGetRequest; const request = testGetRequest;
serviceAsAny.dispatchRequest(request); serviceAsAny.dispatchRequest(request);
expect(store.dispatch).toHaveBeenCalledWith(new RequestExecuteAction(request.uuid)); expect(store.dispatch).toHaveBeenCalledWith(new RequestExecuteAction(request.uuid));
}); });
describe('when it\'s a GET request', () => { describe('when it\'s a GET request', () => {
let request: RestRequest;
beforeEach(() => {
request = testGetRequest;
});
it('should track it on it\'s way to the store', () => { it('should track it on it\'s way to the store', () => {
spyOn(serviceAsAny, 'trackRequestsOnTheirWayToTheStore'); spyOn(serviceAsAny, 'trackRequestsOnTheirWayToTheStore');
const request = testGetRequest;
serviceAsAny.dispatchRequest(request); serviceAsAny.dispatchRequest(request);
expect(serviceAsAny.trackRequestsOnTheirWayToTheStore).toHaveBeenCalledWith(request); expect(serviceAsAny.trackRequestsOnTheirWayToTheStore).toHaveBeenCalledWith(request);
}); });
}); });
describe('when it\'s not a GET request', () => { describe('when it\'s not a GET request', () => {
it('shouldn\'t track it', () => { it('shouldn\'t track it', () => {
spyOn(serviceAsAny, 'trackRequestsOnTheirWayToTheStore'); spyOn(serviceAsAny, 'trackRequestsOnTheirWayToTheStore');
@@ -421,7 +424,6 @@ describe('RequestService', () => {
let request: GetRequest; let request: GetRequest;
beforeEach(() => { beforeEach(() => {
initServices();
request = testGetRequest; request = testGetRequest;
}); });
@@ -435,7 +437,7 @@ describe('RequestService', () => {
describe('when the request is added to the store', () => { describe('when the request is added to the store', () => {
it('should stop tracking the request', () => { it('should stop tracking the request', () => {
(store.select as any).and.returnValue(Observable.of({ request })); (store.select as any).and.returnValues(Observable.of({ request }));
serviceAsAny.trackRequestsOnTheirWayToTheStore(request); serviceAsAny.trackRequestsOnTheirWayToTheStore(request);
expect(serviceAsAny.requestsOnTheirWayToTheStore.includes(request.href)).toBeFalsy(); expect(serviceAsAny.requestsOnTheirWayToTheStore.includes(request.href)).toBeFalsy();
}); });

View File

@@ -1,6 +1,6 @@
import { cold, hot } from 'jasmine-marbles'; import { cold, hot } from 'jasmine-marbles';
import { GlobalConfig } from '../../../config/global-config.interface'; import { GlobalConfig } from '../../../config/global-config.interface';
import { initMockRequestService } from '../../shared/mocks/mock-request.service'; import { getMockRequestService } from '../../shared/mocks/mock-request.service';
import { ResponseCacheService } from '../cache/response-cache.service'; import { ResponseCacheService } from '../cache/response-cache.service';
import { RootEndpointRequest } from '../data/request.models'; import { RootEndpointRequest } from '../data/request.models';
import { RequestService } from '../data/request.service'; import { RequestService } from '../data/request.service';
@@ -39,7 +39,7 @@ describe('HALEndpointService', () => {
}) })
}); });
requestService = initMockRequestService(); requestService = getMockRequestService();
envConfig = { envConfig = {
rest: { baseUrl: 'https://rest.api/' } rest: { baseUrl: 'https://rest.api/' }

View File

@@ -1,6 +1,6 @@
import { ObjectCacheService } from '../../core/cache/object-cache.service'; import { ObjectCacheService } from '../../core/cache/object-cache.service';
export function initMockObjectCacheService(): ObjectCacheService { export function getMockObjectCacheService(): ObjectCacheService {
return jasmine.createSpyObj('objectCacheService', [ return jasmine.createSpyObj('objectCacheService', [
'add', 'add',
'remove', 'remove',

View File

@@ -1,6 +1,6 @@
import { RequestService } from '../../core/data/request.service'; import { RequestService } from '../../core/data/request.service';
export function initMockRequestService(): RequestService { export function getMockRequestService(): RequestService {
return jasmine.createSpyObj('requestService', { return jasmine.createSpyObj('requestService', {
configure: () => false, configure: () => false,
generateRequestId: () => 'clients/b186e8ce-e99c-4183-bc9a-42b4821bdb78' generateRequestId: () => 'clients/b186e8ce-e99c-4183-bc9a-42b4821bdb78'

View File

@@ -0,0 +1,10 @@
import { ResponseCacheService } from '../../core/cache/response-cache.service';
export function getMockResponseCacheService(): ResponseCacheService {
return jasmine.createSpyObj('ResponseCacheService', [
'add',
'get',
'has',
]);
}

View File

@@ -1,9 +1,15 @@
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
export function initMockStore<T>(selectResult: Observable<T>): Store<T> { export function getMockStore<T>(): Store<T> {
return jasmine.createSpyObj('store', { return jasmine.createSpyObj('store', [
dispatch: null, 'select',
select: selectResult, 'dispatch',
}); 'lift',
'next',
'error',
'complete',
'addReducer',
'removeReducer'
]);
} }

View File

@@ -2,7 +2,7 @@ import { UUIDService } from '../../core/shared/uuid.service';
export const defaultUUID = 'c4ce6905-290b-478f-979d-a333bbd7820f'; export const defaultUUID = 'c4ce6905-290b-478f-979d-a333bbd7820f';
export function initMockUUIDService(uuid = defaultUUID): UUIDService { export function getMockUUIDService(uuid = defaultUUID): UUIDService {
return jasmine.createSpyObj('uuidService', { return jasmine.createSpyObj('uuidService', {
generate: uuid, generate: uuid,
}); });