diff --git a/workspaces/cli-server/src/server.ts b/workspaces/cli-server/src/server.ts index 1c5b76497c..e3931445d7 100644 --- a/workspaces/cli-server/src/server.ts +++ b/workspaces/cli-server/src/server.ts @@ -165,6 +165,7 @@ class CliServer { '/api/testing', createProxyMiddleware({ changeOrigin: true, + followRedirects: true, target: this.config.cloudApiBaseUrl, pathRewrite(input, req) { return input.substring(req.baseUrl.length); diff --git a/workspaces/ui/src/components/testing/ReportSummary.js b/workspaces/ui/src/components/testing/ReportSummary.js index 31603378a7..4917c658b5 100644 --- a/workspaces/ui/src/components/testing/ReportSummary.js +++ b/workspaces/ui/src/components/testing/ReportSummary.js @@ -103,7 +103,7 @@ export default function ReportSummary(props) {

from capturing interactions for build {summary.buildId}{' '} @@ -248,14 +248,18 @@ export default function ReportSummary(props) { } ReportSummary.displayName = 'Testing/ReportSummary'; -function SummaryStats({ totalInteractions, totalDiffs, totalUnmatchedPaths }) { +function SummaryStats({ + totalInteractions, + totalDiffs, + totalUndocumentedEndpoints, +}) { const classes = useStyles(); return ( Optic observed , yielding in and{' '} - . + . ); } diff --git a/workspaces/ui/src/services/testing/TestingService.ts b/workspaces/ui/src/services/testing/TestingService.ts index 698fcc73a5..4efebc76a8 100644 --- a/workspaces/ui/src/services/testing/TestingService.ts +++ b/workspaces/ui/src/services/testing/TestingService.ts @@ -1,8 +1,20 @@ -import { ITestingService, Result, Capture, ok } from '.'; +import { + ITestingService, + Capture, + CoverageReport, + Result, + ok, + err, + NotFoundError, + RfcEventStream, + UndocumentedEndpoint, +} from '.'; import UrlJoin from 'url-join'; +import { StableHasher } from '../../utilities/CoverageUtilities'; +import { opticEngine } from '@useoptic/domain'; // TODO: implement ITestingService -export class TestingService { +export class TestingService implements ITestingService { private authToken: string; private refreshing?: Promise; @@ -29,6 +41,7 @@ export class TestingService { headers.set('Authorization', `Bearer ${this.authToken}`); const response = await fetch(url, { + ...options, headers, }); @@ -74,4 +87,83 @@ export class TestingService { return ok(payload.captures); } + + async loadCapture(captureId): Promise> { + const response = await this.callApi(`/captures/${captureId}`); + + if (!response.ok) { + if (response.status === 404) { + return err(new NotFoundError()); + } else { + throw new Error('Capture could not be fetched'); + } + } + + const payload = await response.json(); + + return ok(payload); + } + + async loadReport(captureId): Promise> { + const response = await this.callApi( + `/captures/${captureId}/reports/coverage` + ); + + if (!response.ok) { + if (response.status === 404) { + return err(new NotFoundError()); + } else { + throw new Error('CoverageReport for capture could not be fetched'); + } + } + + const payload = await response.json(); + const deserialized = opticEngine.CoverageReportJsonDeserializer.fromJs( + payload + ); + const converter = new opticEngine.com.useoptic.CoverageReportConverter( + StableHasher + ); + const serializedReport = converter.toJs(deserialized); + return ok(serializedReport); + } + + async loadUndocumentedEndpoints( + captureId + ): Promise> { + const response = await this.callApi( + `/captures/${captureId}/reports/undocumented-urls` + ); + + if (!response.ok) { + if (response.status === 404) { + return err(new NotFoundError()); + } else { + throw new Error( + 'Undocumented endpoints for capture could not be fetched' + ); + } + } + + const payload = await response.json(); + return ok(payload); + } + + async loadSpecEvents( + captureId + ): Promise> { + const response = await this.callApi(`/captures/${captureId}/spec`); + + if (!response.ok) { + if (response.status === 404) { + return err(new NotFoundError()); + } else { + throw new Error('Spec for capture could not be fetched'); + } + } + + const payload = await response.json(); + + return ok(payload); + } } diff --git a/workspaces/ui/src/services/testing/index.ts b/workspaces/ui/src/services/testing/index.ts index b520a12410..c6f709dda1 100644 --- a/workspaces/ui/src/services/testing/index.ts +++ b/workspaces/ui/src/services/testing/index.ts @@ -9,7 +9,7 @@ export interface ITestingService { captureId: CaptureId ): Promise>; - loadEndpointDiffs( + loadEndpointDiffs?( captureId: CaptureId, pathId: PathId, httpMethod: HttpMethod