Skip to content

Commit

Permalink
all old test are passed
Browse files Browse the repository at this point in the history
  • Loading branch information
Vixtir committed Dec 4, 2018
1 parent ed7863a commit 1491e7b
Show file tree
Hide file tree
Showing 21 changed files with 121 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { RouterModule } from '@angular/router';
import { SharedModule } from '@shared/shared.module';
import { ApplicationsItemDetailComponent } from './applications-item-detail.component';

import { HttpClient, HttpHandler } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { LoaderStateService, InfluxDBService } from '@core/services';
import { HttpService } from '@core/services/http';
import { MetricsService } from '@core/services/metrics/metrics.service';
import { DialogService } from '@dialog/dialog.service';
import { Store } from '@ngrx/store';
import { application } from '@testing/factories/application';
import { MockStoreProvider } from '@testing/mocks';
import { of } from 'rxjs';

describe('ApplicationsItemDetailComponent', () => {
let component: ApplicationsItemDetailComponent;
Expand All @@ -23,15 +24,14 @@ describe('ApplicationsItemDetailComponent', () => {
SharedModule,
RouterModule,
SharedModule,
HttpClientTestingModule,
],
providers: [
MockStoreProvider,
DialogService,
MetricsService,
LoaderStateService,
InfluxDBService,
HttpHandler,
HttpClient,
HttpService,
],
})
Expand All @@ -41,6 +41,8 @@ describe('ApplicationsItemDetailComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(ApplicationsItemDetailComponent);
component = fixture.componentInstance;
component.application$ = of(application);

fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ describe('ApplicationsStageDetailComponent', () => {
MockStoreProvider,
DialogService,
],
})
.compileComponents();
}).compileComponents();
}));

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ describe('DialogAddApplicationComponent', () => {
MockStoreProvider,
CustomValidatorsService,
],
})
.compileComponents();
}).compileComponents();
}));

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<hydro-application-form (onSubmit)="onSubmit($event)" [data]="data" #form></hydro-application-form>
<hydro-application-form (onSubmit)="onSubmit($event)" [data]="application" #form></hydro-application-form>
<div class="dialog__footer">
<div class="buttons-group">
<div class="button button--flat button--large" (click)="onClose()">cancel</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { ApplicationFormComponent, KafkaFormComponent, ServiceFormComponent } fr
import { CustomValidatorsService } from '@core/services/custom-validators.service';
import { DialogService } from '@dialog/dialog.service';
import { SharedModule } from '@shared/shared.module';
import { MockSelectedApplication, MockSelectedUpdApplication, MockStoreProvider } from '@testing/mocks';
import { DialogUpdateApplicationComponent } from './dialog-update-application.component';
import { application } from '@testing/factories/application';
import { MockStoreProvider } from '@testing/mocks';
import { of } from 'rxjs';
import { DialogUpdateApplicationComponent, SELECTED_UPD_APPLICATION$ } from './dialog-update-application.component';

