address comments

This commit is contained in:
Samira Mokaram
2020-12-01 16:38:40 +01:00
parent 04a53de52f
commit 3d392a0b6a
9 changed files with 30 additions and 28 deletions
+12 -2
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { createApiRef } from '@backstage/core';
import { createApiRef, DiscoveryApi, ConfigApi } from '@backstage/core';
import { Service, Incident, OnCall } from '../components/types';
import {
PagerDutyApi,
@@ -34,6 +34,15 @@ export const pagerDutyApiRef = createApiRef<PagerDutyApi>({
});
export class PagerDutyClient implements PagerDutyApi {
static fromConfig(configApi: ConfigApi, discoveryApi: DiscoveryApi) {
const eventsBaseUrl: string =
configApi.getOptionalString('pagerDuty.eventsBaseUrl') ??
'https://events.pagerduty.com/v2';
return new PagerDutyClient({
eventsBaseUrl,
discoveryApi,
});
}
constructor(private readonly config: ClientApiConfig) {}
async getServiceByIntegrationKey(integrationKey: string): Promise<Service[]> {
@@ -98,7 +107,8 @@ export class PagerDutyClient implements PagerDutyApi {
};
return this.request(
`${this.config.eventsUrl ?? 'https://events.pagerduty.com/v2'}/enqueue`,
`${this.config.eventsBaseUrl ??
'https://events.pagerduty.com/v2'}/enqueue`,
options,
);
}
+1 -1
View File
@@ -62,7 +62,7 @@ export type OnCallsResponse = {
};
export type ClientApiConfig = {
eventsUrl?: string;
eventsBaseUrl?: string;
discoveryApi: DiscoveryApi;
};
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import React from 'react';
import { render, waitFor, fireEvent } from '@testing-library/react';
import { render, waitFor, fireEvent, act } from '@testing-library/react';
import { PagerDutyCard } from './PagerDutyCard';
import { Entity } from '@backstage/catalog-model';
import { wrapInTestApp } from '@backstage/test-utils';
@@ -26,7 +26,6 @@ import {
} from '@backstage/core';
import { pagerDutyApiRef, UnauthorizedError, PagerDutyClient } from '../api';
import { Service } from './types';
import { act } from 'react-dom/test-utils';
const mockPagerDutyApi: Partial<PagerDutyClient> = {
getServiceByIntegrationKey: async () => [],
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import { render, fireEvent, act } from '@testing-library/react';
import { wrapInTestApp } from '@backstage/test-utils';
import {
ApiRegistry,
@@ -26,7 +26,6 @@ import {
} from '@backstage/core';
import { pagerDutyApiRef } from '../../api';
import { Entity } from '@backstage/catalog-model';
import { act } from 'react-dom/test-utils';
import { TriggerDialog } from './TriggerDialog';
describe('TriggerDialog', () => {
+4 -5
View File
@@ -18,6 +18,7 @@ import {
createPlugin,
createRouteRef,
discoveryApiRef,
configApiRef,
} from '@backstage/core';
import { pagerDutyApiRef, PagerDutyClient } from './api';
@@ -31,11 +32,9 @@ export const plugin = createPlugin({
apis: [
createApiFactory({
api: pagerDutyApiRef,
deps: { discoveryApi: discoveryApiRef },
factory: ({ discoveryApi }) =>
new PagerDutyClient({
discoveryApi: discoveryApi,
}),
deps: { discoveryApi: discoveryApiRef, configApi: configApiRef },
factory: ({ configApi, discoveryApi }) =>
PagerDutyClient.fromConfig(configApi, discoveryApi),
}),
],
});