Skip to content

Commit

Permalink
test updates (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy authored Apr 3, 2021
1 parent 33d7360 commit 0d40398
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 21 deletions.
33 changes: 33 additions & 0 deletions src/app/_interceptors/mock-interceptior.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Injectable, Injector } from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http';

import { Observable, of } from 'rxjs';


@Injectable()
export class HttpRequestInterceptorMock implements HttpInterceptor {
constructor(private injector: Injector) { }

intercept(request: HttpRequest<any>, next: HttpHandler):
Observable<HttpEvent<any>> {
if (request.url &&
request.url.includes(`projects/test-project/scenarios/test-scenario/notification`)) {
return of(new HttpResponse({ status: 200, body: [] }));
}
if (request.url &&
request.url.includes('projects/test-project/scenarios/test-scenario/items/test-item/share-tokens')) {
return of(new HttpResponse({ status: 200, body: [] }));
}
if (request.url &&
request.url.includes('api-tokens')) {
return of(new HttpResponse({ status: 200, body: [] }));
}
if (request.url &&
request.url.includes('projects/test-project/scenarios/test-scenario/items/test-item/custom-chart-settings')) {
return of(new HttpResponse({ status: 200 }));
}


return next.handle(request);
}
}
12 changes: 9 additions & 3 deletions src/app/administration/api-token/api-keys.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ import { ControlPanelComponent } from 'src/app/control-panel/control-panel.compo
import { DeleteTokenComponent } from './delete-token/delete-token.component';
import { RouterTestingModule } from '@angular/router/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { HttpRequestInterceptorMock } from 'src/app/_interceptors/mock-interceptior';


xdescribe('ApiKeysComponent', () => {
describe('ApiKeysComponent', () => {
let component: ApiKeysComponent;
let fixture: ComponentFixture<ApiKeysComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule, ReactiveFormsModule, HttpClientModule],
declarations: [ApiKeysComponent, NavigationComponent, AddTokenComponent, ControlPanelComponent, DeleteTokenComponent]
declarations: [ApiKeysComponent, NavigationComponent, AddTokenComponent, ControlPanelComponent, DeleteTokenComponent],
providers: [{
provide: HTTP_INTERCEPTORS,
useClass: HttpRequestInterceptorMock,
multi: true
}]
})
.compileComponents();
}));
Expand Down
20 changes: 16 additions & 4 deletions src/app/administration/users/users.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,30 @@ import { AddUserComponent } from './add-user/add-user.component';
import { ControlPanelComponent } from 'src/app/control-panel/control-panel.component';
import { RouterTestingModule } from '@angular/router/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { DeleteUserComponent } from './delete-user/delete-user.component';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { HttpRequestInterceptorMock } from 'src/app/_interceptors/mock-interceptior';



xdescribe('UsersComponent', () => {
describe('UsersComponent', () => {
let component: UsersComponent;
let fixture: ComponentFixture<UsersComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule, ReactiveFormsModule, HttpClientModule],
declarations: [UsersComponent, NavigationComponent, AddUserComponent, ControlPanelComponent, ]
imports: [RouterTestingModule, ReactiveFormsModule, HttpClientTestingModule],
declarations: [
UsersComponent, NavigationComponent,
AddUserComponent, ControlPanelComponent,
DeleteUserComponent,
],
providers: [{
provide: HTTP_INTERCEPTORS,
useClass: HttpRequestInterceptorMock,
multi: true
}]
})
.compileComponents();
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { HttpClientModule } from '@angular/common/http';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { HighchartsChartModule } from 'highcharts-angular';
import { HttpRequestInterceptorMock } from 'src/app/_interceptors/mock-interceptior';
import { AddMetricComponent } from './add-metric/add-metric.component';

import { AnalyzeChartsComponent } from './analyze-charts.component';
Expand All @@ -19,7 +20,12 @@ describe('AnalyzeChartsComponent', () => {
NgbModule,
FormsModule,
HttpClientModule
]
],
providers: [{
provide: HTTP_INTERCEPTORS,
useClass: HttpRequestInterceptorMock,
multi: true
}]
})
.compileComponents();
}));
Expand All @@ -28,7 +34,7 @@ describe('AnalyzeChartsComponent', () => {
fixture = TestBed.createComponent(AnalyzeChartsComponent);
component = fixture.componentInstance;
component.chartLines = { labels: new Map([['test', [{ name: 'test', data: []}]]]), overall: new Map() };
component.params = { projectName: 'test', scenarioName: 'test', id: 'id' };
component.params = { projectName: 'test-project', scenarioName: 'test-scenario', id: 'test-item' };
fixture.detectChanges();
});

Expand Down
15 changes: 11 additions & 4 deletions src/app/item-detail/share/share.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { HttpClientModule } from '@angular/common/http';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { DataTableModule } from '@rushvora/ng-datatable';
import { HttpRequestInterceptorMock } from 'src/app/_interceptors/mock-interceptior';
import { CreateNewShareLinkComponent } from './create-new-share-link/create-new-share-link.component';
import { DeleteShareLinkComponent } from './delete-share-link/delete-share-link.component';

Expand All @@ -20,17 +22,22 @@ describe('ShareComponent', () => {
imports: [
ReactiveFormsModule,
FormsModule,
HttpClientModule,
HttpClientTestingModule,
DataTableModule
]
],
providers: [{
provide: HTTP_INTERCEPTORS,
useClass: HttpRequestInterceptorMock,
multi: true
}]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ShareComponent);
component = fixture.componentInstance;
component.params = { projectName: 'project', scenarioName: 'scenario', 'id': 'id'};
component.params = { projectName: 'test-project', scenarioName: 'test-scenario', 'id': 'test-item'};
fixture.detectChanges();
});

