diff options
Diffstat (limited to 'vid-webpack-master/src/app/shared/services/templateService/instantiationTemplates.service.spec.ts')
-rw-r--r-- | vid-webpack-master/src/app/shared/services/templateService/instantiationTemplates.service.spec.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/services/templateService/instantiationTemplates.service.spec.ts b/vid-webpack-master/src/app/shared/services/templateService/instantiationTemplates.service.spec.ts new file mode 100644 index 000000000..80b113bde --- /dev/null +++ b/vid-webpack-master/src/app/shared/services/templateService/instantiationTemplates.service.spec.ts @@ -0,0 +1,51 @@ +import {HttpClientTestingModule, HttpTestingController} from "@angular/common/http/testing"; +import {InstantiationTemplatesService} from "./instantiationTemplates.service"; +import {mock} from "ts-mockito"; +import {NgRedux} from "@angular-redux/store"; +import {getTestBed, TestBed} from "@angular/core/testing"; +import {ServiceInstance} from "../../models/serviceInstance"; +import {Constants} from "../../utils/constants"; + +class MockAppStore<T> { + dispatch() {} + getState() {} +} + +describe("TemplateService", ()=>{ + let injector; + let httpMock: HttpTestingController; + let templateService: InstantiationTemplatesService; + + beforeAll( done => (async () => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [ + InstantiationTemplatesService, + {provide: NgRedux, useClass: MockAppStore}, + ] + }); + await TestBed.compileComponents(); + + injector = getTestBed(); + httpMock = injector.get(HttpTestingController); + templateService = injector.get(InstantiationTemplatesService); + })().then(done).catch(done.fail)); + + describe ('#retrieveInstantiationTemplateTopology tests', () => { + test('when called -> retrieve template from backend', done => { + const mockedTemplate = mock(ServiceInstance); + const jobId: string = "some-random-job-id"; + + templateService.retrieveInstantiationTemplateTopology(jobId) + .subscribe((result: ServiceInstance) => { + expect(Object.is(result, mockedTemplate)).toBe(true); + done(); + }); + + httpMock + .expectOne(`${Constants.Path.INSTANTIATION_TEMPLATE_TOPOLOGY}/${jobId}`) + .flush(mockedTemplate); + }) + }) +}); + |