describe('DialogUpdateApplicationComponent', () => {
let component: DialogUpdateApplicationComponent;
Expand All @@ -27,13 +29,12 @@ describe('DialogUpdateApplicationComponent', () => {
ServiceFormComponent,
],
providers: [
MockSelectedUpdApplication,
{ provide: SELECTED_UPD_APPLICATION$, useValue: of(application) },
MockStoreProvider,
DialogService,
CustomValidatorsService,
],
})
.compileComponents();
}).compileComponents();
}));

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ export let SELECTED_UPD_APPLICATION$ = new InjectionToken<Observable<Application
templateUrl: './dialog-update-application.component.html',
})
export class DialogUpdateApplicationComponent implements OnInit, OnDestroy {
public data$: Observable<Application>;
public dataSub: Subscription;
public data: Application;
public application$: Observable<Application>;
public applicationSub: Subscription;
public application: Application;

constructor(
@Inject(SELECTED_UPD_APPLICATION$) data: Observable<Application>,
@Inject(SELECTED_UPD_APPLICATION$) application: Observable<Application>,
public store: Store<HydroServingState>,
public dialog: DialogService
) {
this.data$ = data;
this.application$ = application;
}

ngOnInit(): void {
this.dataSub = this.data$.subscribe(data => {
this.data = data;
this.applicationSub = this.application$.subscribe(application => {
this.application = application;
});
}

Expand All @@ -39,14 +39,14 @@ export class DialogUpdateApplicationComponent implements OnInit, OnDestroy {
}

public onSubmit(formData) {
formData.id = this.data.id;
formData.id = this.application.id;
const application = new Application(formData);
this.store.dispatch(new HydroActions.UpdateApplicationAction(application));

this.onClose();
}

ngOnDestroy(): void {
this.dataSub.unsubscribe();
this.applicationSub.unsubscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class ServiceFormComponent implements OnInit {
this.modelVersionIdControl.setValue(this.serviceFormService.getDefaultModelVersion().id);
}

public onModelVersionChange(modelVersionId): void {
public onModelVersionChange(modelVersionId: number): void {
this.signatureName.patchValue(this.serviceFormService.getSignature(modelVersionId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ export class ApplicationsBuilderService {
id,
contract,
name: props.name,
executionGraph: props.executionGraph,
kafkaStreaming: props.kafkaStreaming,
executionGraph: props.executionGraph || [],
kafkaStreaming: props.kafkaStreaming || [],
});

return application;
}

}
23 changes: 14 additions & 9 deletions src/modules/applications/services/service-form.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, OnDestroy } from '@angular/core';
import { Injectable, OnDestroy, Type } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';

import { Store } from '@ngrx/store';
Expand Down Expand Up @@ -48,9 +48,14 @@ export class ServiceFormService implements OnDestroy {
);
}

public getSignature(versionId): string {
const modelVersion = this.allModelVersions.find(version => version.id === versionId);
return hocon(modelVersion.modelContract).signatures.signature_name;
public getSignature(modelVersionId: number): string {
const modelVer = this.allModelVersions.find(version => version.id === modelVersionId);
try {
return hocon(modelVer.modelContract).signatures.signature_name;
} catch (err) {
console.error(err);
return '';
}
}

public getModelVersions(): Observable<any> {
Expand Down Expand Up @@ -78,7 +83,7 @@ export class ServiceFormService implements OnDestroy {
const modelId = this.defaultModelId();
this.updateModelVersionList(modelId);
const modelVersion = this.getDefaultModelVersion();
const signatureName = this.getSignature(modelVersion.id);
const signatureName = modelVersion ? this.getSignature(modelVersion.id) : '';

return {
weight: 100,
Expand All @@ -90,7 +95,7 @@ export class ServiceFormService implements OnDestroy {
},
signatureName,
modelVersion: {
id: modelVersion.id,
id: modelVersion && modelVersion.id,
model: {
id: modelId,
},
Expand All @@ -106,7 +111,7 @@ export class ServiceFormService implements OnDestroy {
);
const runtime = new FormControl(service.runtime.id, this.customValidators.required());
const signatureName = new FormControl(
service.signatureName || this.getSignature(service.modelVersion.id),
service.signatureName || this.getSignature(service.modelVersion && service.modelVersion.id),
[this.customValidators.required(), this.customValidators.pattern(/[a-zA-Z0-9]+/)]
);
const model = new FormGroup({
Expand All @@ -130,13 +135,13 @@ export class ServiceFormService implements OnDestroy {
}

private defaultRuntimeId() {
if (this.runtimes) {
if (this.runtimes[0]) {
return this.runtimes[0].id;
}
}

private defaultModelId() {
if (this.models.length) {
if (this.models[0]) {
return this.models[0].id;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/modules/core/services/command-creator/command-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export abstract class CommandCreator {
abstract getCommand(application: Application): string;

protected getApplicationContract({contract}: Application): IApplicationContract {
return hocon(contract);
if (contract) {
return hocon(contract);
}
}
}
16 changes: 10 additions & 6 deletions src/modules/core/services/command-creator/curl-command-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Application } from '@shared/_index';
import { CommandCreator, IApplicationContract } from './command-creator';

export class CurlCommandCreator extends CommandCreator {
readonly headers: string = `--header 'Content-Type: application/json' --header 'Accept: application/json'`;

get apiUrl() {
if (environment.production) {
const { protocol, hostname } = window.location;
Expand All @@ -13,12 +15,14 @@ export class CurlCommandCreator extends CommandCreator {
}

getCommand(application: Application): string {
const headers = `--header 'Content-Type: application/json' --header 'Accept: application/json'`;
const { input, name } = application;
const contract: IApplicationContract = this.getApplicationContract(application);
const url: string = `${this.apiUrl}/gateway/applications/${name}/${contract.signatures.signature_name}`;

return `curl -X POST ${headers} -d '${this.removeNewLineSymbolsFromString(input)}' '${url}'`.trim();
try {
const { input, name } = application;
const contract: IApplicationContract = this.getApplicationContract(application);
const url: string = `${this.apiUrl}/gateway/applications/${name}/${contract.signatures.signature_name}`;
return `curl -X POST ${this.headers} -d '${this.removeNewLineSymbolsFromString(input)}' '${url}'`.trim();
} catch (err) {
return 'invalid contract';
}
}

private removeNewLineSymbolsFromString(str: string = ''): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class GrpcCommandCreator extends CommandCreator {

return { inputKey, inputValue };
} catch {
return {inputKey: ' %input key% ', inputValue: '%input value% '};
return { inputKey: ' %input key% ', inputValue: '%input value% ' };
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { RouterTestingModule } from '@angular/router/testing';
import { DialogService } from '@dialog/dialog.service';
import { SharedModule } from '@shared/shared.module';
import { MockStoreProvider } from '@testing/mocks';
import { MomentModule } from 'angular2-moment';
import { ModelDetailsComponent } from './model-details.component';

describe('ModelDetailsComponent', () => {
Expand All @@ -9,9 +13,17 @@ describe('ModelDetailsComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ModelDetailsComponent],
declarations: [
ModelDetailsComponent,
],
imports: [
SharedModule,
MomentModule,
RouterTestingModule,
],
providers: [
MockStoreProvider,
DialogService,
],
})
.compileComponents();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { MdlSelectModule } from '@angular-mdl/select';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { SignaturesService, LoaderStateService } from '@core/services';
import { HttpService } from '@core/services/http';
import {
DataComparisonHistogramComponent
} from '@profiles/components/data-comparison-histogram/data-comparison-histogram.component';
import { DataProfilesComponent } from '@profiles/components/data-profiles/data-profiles.component';
import { DataStatsComponent } from '@profiles/components/data-stats/data-stats.component';
import { SharedModule } from '@shared/shared.module';
import { modelBuild } from '@testing/factories/modelBuild';
import { MockStoreProvider } from '@testing/mocks';
import { MomentModule } from 'angular2-moment';
import { of } from 'rxjs';
import { ModelVersionDetailsComponent } from './model-version-details.component';

describe('ModelVersionDetailsComponent', () => {
Expand All @@ -10,23 +23,38 @@ describe('ModelVersionDetailsComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ModelVersionDetailsComponent],
declarations: [
ModelVersionDetailsComponent,
DataProfilesComponent,
DataComparisonHistogramComponent,
DataStatsComponent,
],
imports: [
MdlSelectModule,
SharedModule,
RouterTestingModule,
MomentModule,
HttpClientTestingModule,
],
providers: [
MockStoreProvider,
SignaturesService,
HttpService,
LoaderStateService,
],
})
.compileComponents();
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ModelVersionDetailsComponent);
component = fixture.componentInstance;
// TODO: mock store
component.build$ = of(modelBuild);

fixture.detectChanges();
});

it('it should be created', () => {
expect(component).toBeTruthy();
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export class ModelVersionDetailsComponent implements OnInit, OnDestroy {
'Field name', 'Data type', 'Shape',
];

public contracts: Signature[];
public build: any;
public build$: Observable<ModelBuild>;

public modelId: number;
Expand Down
Loading

0 comments on commit 1491e7b

Please sign in to comment.