Skip to content

Commit

Permalink
fixed typing in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Dec 21, 2020
1 parent 561ebb1 commit 5ddcf7a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
4 changes: 3 additions & 1 deletion x-pack/examples/alerting_example/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AlertTypeParams } from '../../../plugins/alerts/common';

export const ALERTING_EXAMPLE_APP_ID = 'AlertingExample';

// always firing
export const DEFAULT_INSTANCES_TO_GENERATE = 5;
export interface AlwaysFiringParams {
export interface AlwaysFiringParams extends AlertTypeParams {
instances?: number;
thresholds?: {
small?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { withRouter, RouteComponentProps } from 'react-router-dom';
import { CoreStart } from 'kibana/public';
import { isEmpty } from 'lodash';
import { Alert, AlertTaskState, BASE_ALERT_API_PATH } from '../../../../plugins/alerts/common';
import { ALERTING_EXAMPLE_APP_ID } from '../../common/constants';
import { ALERTING_EXAMPLE_APP_ID, AlwaysFiringParams } from '../../common/constants';

type Props = RouteComponentProps & {
http: CoreStart['http'];
Expand All @@ -34,7 +34,7 @@ function hasCraft(state: any): state is { craft: string } {
return state && state.craft;
}
export const ViewPeopleInSpaceAlertPage = withRouter(({ http, id }: Props) => {
const [alert, setAlert] = useState<Alert | null>(null);
const [alert, setAlert] = useState<Alert<AlwaysFiringParams> | null>(null);
const [alertState, setAlertState] = useState<AlertTaskState | null>(null);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ function getCraftFilter(craft: string) {
craft === Craft.OuterSpace ? true : craft === person.craft;
}

export const alertType: AlertType = {
export const alertType: AlertType<
{ outerSpaceCapacity: number; craft: string; op: string },
{ peopleInSpace: number },
{ craft: string }
> = {
id: 'example.people-in-space',
name: 'People In Space Right Now',
actionGroups: [{ id: 'default', name: 'default' }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { i18n } from '@kbn/i18n';
import { Expression, Props } from '../components/duration/expression';
import { AlertTypeModel, ValidationResult } from '../../../../triggers_actions_ui/public';
import { ALERT_CCR_READ_EXCEPTIONS, ALERT_DETAILS } from '../../../common/constants';
import { AlertTypeParams } from '../../../../alerts/common';

interface ValidateOptions {
interface ValidateOptions extends AlertTypeParams {
duration: string;
}

Expand All @@ -30,7 +31,7 @@ const validate = (inputValues: ValidateOptions): ValidationResult => {
return validationResult;
};

export function createCCRReadExceptionsAlertType(): AlertTypeModel {
export function createCCRReadExceptionsAlertType(): AlertTypeModel<ValidateOptions> {
return {
id: ALERT_CCR_READ_EXCEPTIONS,
description: ALERT_DETAILS[ALERT_CCR_READ_EXCEPTIONS].description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
AlertType,
AlertInstanceState,
AlertInstanceContext,
AlertTypeState,
AlertTypeParams,
} from '../../../../../../../plugins/alerts/server';

export const EscapableStrings = {
Expand Down Expand Up @@ -50,7 +52,7 @@ function getAlwaysFiringAlertType() {
groupsToScheduleActionsInSeries: schema.maybe(schema.arrayOf(schema.nullable(schema.string()))),
});
type ParamsType = TypeOf<typeof paramsSchema>;
interface State {
interface State extends AlertTypeState {
groupInSeriesIndex?: number;
}
interface InstanceState extends AlertInstanceState {
Expand All @@ -59,7 +61,7 @@ function getAlwaysFiringAlertType() {
interface InstanceContext extends AlertInstanceContext {
instanceContextValue: boolean;
}
const result: AlertType<ParamsType, State, InstanceState, InstanceContext> = {
const result: AlertType<ParamsType & AlertTypeParams, State, InstanceState, InstanceContext> = {
id: 'test.always-firing',
name: 'Test: Always Firing',
actionGroups: [
Expand Down Expand Up @@ -141,7 +143,7 @@ async function alwaysFiringExecutor(alertExecutorOptions: any) {
}

function getCumulativeFiringAlertType() {
interface State {
interface State extends AlertTypeState {
runCount?: number;
}
interface InstanceState extends AlertInstanceState {
Expand Down Expand Up @@ -175,7 +177,7 @@ function getCumulativeFiringAlertType() {
};
},
};
return result as AlertType;
return result;
}

function getNeverFiringAlertType() {
Expand All @@ -184,7 +186,7 @@ function getNeverFiringAlertType() {
reference: schema.string(),
});
type ParamsType = TypeOf<typeof paramsSchema>;
interface State {
interface State extends AlertTypeState {
globalStateValue: boolean;
}
const result: AlertType<ParamsType, State, {}, {}> = {
Expand Down Expand Up @@ -385,7 +387,7 @@ function getPatternFiringAlertType() {
reference: schema.maybe(schema.string()),
});
type ParamsType = TypeOf<typeof paramsSchema>;
interface State {
interface State extends AlertTypeState {
patternIndex?: number;
}
const result: AlertType<ParamsType, State, {}, {}> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ export const noopAlertType: AlertType = {
producer: 'alerts',
};

export const alwaysFiringAlertType: AlertType = {
export const alwaysFiringAlertType: AlertType<
{ instances: Array<{ id: string; state: any }> },
{
globalStateValue: boolean;
groupInSeriesIndex: number;
},
{ instanceStateValue: boolean; globalStateValue: boolean; groupInSeriesIndex: number }
> = {
id: 'test.always-firing',
name: 'Always Firing',
actionGroups: [
Expand All @@ -37,7 +44,7 @@ export const alwaysFiringAlertType: AlertType = {
defaultActionGroupId: 'default',
producer: 'alerts',
minimumLicenseRequired: 'basic',
async executor(alertExecutorOptions: any) {
async executor(alertExecutorOptions) {
const { services, state, params } = alertExecutorOptions;

(params.instances || []).forEach((instance: { id: string; state: any }) => {
Expand Down

0 comments on commit 5ddcf7a

Please sign in to comment.