Skip to content

Commit

Permalink
Fixed unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Aug 13, 2019
1 parent 0a60127 commit 76dcaa6
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import { MetadataSourceEditor } from '../../domain/model/wizards/metadata-source
import { ResolverService } from '../../domain/service/resolver.service';
import { of } from 'rxjs';
import { MetadataProviderService } from '../../domain/service/provider.service';
import { Metadata } from '../../domain/domain.type';
import { SCHEMA } from '../../../../testing/form-schema.stub';
import { getConfigurationSectionsFn } from '../reducer';

describe(`Configuration Service`, () => {

let resolverService: any;
let providerService: any;

let mockService = {
find: () => of([])
Expand All @@ -36,11 +40,12 @@ describe(`Configuration Service`, () => {
});

resolverService = TestBed.get(ResolverService);
providerService = TestBed.get(MetadataProviderService);

});

describe('find method', () => {
it(`should send an expected GET request`, async(inject([MetadataConfigurationService, HttpTestingController],
it(`should call the resolver service when type is resolver`, async(inject([MetadataConfigurationService, HttpTestingController],
(service: MetadataConfigurationService, backend: HttpTestingController) => {
spyOn(resolverService, 'find').and.callThrough();
const type = 'resolver';
Expand All @@ -49,6 +54,25 @@ describe(`Configuration Service`, () => {
expect(resolverService.find).toHaveBeenCalledWith(id);
}
)));
it(`should call the provider service when type is resolver`, async(inject([MetadataConfigurationService, HttpTestingController],
(service: MetadataConfigurationService, backend: HttpTestingController) => {
spyOn(providerService, 'find').and.callThrough();
const type = 'provider';
const id = 'foo';
service.find(id, type).subscribe();
expect(providerService.find).toHaveBeenCalledWith(id);
}
)));
it(`should throw an error when a type is not found`, async(inject([MetadataConfigurationService, HttpTestingController],
(service: MetadataConfigurationService, backend: HttpTestingController) => {
spyOn(providerService, 'find').and.callThrough();
const type = 'bar';
const id = 'foo';
service.find(id, type).subscribe(null, (err) => {
expect(err).toEqual(new Error('Type not supported'));
});
}
)));
});

describe('loadSchema method', () => {
Expand Down Expand Up @@ -79,4 +103,15 @@ describe(`Configuration Service`, () => {
}
)));
});

describe('getMetadataConfiguration method', () => {
it('should return the parsed configuration', async(inject([MetadataConfigurationService],
(service: MetadataConfigurationService) => {
const model = {} as Metadata;
const definition = {steps: []};
const expected = getConfigurationSectionsFn([model], definition, SCHEMA);
expect(service.getMetadataConfiguration(model, definition, SCHEMA)).toEqual(expected);
}
)));
});
});

0 comments on commit 76dcaa6

Please sign in to comment.