diff --git a/src/app/_interceptors/mock-interceptior.ts b/src/app/_interceptors/mock-interceptior.ts new file mode 100644 index 00000000..f3e81356 --- /dev/null +++ b/src/app/_interceptors/mock-interceptior.ts @@ -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, next: HttpHandler): + Observable> { + 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); + } +} diff --git a/src/app/administration/api-token/api-keys.component.spec.ts b/src/app/administration/api-token/api-keys.component.spec.ts index 98c760e5..47252b9d 100644 --- a/src/app/administration/api-token/api-keys.component.spec.ts +++ b/src/app/administration/api-token/api-keys.component.spec.ts @@ -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; 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(); })); diff --git a/src/app/administration/users/users.component.spec.ts b/src/app/administration/users/users.component.spec.ts index e604d745..42894fdd 100644 --- a/src/app/administration/users/users.component.spec.ts +++ b/src/app/administration/users/users.component.spec.ts @@ -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; 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(); })); diff --git a/src/app/item-detail/analyze-charts/analyze-charts.component.spec.ts b/src/app/item-detail/analyze-charts/analyze-charts.component.spec.ts index 3fd6e14f..74dcd7d8 100644 --- a/src/app/item-detail/analyze-charts/analyze-charts.component.spec.ts +++ b/src/app/item-detail/analyze-charts/analyze-charts.component.spec.ts @@ -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'; @@ -19,7 +20,12 @@ describe('AnalyzeChartsComponent', () => { NgbModule, FormsModule, HttpClientModule - ] + ], + providers: [{ + provide: HTTP_INTERCEPTORS, + useClass: HttpRequestInterceptorMock, + multi: true + }] }) .compileComponents(); })); @@ -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(); }); diff --git a/src/app/item-detail/share/share.component.spec.ts b/src/app/item-detail/share/share.component.spec.ts index e55f5d11..1fc37c51 100644 --- a/src/app/item-detail/share/share.component.spec.ts +++ b/src/app/item-detail/share/share.component.spec.ts @@ -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'; @@ -20,9 +22,14 @@ describe('ShareComponent', () => { imports: [ ReactiveFormsModule, FormsModule, - HttpClientModule, + HttpClientTestingModule, DataTableModule - ] + ], + providers: [{ + provide: HTTP_INTERCEPTORS, + useClass: HttpRequestInterceptorMock, + multi: true + }] }) .compileComponents(); })); @@ -30,7 +37,7 @@ describe('ShareComponent', () => { 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(); }); diff --git a/src/app/items-api.service.pact.spec.ts b/src/app/items-api.service.pact.spec.ts new file mode 100644 index 00000000..ad36a42a --- /dev/null +++ b/src/app/items-api.service.pact.spec.ts @@ -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(); + }); + }); + }); +}); diff --git a/src/app/scenario-api.service.pact.spec.ts b/src/app/scenario-api.service.pact.spec.ts index aebec95b..3c2d57cf 100644 --- a/src/app/scenario-api.service.pact.spec.ts +++ b/src/app/scenario-api.service.pact.spec.ts @@ -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(); + }); + }); + }); }); }); diff --git a/src/app/scenario/delete-scenario/delete-scenario.component.spec.ts b/src/app/scenario/delete-scenario/delete-scenario.component.spec.ts new file mode 100644 index 00000000..3c8da356 --- /dev/null +++ b/src/app/scenario/delete-scenario/delete-scenario.component.spec.ts @@ -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; + + 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(); + }); +}); diff --git a/src/app/scenario/external-notification/external-notification.component.spec.ts b/src/app/scenario/external-notification/external-notification.component.spec.ts index 7210b00a..f46373f7 100644 --- a/src/app/scenario/external-notification/external-notification.component.spec.ts +++ b/src/app/scenario/external-notification/external-notification.component.spec.ts @@ -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'; @@ -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(); @@ -26,6 +33,7 @@ describe('ExternalNotificationComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(ExternalNotificationComponent); component = fixture.componentInstance; + component.params = { projectName: 'test-project' }; fixture.detectChanges(); }); diff --git a/src/app/scenario/scenario-trends/scenario-trends.component.spec.ts b/src/app/scenario/scenario-trends/scenario-trends.component.spec.ts index 1fe5bfa2..f74950bd 100644 --- a/src/app/scenario/scenario-trends/scenario-trends.component.spec.ts +++ b/src/app/scenario/scenario-trends/scenario-trends.component.spec.ts @@ -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'; @@ -15,7 +15,7 @@ describe('ScenarioTrendsComponent', () => { imports: [ HighchartsChartModule, NgbModule, - HttpClientModule, + HttpClientTestingModule, ] }) .compileComponents(); diff --git a/src/app/scenario/scenario.component.spec.ts b/src/app/scenario/scenario.component.spec.ts index de56b87f..1d05de2d 100644 --- a/src/app/scenario/scenario.component.spec.ts +++ b/src/app/scenario/scenario.component.spec.ts @@ -11,10 +11,12 @@ import { NgxSpinnerModule } from 'ngx-spinner'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { RouterTestingModule } from '@angular/router/testing'; import { ReactiveFormsModule, FormsModule } from '@angular/forms'; -import { HttpClientModule } from '@angular/common/http'; +import { HTTP_INTERCEPTORS } from '@angular/common/http'; import { DataTableModule } from '@rushvora/ng-datatable'; import { ExternalNotificationComponent } from './external-notification/external-notification.component'; import { ScenarioTrendsComponent } from './scenario-trends/scenario-trends.component'; +import { HttpRequestInterceptorMock } from '../_interceptors/mock-interceptior'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; describe('ScenarioComponent', () => { let component: ScenarioComponent; @@ -40,8 +42,13 @@ describe('ScenarioComponent', () => { RouterTestingModule, ReactiveFormsModule, FormsModule, - HttpClientModule - ] + HttpClientTestingModule + ], + providers: [{ + provide: HTTP_INTERCEPTORS, + useClass: HttpRequestInterceptorMock, + multi: true + }] }) .compileComponents(); }));