mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
add test fix mocks
This commit is contained in:
@@ -10,6 +10,8 @@ export const mockLdnService: LdnService = {
|
||||
enabled: false,
|
||||
score: 0,
|
||||
id: 1,
|
||||
lowerIp: '192.0.2.146',
|
||||
upperIp: '192.0.2.255',
|
||||
name: 'Service Name',
|
||||
description: 'Service Description',
|
||||
url: 'Service URL',
|
||||
@@ -45,6 +47,8 @@ export const mockLdnServices: LdnService[] = [{
|
||||
enabled: false,
|
||||
score: 0,
|
||||
id: 1,
|
||||
lowerIp: '192.0.2.146',
|
||||
upperIp: '192.0.2.255',
|
||||
name: 'Service Name',
|
||||
description: 'Service Description',
|
||||
url: 'Service URL',
|
||||
@@ -75,6 +79,8 @@ export const mockLdnServices: LdnService[] = [{
|
||||
enabled: false,
|
||||
score: 0,
|
||||
id: 2,
|
||||
lowerIp: '192.0.2.146',
|
||||
upperIp: '192.0.2.255',
|
||||
name: 'Service Name',
|
||||
description: 'Service Description',
|
||||
url: 'Service URL',
|
||||
|
@@ -0,0 +1,85 @@
|
||||
import { TestScheduler } from "rxjs/testing";
|
||||
import { LdnItemfiltersService } from "./ldn-itemfilters-data.service";
|
||||
import { RequestService } from "../../../core/data/request.service";
|
||||
import { RemoteDataBuildService } from "../../../core/cache/builders/remote-data-build.service";
|
||||
import { ObjectCacheService } from "../../../core/cache/object-cache.service";
|
||||
import { HALEndpointService } from "../../../core/shared/hal-endpoint.service";
|
||||
import { NotificationsService } from "../../../shared/notifications/notifications.service";
|
||||
import { RequestEntry } from "../../../core/data/request-entry.model";
|
||||
import { RemoteData } from "../../../core/data/remote-data";
|
||||
import { RequestEntryState } from "../../../core/data/request-entry-state.model";
|
||||
import { cold, getTestScheduler } from "jasmine-marbles";
|
||||
import { RestResponse } from "../../../core/cache/response.models";
|
||||
import { of } from "rxjs";
|
||||
import { createSuccessfulRemoteDataObject$ } from "../../../shared/remote-data.utils";
|
||||
import { FindAllData } from "../../../core/data/base/find-all-data";
|
||||
import { testFindAllDataImplementation } from "../../../core/data/base/find-all-data.spec";
|
||||
|
||||
describe('LdnItemfiltersService test', () => {
|
||||
let scheduler: TestScheduler;
|
||||
let service: LdnItemfiltersService;
|
||||
let requestService: RequestService;
|
||||
let rdbService: RemoteDataBuildService;
|
||||
let objectCache: ObjectCacheService;
|
||||
let halService: HALEndpointService;
|
||||
let notificationsService: NotificationsService;
|
||||
let responseCacheEntry: RequestEntry;
|
||||
|
||||
const endpointURL = `https://rest.api/rest/api/ldn/itemfilters`;
|
||||
const requestUUID = '8b3c613a-5a4b-438b-9686-be1d5b4a1c5a';
|
||||
|
||||
const remoteDataMocks = {
|
||||
Success: new RemoteData(null, null, null, RequestEntryState.Success, null, null, 200),
|
||||
};
|
||||
|
||||
function initTestService() {
|
||||
return new LdnItemfiltersService(
|
||||
requestService,
|
||||
rdbService,
|
||||
objectCache,
|
||||
halService,
|
||||
notificationsService,
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
scheduler = getTestScheduler();
|
||||
|
||||
objectCache = {} as ObjectCacheService;
|
||||
notificationsService = {} as NotificationsService;
|
||||
responseCacheEntry = new RequestEntry();
|
||||
responseCacheEntry.request = { href: 'https://rest.api/' } as any;
|
||||
responseCacheEntry.response = new RestResponse(true, 200, 'Success');
|
||||
|
||||
requestService = jasmine.createSpyObj('requestService', {
|
||||
generateRequestId: requestUUID,
|
||||
send: true,
|
||||
removeByHrefSubstring: {},
|
||||
getByHref: of(responseCacheEntry),
|
||||
getByUUID: of(responseCacheEntry),
|
||||
});
|
||||
|
||||
halService = jasmine.createSpyObj('halService', {
|
||||
getEndpoint: of(endpointURL)
|
||||
});
|
||||
|
||||
rdbService = jasmine.createSpyObj('rdbService', {
|
||||
buildSingle: createSuccessfulRemoteDataObject$({}, 500),
|
||||
buildList: cold('a', { a: remoteDataMocks.Success })
|
||||
});
|
||||
|
||||
|
||||
service = initTestService();
|
||||
});
|
||||
|
||||
describe('composition', () => {
|
||||
const initFindAllService = () => new LdnItemfiltersService(null, null, null, null, null) as unknown as FindAllData<any>;
|
||||
testFindAllDataImplementation(initFindAllService);
|
||||
});
|
||||
|
||||
describe('get endpoint', () => {
|
||||
service.getEndpoint()
|
||||
expect(halService.getEndpoint).toHaveBeenCalledWith('linkPath')
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user