Expand Down
74 changes: 74 additions & 0 deletions src/app/items-api.service.pact.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { TestBed, async } from '@angular/core/testing';
import { PactWeb, Matchers } from '@pact-foundation/pact-web';
import { HttpClientModule } from '@angular/common/http';
import { ItemsApiService } from './items-api.service';

describe('Items', () => {

let provider;

beforeAll((done) => {
provider = new PactWeb({
port: 1234,
host: '127.0.0.1',
});

// required for slower CI environments
setTimeout(done, 4000);

// Required if run with `singleRun: false`
provider.removeInteractions();
});

afterAll((done) => {
provider.finalize().then(done, e => done.fail(e));
});

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule
],
providers: [
ItemsApiService
],
});
}));

afterEach((done) => {
provider.verify().then(done, e => done.fail(e));
});

describe('/projects/:projectName/scenarios/:scenarionName/items/:id/share-tokens', () => {
describe('GET /projects/:projectName/scenarios/:scenarionName/items/:id/share-tokens', () => {
beforeAll((done) => {
provider.addInteraction({
state: 'there is at least one existing test item',
uponReceiving: 'a request for test item',
withRequest: {
method: 'GET',
path: '/projects/test-project/scenarios/test-scenario/items/28b32386-2c69-41fc-ab98-8b16ef4823af/share-tokens'
},
willRespondWith: {
status: 200,
body: Matchers.eachLike({
name: 'token name',
id: 'e3d1cde2-6079-4b01-8592-4bde15ae6ed7',
token: '93ca7b28a9a97d0f80ec815ddcf046274dcb25fdef5583f7b15fa04c6990300a20a08281fa5838'
})
},
headers: {
'Content-Type': 'application/json'
}
}).then(done, e => done.fail(e));
});
it('should return item share tokens', (done) => {
const itemApiService: ItemsApiService = TestBed.get(ItemsApiService);
itemApiService.fetchItemShareTokens('test-project', 'test-scenario', '28b32386-2c69-41fc-ab98-8b16ef4823af').subscribe(response => {
done();
});
done();
});
});
});
});
48 changes: 48 additions & 0 deletions src/app/scenario-api.service.pact.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,53 @@ describe('Scenario', () => {
});
});
});
describe('GET /project/:projectName/scenarios/:scenarioName/trends', () => {
beforeAll((done) => {
provider.addInteraction({
state: 'there is existing project with at least one scenario and test runs',
uponReceiving: 'a request for scenario trends',
withRequest: {
method: 'GET',
path: '/projects/test-project/scenarios/test-scenario/trends',
},
willRespondWith: {
status: 200,
body: Matchers.eachLike({
id: 'e3d1cde2-6079-4b01-8592-4bde15ae6ed7',
overview: Matchers.somethingLike({
avgLatency: 372,
avgResponseTime: 373,
duration: 11.99,
endDate: Matchers.term({
generate: '2019-07-24T13:12:20.807Z',
matcher: '\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z'
}),
errorRate: 0.48,
maxVu: 10,
percentil: 658,
startDate: Matchers.term({
generate: '2019-07-24T12:00:21.156Z',
matcher: '\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z'
}),
throughput: 24.81,
avgConnect: 10,
bytesPerSecond: 1000,
})
})
},
headers: {
'Content-Type': 'application/json'
}
}).then(done, e => done.fail(e));
});
it('should be able to fetch scenario trends', (done) => {
const scenarioService: ScenarioApiService = TestBed.get(ScenarioApiService);
scenarioService.fetchScenarioTrend('test-project', 'test-scenario').subscribe(response => {
// @ts-ignore
console.log(response);
done();
});
});
});
});
});
29 changes: 29 additions & 0 deletions src/app/scenario/delete-scenario/delete-scenario.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { HttpClientModule } from '@angular/common/http';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { DeleteScenarioComponent } from './delete-scenario.component';


describe('DeleteScenarioComponent', () => {
let component: DeleteScenarioComponent;
let fixture: ComponentFixture<DeleteScenarioComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [DeleteScenarioComponent],
imports: [FormsModule, ReactiveFormsModule, HttpClientModule, RouterModule.forRoot([])]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(DeleteScenarioComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { HttpClientModule } from '@angular/common/http';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { DataTableModule } from '@rushvora/ng-datatable';
import { HttpRequestInterceptorMock } from 'src/app/_interceptors/mock-interceptior';
import { AddNewExternalNotificationComponent } from './add-new-external-notification/add-new-external-notification.component';
import { DeleteExternalNotificationComponent } from './delete-external-notification/delete-external-notification.component';

Expand All @@ -17,7 +19,12 @@ describe('ExternalNotificationComponent', () => {
declarations: [ExternalNotificationComponent,
AddNewExternalNotificationComponent,
DeleteExternalNotificationComponent],
imports: [RouterTestingModule, ReactiveFormsModule, HttpClientModule, DataTableModule],
imports: [RouterTestingModule, ReactiveFormsModule, HttpClientTestingModule, DataTableModule],
providers: [{
provide: HTTP_INTERCEPTORS,
useClass: HttpRequestInterceptorMock,
multi: true
}]

})
.compileComponents();
Expand All @@ -26,6 +33,7 @@ describe('ExternalNotificationComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(ExternalNotificationComponent);
component = fixture.componentInstance;
component.params = { projectName: 'test-project' };
fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpClientModule } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { HighchartsChartModule } from 'highcharts-angular';
Expand All @@ -15,7 +15,7 @@ describe('ScenarioTrendsComponent', () => {
imports: [
HighchartsChartModule,
NgbModule,
HttpClientModule,
HttpClientTestingModule,
]
})
.compileComponents();
Expand Down
Loading

0 comments on commit 0d40398

Please sign in to comment.