Skip to content

Commit

Permalink
Fix type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Jan 13, 2020
1 parent d8b505d commit 9e5a7bc
Showing 1 changed file with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ import { Logger } from 'src/core/server';
import { AlertServices } from '../../../alerting/server/types';
import { savedObjectsClientMock } from 'src/core/server/mocks';
import { AlertInstance } from '../../../alerting/server/alert_instance';
import { AlertState, AlertClusterState, AlertParams } from './types';
import {
AlertState,
AlertClusterState,
AlertParams,
LicenseExpirationAlertExecutorOptions,
} from './types';
import { SavedObject, SavedObjectAttributes } from 'src/core/server';
import { SavedObjectsClientContract } from 'src/core/server';

function fillLicense(license: any, clusterUuid?: string) {
return {
Expand All @@ -39,6 +45,29 @@ const params: AlertParams = {
ccs: null,
};

interface MockServices {
callCluster: jest.Mock;
alertInstanceFactory: jest.Mock;
savedObjectsClient: jest.Mock;
}

const alertExecutorOptions: LicenseExpirationAlertExecutorOptions = {
alertId: '',
startedAt: new Date(),
services: {
callCluster: (path: string, opts: any) => new Promise(resolve => resolve()),
alertInstanceFactory: (id: string) => new AlertInstance(),
savedObjectsClient: {} as jest.Mocked<SavedObjectsClientContract>,
},
params: {},
state: {},
spaceId: '',
name: '',
tags: [],
createdBy: null,
updatedBy: null,
};

describe('getLicenseExpiration', () => {
const getMonitoringCluster: () => void = jest.fn();
const logger: Logger = {
Expand All @@ -64,11 +93,6 @@ describe('getLicenseExpiration', () => {
expect(alert.actionGroups).toEqual(['default']);
});

interface MockServices {
callCluster: jest.Mock;
alertInstanceFactory: jest.Mock;
savedObjectsClient: jest.Mock;
}
it('should return the state if no license is provided', async () => {
const alert = getLicenseExpiration(getMonitoringCluster, getLogger, ccrEnabled);

Expand All @@ -80,8 +104,7 @@ describe('getLicenseExpiration', () => {
const state = { foo: 1 };

const result = await alert.executor({
alertId: '',
startedAt: new Date(),
...alertExecutorOptions,
services,
params,
state,
Expand Down Expand Up @@ -119,8 +142,7 @@ describe('getLicenseExpiration', () => {
const state = {};

await alert.executor({
alertId: '',
startedAt: new Date(),
...alertExecutorOptions,
services,
params,
state,
Expand Down Expand Up @@ -189,8 +211,7 @@ describe('getLicenseExpiration', () => {
const state = {};

const result: AlertState = (await alert.executor({
alertId: '',
startedAt: new Date(),
...alertExecutorOptions,
services,
params,
state,
Expand Down Expand Up @@ -268,8 +289,7 @@ describe('getLicenseExpiration', () => {
};

const result: AlertState = (await alert.executor({
alertId: '',
startedAt: new Date(),
...alertExecutorOptions,
services,
params,
state,
Expand Down Expand Up @@ -338,8 +358,7 @@ describe('getLicenseExpiration', () => {

const state = {};
const result: AlertState = (await alert.executor({
alertId: '',
startedAt: new Date(),
...alertExecutorOptions,
services,
params,
state,
Expand Down Expand Up @@ -404,8 +423,7 @@ describe('getLicenseExpiration', () => {

const state = {};
const result: AlertState = (await alert.executor({
alertId: '',
startedAt: new Date(),
...alertExecutorOptions,
services,
params,
state,
Expand Down

0 comments on commit 9e5a7bc

Please sign in to comment.