Skip to content

Commit

Permalink
Fix/improve broken types/unit/integration/api tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkambic committed Apr 21, 2020
1 parent 674857e commit 7d2bf4c
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 61 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ export const CertificateExpirationForm: React.FC<SettingsFormProps> = ({
<EuiFlexGroup>
<EuiFlexItem grow={2}>
<EuiFieldNumber
data-test-subj={`error-state-threshold-input-${dss.loading ? 'loading' : 'loaded'}`}
data-test-subj={`expiration-threshold-input-${dss.loading ? 'loading' : 'loaded'}`}
fullWidth
disabled={isDisabled}
isLoading={dss.loading}
value={formFields?.certificatesThresholds?.expiration || ''}
onChange={({ currentTarget: { value } }: any) =>
onChange({
certificatesThresholds: {
expiration: value === '' ? undefined : Number(value),
expiration: Number(value),
},
})
}
Expand Down Expand Up @@ -137,9 +137,7 @@ export const CertificateExpirationForm: React.FC<SettingsFormProps> = ({
<EuiFlexGroup>
<EuiFlexItem grow={2}>
<EuiFieldNumber
data-test-subj={`warning-state-threshold-input-${
dss.loading ? 'loading' : 'loaded'
}`}
data-test-subj={`age-threshold-input-${dss.loading ? 'loading' : 'loaded'}`}
fullWidth
disabled={isDisabled}
isLoading={dss.loading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { getBasePath, isIntegrationsPopupOpen } from '../index';
import { AppState } from '../../../state';
import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../../common/constants';

describe('state selectors', () => {
const state: AppState = {
Expand All @@ -20,6 +21,7 @@ describe('state selectors', () => {
loading: false,
},
dynamicSettings: {
settings: DYNAMIC_SETTINGS_DEFAULTS,
loading: false,
},
monitor: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { AlertType } from '../../../../../alerting/server';
import { IRouter } from 'kibana/server';
import { UMServerLibs } from '../../lib';
import { UptimeCoreSetup } from '../../adapters';
import { defaultDynamicSettings } from '../../../../../../legacy/plugins/uptime/common/runtime_types';
import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../../../../legacy/plugins/uptime/common/constants';
import { alertsMock, AlertServicesMock } from '../../../../../alerting/server/mocks';

/**
Expand Down Expand Up @@ -52,7 +52,7 @@ const mockOptions = (
id: '',
type: '',
references: [],
attributes: defaultDynamicSettings,
attributes: DYNAMIC_SETTINGS_DEFAULTS,
});
return {
params,
Expand Down Expand Up @@ -89,8 +89,8 @@ describe('status check alert', () => {
"callES": [MockFunction],
"dynamicSettings": Object {
"certificatesThresholds": Object {
"errorState": 7,
"warningState": 30,
"age": 365,
"expiration": 7,
},
"heartbeatIndices": "heartbeat-8*",
},
Expand Down Expand Up @@ -136,8 +136,8 @@ describe('status check alert', () => {
"callES": [MockFunction],
"dynamicSettings": Object {
"certificatesThresholds": Object {
"errorState": 7,
"warningState": 30,
"age": 365,
"expiration": 7,
},
"heartbeatIndices": "heartbeat-8*",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/

import { getLatestMonitor } from '../get_latest_monitor';
import { defaultDynamicSettings } from '../../../../../../legacy/plugins/uptime/common/runtime_types';
import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../../../../legacy/plugins/uptime/common/constants';

describe('getLatestMonitor', () => {
let expectedGetLatestSearchParams: any;
let mockEsSearchResult: any;
beforeEach(() => {
expectedGetLatestSearchParams = {
index: defaultDynamicSettings.heartbeatIndices,
index: DYNAMIC_SETTINGS_DEFAULTS.heartbeatIndices,
body: {
query: {
bool: {
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('getLatestMonitor', () => {
const mockEsClient = jest.fn(async (_request: any, _params: any) => mockEsSearchResult);
const result = await getLatestMonitor({
callES: mockEsClient,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
dateStart: 'now-1h',
dateEnd: 'now',
monitorId: 'testMonitor',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { set } from 'lodash';
import mockChartsData from './monitor_charts_mock.json';
import { getMonitorDurationChart } from '../get_monitor_duration';
import { defaultDynamicSettings } from '../../../../../../legacy/plugins/uptime/common/runtime_types';
import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../../../../legacy/plugins/uptime/common/constants';

describe('ElasticsearchMonitorsAdapter', () => {
it('getMonitorChartsData will provide expected filters', async () => {
Expand All @@ -16,7 +16,7 @@ describe('ElasticsearchMonitorsAdapter', () => {
const search = searchMock.bind({});
await getMonitorDurationChart({
callES: search,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
monitorId: 'fooID',
dateStart: 'now-15m',
dateEnd: 'now',
Expand All @@ -39,7 +39,7 @@ describe('ElasticsearchMonitorsAdapter', () => {
expect(
await getMonitorDurationChart({
callES: search,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
monitorId: 'id',
dateStart: 'now-15m',
dateEnd: 'now',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { elasticsearchServiceMock } from '../../../../../../../src/core/server/mocks';
import { getMonitorStatus } from '../get_monitor_status';
import { ScopedClusterClient } from 'src/core/server/elasticsearch';
import { defaultDynamicSettings } from '../../../../../../legacy/plugins/uptime/common/runtime_types';
import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../../../../legacy/plugins/uptime/common/constants';

interface BucketItemCriteria {
monitor_id: string;
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('getMonitorStatus', () => {
}`;
await getMonitorStatus({
callES,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
filters: exampleFilter,
locations: [],
numTimes: 5,
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('getMonitorStatus', () => {
const [callES, esMock] = setupMock([]);
await getMonitorStatus({
callES,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
locations: ['fairbanks', 'harrisburg'],
numTimes: 1,
timerange: {
Expand Down Expand Up @@ -329,7 +329,7 @@ describe('getMonitorStatus', () => {
};
const result = await getMonitorStatus({
callES,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
...clientParameters,
});
expect(esMock.callAsCurrentUser).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -494,7 +494,7 @@ describe('getMonitorStatus', () => {
const [callES] = setupMock(criteria);
const result = await getMonitorStatus({
callES,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
locations: [],
numTimes: 5,
timerange: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { getPingHistogram } from '../get_ping_histogram';
import { defaultDynamicSettings } from '../../../../../../legacy/plugins/uptime/common/runtime_types';
import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../../../../legacy/plugins/uptime/common/constants';

describe('getPingHistogram', () => {
const standardMockResponse: any = {
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('getPingHistogram', () => {

const result = await getPingHistogram({
callES: mockEsClient,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
from: 'now-15m',
to: 'now',
filters: null,
Expand All @@ -78,7 +78,7 @@ describe('getPingHistogram', () => {

const result = await getPingHistogram({
callES: mockEsClient,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
from: 'now-15m',
to: 'now',
filters: null,
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('getPingHistogram', () => {

const result = await getPingHistogram({
callES: mockEsClient,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
from: '1234',
to: '5678',
filters: JSON.stringify(searchFilter),
Expand Down Expand Up @@ -196,7 +196,7 @@ describe('getPingHistogram', () => {
const filters = `{"bool":{"must":[{"simple_query_string":{"query":"http"}}]}}`;
const result = await getPingHistogram({
callES: mockEsClient,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
from: 'now-15m',
to: 'now',
filters,
Expand All @@ -213,7 +213,7 @@ describe('getPingHistogram', () => {
mockEsClient.mockReturnValue(standardMockResponse);
const result = await getPingHistogram({
callES: mockEsClient,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
from: '1234',
to: '5678',
filters: '',
Expand All @@ -234,7 +234,7 @@ describe('getPingHistogram', () => {

const result = await getPingHistogram({
callES: mockEsClient,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
from: '1234',
to: '5678',
filters: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { getPings } from '../get_pings';
import { set } from 'lodash';
import { defaultDynamicSettings } from '../../../../../../legacy/plugins/uptime/common/runtime_types';
import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../../../../legacy/plugins/uptime/common/constants';

describe('getAll', () => {
let mockEsSearchResult: any;
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('getAll', () => {
},
};
expectedGetAllParams = {
index: defaultDynamicSettings.heartbeatIndices,
index: DYNAMIC_SETTINGS_DEFAULTS.heartbeatIndices,
body: {
query: {
bool: {
Expand All @@ -88,7 +88,7 @@ describe('getAll', () => {
mockEsClient.mockReturnValue(mockEsSearchResult);
const result = await getPings({
callES: mockEsClient,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
dateRange: { from: 'now-1h', to: 'now' },
sort: 'asc',
size: 12,
Expand All @@ -110,7 +110,7 @@ describe('getAll', () => {
mockEsClient.mockReturnValue(mockEsSearchResult);
await getPings({
callES: mockEsClient,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
dateRange: { from: 'now-1h', to: 'now' },
sort: 'asc',
size: 12,
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('getAll', () => {
mockEsClient.mockReturnValue(mockEsSearchResult);
await getPings({
callES: mockEsClient,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
dateRange: { from: 'now-1h', to: 'now' },
size: 12,
});
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('getAll', () => {
mockEsClient.mockReturnValue(mockEsSearchResult);
await getPings({
callES: mockEsClient,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
dateRange: { from: 'now-1h', to: 'now' },
sort: 'desc',
});
Expand Down Expand Up @@ -274,7 +274,7 @@ describe('getAll', () => {
mockEsClient.mockReturnValue(mockEsSearchResult);
await getPings({
callES: mockEsClient,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
dateRange: { from: 'now-1h', to: 'now' },
monitorId: 'testmonitorid',
});
Expand Down Expand Up @@ -333,7 +333,7 @@ describe('getAll', () => {
mockEsClient.mockReturnValue(mockEsSearchResult);
await getPings({
callES: mockEsClient,
dynamicSettings: defaultDynamicSettings,
dynamicSettings: DYNAMIC_SETTINGS_DEFAULTS,
dateRange: { from: 'now-1h', to: 'now' },
status: 'down',
});
Expand Down
12 changes: 8 additions & 4 deletions x-pack/test/api_integration/apis/uptime/rest/dynamic_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@
*/

import expect from '@kbn/expect';
import { isRight } from 'fp-ts/lib/Either';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { defaultDynamicSettings } from '../../../../../legacy/plugins/uptime/common/runtime_types/dynamic_settings';
import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../../../legacy/plugins/uptime/common/constants';
import { DynamicSettingsType } from '../../../../../legacy/plugins/uptime/common/runtime_types';

export default function({ getService }: FtrProviderContext) {
const supertest = getService('supertest');

describe('dynamic settings', () => {
it('returns the defaults when no user settings have been saved', async () => {
const apiResponse = await supertest.get(`/api/uptime/dynamic_settings`);
expect(apiResponse.body).to.eql(defaultDynamicSettings as any);
expect(apiResponse.body).to.eql(DYNAMIC_SETTINGS_DEFAULTS);
expect(isRight(DynamicSettingsType.decode(apiResponse.body))).to.be.ok();
});

it('can change the settings', async () => {
const newSettings = {
heartbeatIndices: 'myIndex1*',
certificatesThresholds: {
errorState: 5,
warningState: 15,
expiration: 5,
age: 15,
},
};
const postResponse = await supertest
Expand All @@ -35,6 +38,7 @@ export default function({ getService }: FtrProviderContext) {

const getResponse = await supertest.get(`/api/uptime/dynamic_settings`);
expect(getResponse.body).to.eql(newSettings);
expect(isRight(DynamicSettingsType.decode(getResponse.body))).to.be.ok();
});
});
}
Loading

0 comments on commit 7d2bf4c

Please sign in to comment.