Added more tests

This commit is contained in:
Giuseppe Digilio
2018-06-22 15:13:49 +02:00
parent 40ccbdf653
commit e6c68c9396
13 changed files with 325 additions and 45 deletions

View File

@@ -0,0 +1,94 @@
import { cold, getTestScheduler } from 'jasmine-marbles';
import { TestScheduler } from 'rxjs/Rx';
import { getMockRequestService } from '../../shared/mocks/mock-request.service';
import { ResponseCacheService } from '../cache/response-cache.service';
import { RequestService } from '../data/request.service';
import { IntegrationRequest } from '../data/request.models';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service-stub';
import { IntegrationService } from './integration.service';
import { IntegrationSearchOptions } from './models/integration-options.model';
const LINK_NAME = 'authorities';
const BROWSE = 'entries';
class TestService extends IntegrationService {
protected linkPath = LINK_NAME;
protected browseEndpoint = BROWSE;
constructor(
protected responseCache: ResponseCacheService,
protected requestService: RequestService,
protected halService: HALEndpointService) {
super();
}
}
describe('IntegrationService', () => {
let scheduler: TestScheduler;
let service: TestService;
let responseCache: ResponseCacheService;
let requestService: RequestService;
let halService: any;
let findOptions: IntegrationSearchOptions;
const name = 'type';
const metadata = 'dc.type';
const query = '';
const uuid = 'd9d30c0c-69b7-4369-8397-ca67c888974d';
const integrationEndpoint = 'https://rest.api/integration';
const serviceEndpoint = `${integrationEndpoint}/${LINK_NAME}`;
const entriesEndpoint = `${serviceEndpoint}/${name}/entries?query=${query}&metadata=${metadata}&uuid=${uuid}`;
findOptions = new IntegrationSearchOptions(uuid, name, metadata);
function initMockResponseCacheService(isSuccessful: boolean): ResponseCacheService {
return jasmine.createSpyObj('responseCache', {
get: cold('c-', {
c: {response: {isSuccessful}}
})
});
}
function initTestService(): TestService {
return new TestService(
responseCache,
requestService,
halService
);
}
beforeEach(() => {
responseCache = initMockResponseCacheService(true);
requestService = getMockRequestService();
scheduler = getTestScheduler();
halService = new HALEndpointServiceStub(integrationEndpoint);
findOptions = new IntegrationSearchOptions(uuid, name, metadata, query);
service = initTestService();
});
describe('getEntriesByName', () => {
it('should configure a new IntegrationRequest', () => {
const expected = new IntegrationRequest(requestService.generateRequestId(), entriesEndpoint);
scheduler.schedule(() => service.getEntriesByName(findOptions).subscribe());
scheduler.flush();
expect(requestService.configure).toHaveBeenCalledWith(expected);
});
});
// describe('getConfigBySearch', () => {
//
// it('should configure a new ConfigRequest', () => {
// findOptions.uuid = uuid;
// const expected = new ConfigRequest(requestService.generateRequestId(), searchEndpoint);
// scheduler.schedule(() => service.getConfigBySearch(findOptions).subscribe());
// scheduler.flush();
//
// expect(requestService.configure).toHaveBeenCalledWith(expected);
// });
// });
});