[Synthetics] Update edit page error handling (#157963)

This commit is contained in:
Shahzad 2023-05-24 12:45:00 +02:00 committed by GitHub
parent bdc4399e01
commit 509d8940c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 136 additions and 150 deletions

View file

@ -40,6 +40,7 @@ export enum API_URLS {
INDEX_TEMPLATES = '/internal/uptime/service/index_templates',
SERVICE_LOCATIONS = '/internal/uptime/service/locations',
SYNTHETICS_MONITORS = '/internal/uptime/service/monitors',
GET_SYNTHETICS_MONITOR = '/internal/uptime/service/monitor/{monitorId}',
SYNTHETICS_ENABLEMENT = '/internal/uptime/service/enablement',
RUN_ONCE_MONITOR = '/internal/uptime/service/monitors/run_once',
TRIGGER_MONITOR = '/internal/uptime/service/monitors/trigger',

View file

@ -6,16 +6,18 @@
*/
import { after, before, expect, journey, step } from '@elastic/synthetics';
import { SyntheticsServices } from './services/synthetics_services';
import { recordVideo } from '../../helpers/record_video';
import { cleanTestMonitors, enableMonitorManagedViaApi } from './services/add_monitor';
import { getMonitor } from './services/get_monitor';
import { addTestMonitorProject } from './services/add_monitor_project';
import { syntheticsAppPageProvider } from '../../page_objects/synthetics/synthetics_app';
import { SyntheticsMonitor } from '../../../common/runtime_types';
journey('Project Monitor Read-only', async ({ page, params }) => {
journey('ProjectMonitorReadOnly', async ({ page, params }) => {
recordVideo(page);
const services = new SyntheticsServices(params);
const syntheticsApp = syntheticsAppPageProvider({ page, kibanaUrl: params.kibanaUrl });
let originalMonitorConfiguration: SyntheticsMonitor | null;
@ -52,12 +54,13 @@ journey('Project Monitor Read-only', async ({ page, params }) => {
step('Confirm configuration is read-only', async () => {
await page.waitForSelector('text=read-only');
monitorId = new URL(await page.url()).pathname.split('/').at(-1) || '';
originalMonitorConfiguration = await getMonitor(params.kibanaUrl, monitorId);
originalMonitorConfiguration = await services.getMonitor(monitorId);
expect(originalMonitorConfiguration).not.toBeNull();
});
step('Monitor configuration is unchanged when saved', async () => {
await syntheticsApp.confirmAndSave(true);
const newConfiguration = await getMonitor(params.kibanaUrl, monitorId);
const newConfiguration = await services.getMonitor(monitorId);
// hash is always reset to empty string when monitor is edited
// this ensures that when the monitor is pushed again, the monitor
@ -74,7 +77,7 @@ journey('Project Monitor Read-only', async ({ page, params }) => {
await page.click('[data-test-subj="syntheticsAlertStatusSwitch"]');
await syntheticsApp.confirmAndSave(true);
const newConfiguration = await getMonitor(params.kibanaUrl, monitorId);
const newConfiguration = await services.getMonitor(monitorId);
// hash is always reset to empty string when monitor is edited
// this ensures that when the monitor is pushed again, the monitor
@ -94,7 +97,7 @@ journey('Project Monitor Read-only', async ({ page, params }) => {
step('Monitor can be repushed and overwrite any changes', async () => {
await addTestMonitorProject(params.kibanaUrl, monitorName);
const repushedConfiguration = await getMonitor(params.kibanaUrl, monitorId);
const repushedConfiguration = await services.getMonitor(monitorId);
expect(repushedConfiguration).toEqual({
...originalMonitorConfiguration,
revision: 4,

View file

@ -1,26 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import axios from 'axios';
import { SyntheticsMonitor } from '../../../../common/runtime_types';
export const getMonitor = async (
kibanaUrl: string,
monitorId: string
): Promise<SyntheticsMonitor | null> => {
try {
const response = await axios.get(kibanaUrl + `/internal/uptime/service/monitors/${monitorId}`, {
auth: { username: 'elastic', password: 'changeme' },
headers: { 'kbn-xsrf': 'true' },
});
return response.data.attributes;
} catch (e) {
// eslint-disable-next-line no-console
console.log(e);
return null;
}
};

View file

@ -9,7 +9,8 @@ import axios from 'axios';
import type { Client } from '@elastic/elasticsearch';
import { KbnClient, uriencode } from '@kbn/test';
import pMap from 'p-map';
import { SYNTHETICS_API_URLS } from '../../../../common/constants';
import { SyntheticsMonitor } from '../../../../common/runtime_types';
import { API_URLS, SYNTHETICS_API_URLS } from '../../../../common/constants';
import { journeyStart, journeySummary, step1, step2 } from './data/browser_docs';
import { firstDownHit, getUpHit } from './data/sample_docs';
@ -23,6 +24,24 @@ export class SyntheticsServices {
this.params = params;
}
async getMonitor(monitorId: string): Promise<SyntheticsMonitor | null> {
try {
const { data } = await this.requester.request<{ attributes: SyntheticsMonitor }>({
description: 'get monitor by id',
path: API_URLS.GET_SYNTHETICS_MONITOR.replace('{monitorId}', monitorId),
query: {
decrypted: true,
},
method: 'GET',
});
return data?.attributes;
} catch (e) {
// eslint-disable-next-line no-console
console.log(e);
return null;
}
}
async enableMonitorManagedViaApi() {
try {
await axios.post(this.kibanaUrl + '/internal/uptime/service/enablement', undefined, {

View file

@ -23,7 +23,7 @@ import { MonitorForm } from './form';
import { LocationsLoadingError } from './locations_loading_error';
import { MonitorDetailsLinkPortal } from './monitor_details_portal';
import { useMonitorAddEditBreadcrumbs } from './use_breadcrumbs';
import { getMonitorAPI } from '../../state/monitor_management/api';
import { getDecryptedMonitorAPI } from '../../state/monitor_management/api';
import { EDIT_MONITOR_STEPS } from './steps/step_config';
import { useMonitorNotFound } from './hooks/use_monitor_not_found';
@ -42,7 +42,7 @@ export const MonitorEditPage: React.FC = () => {
}, [locationsLoaded, dispatch]);
const { data, loading, error } = useFetcher(() => {
return getMonitorAPI({ id: monitorId });
return getDecryptedMonitorAPI({ id: monitorId });
}, []);
const monitorNotFoundError = useMonitorNotFound(

View file

@ -115,17 +115,13 @@ describe('Monitor Detail Flyout', () => {
jest.spyOn(observabilitySharedPublic, 'useFetcher').mockReturnValue({
status: observabilitySharedPublic.FETCH_STATUS.SUCCESS,
data: {
attributes: {
enabled: true,
name: 'test-monitor',
schedule: {
number: '1',
unit: 'm',
},
tags: ['prod'],
enabled: true,
name: 'test-monitor',
schedule: {
number: '1',
unit: 'm',
},
type: 'browser',
updated_at: '1996-02-27',
tags: ['prod'],
},
refetch: jest.fn(),
});

View file

@ -25,17 +25,11 @@ import {
EuiTitle,
useIsWithinMaxBreakpoint,
} from '@elastic/eui';
import { SavedObject } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
useTheme,
FetcherResult,
FETCH_STATUS,
useFetcher,
} from '@kbn/observability-shared-plugin/public';
import { useTheme, FETCH_STATUS, useFetcher } from '@kbn/observability-shared-plugin/public';
import { MonitorDetailsPanel } from '../../../common/components/monitor_details_panel';
import { ClientPluginsStart } from '../../../../../../plugin';
import { LocationsStatus, useStatusByLocation } from '../../../../hooks/use_status_by_location';
@ -48,16 +42,11 @@ import {
setFlyoutConfig,
} from '../../../../state';
import { useMonitorDetail } from '../../../../hooks/use_monitor_detail';
import {
ConfigKey,
EncryptedSyntheticsMonitor,
MonitorOverviewItem,
SyntheticsMonitor,
} from '../types';
import { ConfigKey, EncryptedSyntheticsMonitor, MonitorOverviewItem } from '../types';
import { useMonitorDetailLocator } from '../../../../hooks/use_monitor_detail_locator';
import { fetchSyntheticsMonitor } from '../../../../state/overview/api';
import { MonitorStatus } from '../../../common/components/monitor_status';
import { MonitorLocationSelect } from '../../../common/components/monitor_location_select';
import { fetchSyntheticsMonitor } from '../../../../state/monitor_details/api';
interface Props {
configId: string;
@ -266,17 +255,14 @@ export function MonitorDetailFlyout(props: Props) {
error,
status,
loading,
}: FetcherResult<SavedObject<SyntheticsMonitor>> = useFetcher(
() => fetchSyntheticsMonitor(configId),
[configId, upsertSuccess]
);
} = useFetcher(() => fetchSyntheticsMonitor({ monitorId: configId }), [configId, upsertSuccess]);
const [isActionsPopoverOpen, setIsActionsPopoverOpen] = useState(false);
const monitorDetail = useMonitorDetail(configId, props.location);
const { locations } = useStatusByLocation({
configId,
monitorLocations: monitorSavedObject?.attributes.locations,
monitorLocations: monitorSavedObject?.locations,
});
const isOverlay = useIsWithinMaxBreakpoint('xl');
@ -297,7 +283,7 @@ export function MonitorDetailFlyout(props: Props) {
<EuiFlexGroup responsive={false} gutterSize="s">
<EuiFlexItem grow={false}>
<EuiTitle size="s">
<h2>{monitorSavedObject?.attributes[ConfigKey.NAME]}</h2>
<h2>{monitorSavedObject?.[ConfigKey.NAME]}</h2>
</EuiTitle>
</EuiFlexItem>
<EuiFlexItem grow={false}>
@ -321,7 +307,7 @@ export function MonitorDetailFlyout(props: Props) {
locations={locations}
setCurrentLocation={setLocation}
configId={configId}
monitor={monitorSavedObject.attributes}
monitor={monitorSavedObject}
onEnabledChange={props.onEnabledChange}
/>
</EuiPanel>
@ -334,7 +320,7 @@ export function MonitorDetailFlyout(props: Props) {
latestPing={monitorDetail.data}
configId={configId}
monitor={{
...monitorSavedObject.attributes,
...monitorSavedObject,
id,
updated_at: monitorSavedObject.updated_at!,
created_at: monitorSavedObject.created_at!,

View file

@ -9,10 +9,10 @@ import { SavedObject } from '@kbn/core/types';
import moment from 'moment';
import { apiService } from '../../../../utils/api_service';
import {
EncryptedSyntheticsMonitor,
EncryptedSyntheticsSavedMonitor,
PingsResponse,
PingsResponseType,
SyntheticsMonitor,
} from '../../../../../common/runtime_types';
import { API_URLS, SYNTHETICS_API_URLS } from '../../../../../common/constants';
@ -65,8 +65,8 @@ export const fetchSyntheticsMonitor = async ({
monitorId: string;
}): Promise<EncryptedSyntheticsSavedMonitor> => {
const savedObject = (await apiService.get(
`${API_URLS.SYNTHETICS_MONITORS}/${monitorId}`
)) as SavedObject<SyntheticsMonitor>;
API_URLS.GET_SYNTHETICS_MONITOR.replace('{monitorId}', monitorId)
)) as SavedObject<EncryptedSyntheticsMonitor>;
return {
...savedObject.attributes,

View file

@ -33,12 +33,14 @@ export const updateMonitorAPI = async ({
return await apiService.put(`${API_URLS.SYNTHETICS_MONITORS}/${id}`, monitor);
};
export const getMonitorAPI = async ({
export const getDecryptedMonitorAPI = async ({
id,
}: {
id: string;
}): Promise<DecryptedSyntheticsMonitorSavedObject> => {
return await apiService.get(`${API_URLS.SYNTHETICS_MONITORS}/${id}`);
return await apiService.get(API_URLS.GET_SYNTHETICS_MONITOR.replace('{monitorId}', id), {
decrypted: true,
});
};
export const fetchServiceAPIKey = async (): Promise<{

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import { SavedObject } from '@kbn/core/types';
import { SYNTHETICS_API_URLS } from '../../../../../common/constants';
import {
MonitorOverviewResult,
@ -16,14 +15,6 @@ import {
} from '../../../../../common/runtime_types';
import { apiService } from '../../../../utils/api_service';
import { MonitorOverviewPageState } from './models';
import { SyntheticsMonitor } from '../../../../../common/runtime_types';
import { API_URLS } from '../../../../../common/constants';
export const fetchSyntheticsMonitor = async (
monitorId: string
): Promise<SavedObject<SyntheticsMonitor>> => {
return apiService.get(`${API_URLS.SYNTHETICS_MONITORS}/${monitorId}`);
};
function toMonitorOverviewQueryArgs(
pageState: MonitorOverviewPageState

View file

@ -29,26 +29,45 @@ import {
export const getSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'GET',
path: API_URLS.SYNTHETICS_MONITORS + '/{monitorId}',
path: API_URLS.GET_SYNTHETICS_MONITOR,
validate: {
params: schema.object({
monitorId: schema.string({ minLength: 1, maxLength: 1024 }),
}),
query: schema.object({
decrypted: schema.maybe(schema.boolean()),
}),
},
handler: async ({
request,
response,
server: { encryptedSavedObjects },
server: { encryptedSavedObjects, coreStart },
savedObjectsClient,
}): Promise<any> => {
const { monitorId } = request.params;
const encryptedSavedObjectsClient = encryptedSavedObjects.getClient();
try {
return await libs.requests.getSyntheticsMonitor({
monitorId,
encryptedSavedObjectsClient,
savedObjectsClient,
});
const { decrypted } = request.query;
if (!decrypted) {
return await savedObjectsClient.get<EncryptedSyntheticsMonitor>(
syntheticsMonitorType,
monitorId
);
} else {
// only user with write permissions can decrypt the monitor
const canSave =
(await coreStart?.capabilities.resolveCapabilities(request)).uptime.save ?? false;
if (!canSave) {
return response.forbidden();
}
const encryptedSavedObjectsClient = encryptedSavedObjects.getClient();
return await libs.requests.getSyntheticsMonitor({
monitorId,
encryptedSavedObjectsClient,
savedObjectsClient,
});
}
} catch (getErr) {
if (SavedObjectsErrorHelpers.isNotFoundError(getErr)) {
return getMonitorNotFoundResponse(response, monitorId);

View file

@ -180,7 +180,7 @@ export default function ({ getService }: FtrProviderContext) {
.expect(200);
const response = await supertestAPI
.get(`${API_URLS.SYNTHETICS_MONITORS}/${apiResponse.body.id}`)
.get(API_URLS.GET_SYNTHETICS_MONITOR.replace('{monitorId}', apiResponse.body.id))
.set('kbn-xsrf', 'true')
.expect(200);

View file

@ -24,6 +24,7 @@ import {
getTestProjectSyntheticsPolicy,
getTestProjectSyntheticsPolicyLightweight,
} from './sample_data/test_project_monitor_policy';
import { SyntheticsMonitorTestService } from './services/synthetics_monitor_test_service';
export default function ({ getService }: FtrProviderContext) {
describe('AddProjectMonitors', function () {
@ -33,6 +34,8 @@ export default function ({ getService }: FtrProviderContext) {
const supertestWithoutAuth = getService('supertestWithoutAuth');
const security = getService('security');
const kibanaServer = getService('kibanaServer');
const monitorTestService = new SyntheticsMonitorTestService(getService);
const testPrivateLocations = new PrivateLocationTestService(getService);
let projectMonitors: ProjectMonitorsRequest;
let httpProjectMonitors: ProjectMonitorsRequest;
@ -40,7 +43,6 @@ export default function ({ getService }: FtrProviderContext) {
let icmpProjectMonitors: ProjectMonitorsRequest;
let testPolicyId = '';
const testPrivateLocations = new PrivateLocationTestService(getService);
const setUniqueIds = (request: ProjectMonitorsRequest) => {
return {
@ -149,10 +151,9 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'true')
.expect(200);
const decryptedCreatedMonitor = await supertest
.get(`${API_URLS.SYNTHETICS_MONITORS}/${createdMonitorsResponse.body.monitors[0].id}`)
.set('kbn-xsrf', 'true')
.expect(200);
const decryptedCreatedMonitor = await monitorTestService.getMonitor(
createdMonitorsResponse.body.monitors[0].id
);
expect(decryptedCreatedMonitor.body.attributes).to.eql({
__ui: {
@ -256,10 +257,9 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'true')
.expect(200);
const decryptedCreatedMonitor = await supertest
.get(`${API_URLS.SYNTHETICS_MONITORS}/${createdMonitorsResponse.body.monitors[0].id}`)
.set('kbn-xsrf', 'true')
.expect(200);
const decryptedCreatedMonitor = await monitorTestService.getMonitor(
createdMonitorsResponse.body.monitors[0].id
);
expect(decryptedCreatedMonitor.body.attributes.throttling).to.eql({
value: null,
@ -314,10 +314,9 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'true')
.expect(200);
const decryptedCreatedMonitor = await supertest
.get(`${API_URLS.SYNTHETICS_MONITORS}/${createdMonitorsResponse.body.monitors[0].id}`)
.set('kbn-xsrf', 'true')
.expect(200);
const decryptedCreatedMonitor = await monitorTestService.getMonitor(
createdMonitorsResponse.body.monitors[0].id
);
expect(decryptedCreatedMonitor.body.attributes).to.eql({
__ui: {
@ -445,10 +444,9 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'true')
.expect(200);
const decryptedCreatedMonitor = await supertest
.get(`${API_URLS.SYNTHETICS_MONITORS}/${createdMonitorsResponse.body.monitors[0].id}`)
.set('kbn-xsrf', 'true')
.expect(200);
const decryptedCreatedMonitor = await monitorTestService.getMonitor(
createdMonitorsResponse.body.monitors[0].id
);
expect(decryptedCreatedMonitor.body.attributes).to.eql({
__ui: {
@ -555,10 +553,9 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'true')
.expect(200);
const decryptedCreatedMonitor = await supertest
.get(`${API_URLS.SYNTHETICS_MONITORS}/${createdMonitorsResponse.body.monitors[0].id}`)
.set('kbn-xsrf', 'true')
.expect(200);
const decryptedCreatedMonitor = await monitorTestService.getMonitor(
createdMonitorsResponse.body.monitors[0].id
);
expect(decryptedCreatedMonitor.body.attributes).to.eql({
config_id: decryptedCreatedMonitor.body.id,
@ -1051,10 +1048,11 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'true')
.expect(200);
const decryptedCreatedMonitor = await supertest
.get(`/s/${SPACE_ID}${API_URLS.SYNTHETICS_MONITORS}/${getResponse.body.monitors[0].id}`)
.set('kbn-xsrf', 'true')
.expect(200);
const decryptedCreatedMonitor = await monitorTestService.getMonitor(
getResponse.body.monitors[0].id,
true,
SPACE_ID
);
const { monitors } = getResponse.body;
expect(monitors.length).eql(1);
expect(decryptedCreatedMonitor.body.attributes[ConfigKey.SOURCE_PROJECT_CONTENT]).eql(
@ -1088,10 +1086,11 @@ export default function ({ getService }: FtrProviderContext) {
const { monitors: monitorsUpdated } = getResponseUpdated.body;
expect(monitorsUpdated.length).eql(1);
const decryptedUpdatedMonitor = await supertest
.get(`/s/${SPACE_ID}${API_URLS.SYNTHETICS_MONITORS}/${monitorsUpdated[0].id}`)
.set('kbn-xsrf', 'true')
.expect(200);
const decryptedUpdatedMonitor = await monitorTestService.getMonitor(
monitorsUpdated[0].id,
true,
SPACE_ID
);
expect(decryptedUpdatedMonitor.body.attributes[ConfigKey.SOURCE_PROJECT_CONTENT]).eql(
updatedSource
);
@ -1204,10 +1203,7 @@ export default function ({ getService }: FtrProviderContext) {
});
// ensure that monitor can still be decrypted
await supertest
.get(API_URLS.SYNTHETICS_MONITORS + '/' + monitors[0]?.id)
.set('kbn-xsrf', 'true')
.expect(200);
await monitorTestService.getMonitor(monitors[0]?.id);
} finally {
await Promise.all([
projectMonitors.monitors.map((monitor) => {

View file

@ -11,6 +11,7 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
import { getFixtureJson } from '../uptime/rest/helper/get_fixture_json';
import { PrivateLocationTestService } from './services/private_location_test_service';
import { SyntheticsMonitorTestService } from './services/synthetics_monitor_test_service';
export default function ({ getService }: FtrProviderContext) {
describe('DeleteMonitorRoute', function () {
@ -22,6 +23,7 @@ export default function ({ getService }: FtrProviderContext) {
const kibanaServer = getService('kibanaServer');
const testPrivateLocations = new PrivateLocationTestService(getService);
const monitorTestService = new SyntheticsMonitorTestService(getService);
let _httpMonitorJson: HTTPFields;
let httpMonitorJson: HTTPFields;
@ -144,10 +146,7 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'true')
.expect(500);
const response = await supertest
.get(`${API_URLS.SYNTHETICS_MONITORS}/${monitorId}`)
.set('kbn-xsrf', 'true')
.expect(200);
const response = await monitorTestService.getMonitor(monitorId);
// ensure monitor was not deleted
expect(response.body.attributes.urls).eql(newMonitor.urls);

View file

@ -39,7 +39,6 @@ export default function ({ getService }: FtrProviderContext) {
before(async () => {
await testPrivateLocations.installSyntheticsPackage();
const testPolicyName = 'Fleet test server policy' + Date.now();
const apiResponse = await testPrivateLocations.addFleetPolicy(testPolicyName);
testPolicyId = apiResponse.body.item.id;

View file

@ -14,6 +14,7 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
import { getFixtureJson } from '../uptime/rest/helper/get_fixture_json';
import { PrivateLocationTestService } from './services/private_location_test_service';
import { SyntheticsMonitorTestService } from './services/synthetics_monitor_test_service';
export default function ({ getService }: FtrProviderContext) {
describe('EditMonitor', function () {
@ -25,6 +26,7 @@ export default function ({ getService }: FtrProviderContext) {
const kibanaServer = getService('kibanaServer');
const testPrivateLocations = new PrivateLocationTestService(getService);
const monitorTestService = new SyntheticsMonitorTestService(getService);
let _httpMonitorJson: HTTPFields;
let httpMonitorJson: HTTPFields;
@ -352,10 +354,7 @@ export default function ({ getService }: FtrProviderContext) {
.send(toUpdate)
.expect(500);
const response = await supertest
.get(`${API_URLS.SYNTHETICS_MONITORS}/${monitorId}`)
.set('kbn-xsrf', 'true')
.expect(200);
const response = await monitorTestService.getMonitor(monitorId);
// ensure monitor was not updated
expect(response.body.attributes.urls).eql(newMonitor.urls);
@ -410,10 +409,7 @@ export default function ({ getService }: FtrProviderContext) {
.send(toUpdate)
.expect(200);
const updatedResponse = await supertest
.get(`/s/${SPACE_ID}${API_URLS.SYNTHETICS_MONITORS}/${monitorId}`)
.set('kbn-xsrf', 'true')
.expect(200);
const updatedResponse = await monitorTestService.getMonitor(monitorId, true, SPACE_ID);
// ensure monitor was updated
expect(updatedResponse.body.attributes.urls).eql(toUpdate.urls);
@ -430,10 +426,7 @@ export default function ({ getService }: FtrProviderContext) {
.send(toUpdate2)
.expect(200);
const updatedResponse2 = await supertest
.get(`/s/${SPACE_ID}${API_URLS.SYNTHETICS_MONITORS}/${monitorId}`)
.set('kbn-xsrf', 'true')
.expect(200);
const updatedResponse2 = await monitorTestService.getMonitor(monitorId, true, SPACE_ID);
// ensure monitor was updated
expect(updatedResponse2.body.attributes.urls).eql(toUpdate2.urls);

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { SimpleSavedObject } from '@kbn/core/public';
import { SavedObject } from '@kbn/core/server';
import { ConfigKey, MonitorFields } from '@kbn/synthetics-plugin/common/runtime_types';
import { API_URLS } from '@kbn/synthetics-plugin/common/constants';
import expect from '@kbn/expect';
@ -28,7 +28,7 @@ export default function ({ getService }: FtrProviderContext) {
.send(monitor)
.expect(200);
return res.body as SimpleSavedObject<MonitorFields>;
return res.body as SavedObject<MonitorFields>;
};
before(async () => {
@ -56,13 +56,11 @@ export default function ({ getService }: FtrProviderContext) {
.get(API_URLS.SYNTHETICS_MONITORS + '?perPage=1000') // 1000 to sort of load all saved monitors
.expect(200);
const found: Array<SimpleSavedObject<MonitorFields>> = apiResponse.body.monitors.filter(
({ id }: SimpleSavedObject<MonitorFields>) => [id1, id2].includes(id)
const found: Array<SavedObject<MonitorFields>> = apiResponse.body.monitors.filter(
({ id }: SavedObject<MonitorFields>) => [id1, id2].includes(id)
);
found.sort(({ id: a }) => (a === id2 ? 1 : a === id1 ? -1 : 0));
const foundMonitors = found.map(
({ attributes }: SimpleSavedObject<MonitorFields>) => attributes
);
const foundMonitors = found.map(({ attributes }: SavedObject<MonitorFields>) => attributes);
const expected = [mon1, mon2];
@ -92,7 +90,7 @@ export default function ({ getService }: FtrProviderContext) {
const [{ id: id1 }] = await Promise.all(monitors.map(saveMonitor));
const apiResponse = await supertest
.get(API_URLS.SYNTHETICS_MONITORS + '/' + id1)
.get(API_URLS.GET_SYNTHETICS_MONITOR.replace('{monitorId}', id1) + '?decrypted=true')
.expect(200);
expect(apiResponse.body.attributes).eql({
@ -108,7 +106,7 @@ export default function ({ getService }: FtrProviderContext) {
const expected404Message = `Monitor id ${invalidMonitorId} not found!`;
const getResponse = await supertest
.get(API_URLS.SYNTHETICS_MONITORS + '/' + invalidMonitorId)
.get(API_URLS.GET_SYNTHETICS_MONITOR.replace('{monitorId}', invalidMonitorId))
.set('kbn-xsrf', 'true');
expect(getResponse.status).eql(404);
@ -119,7 +117,7 @@ export default function ({ getService }: FtrProviderContext) {
const veryLargeMonId = new Array(1050).fill('1').join('');
await supertest
.get(API_URLS.SYNTHETICS_MONITORS + '/' + veryLargeMonId)
.get(API_URLS.GET_SYNTHETICS_MONITOR.replace('{monitorId}', veryLargeMonId))
.set('kbn-xsrf', 'true')
.expect(400);
});

View file

@ -17,6 +17,16 @@ export class SyntheticsMonitorTestService {
this.supertest = getService('supertest');
}
async getMonitor(monitorId: string, decrypted: boolean = true, space?: string) {
let url =
API_URLS.GET_SYNTHETICS_MONITOR.replace('{monitorId}', monitorId) +
(decrypted ? '?decrypted=true' : '');
if (space) {
url = '/s/' + space + url;
}
return this.supertest.get(url).set('kbn-xsrf', 'true').expect(200);
}
async addProjectMonitors(project: string, monitors: any) {
const { body } = await this.supertest
.put(API_URLS.SYNTHETICS_MONITORS_PROJECT_UPDATE.replace('{projectName}', project))