Skip to content

Commit

Permalink
Fix TS errors and fix server watch model tests.
Browse files Browse the repository at this point in the history
- Convert tests from Mocha to Jest.
- Remove mocks and fix assertions that depended upon mocked dependencies. These assertions were low-value because they tested implementation details.
- Remove other assertions based upon implementation details.
  • Loading branch information
cjcenizal committed Aug 15, 2019
1 parent 215cd03 commit cc91b97
Show file tree
Hide file tree
Showing 14 changed files with 643 additions and 1,147 deletions.
10 changes: 10 additions & 0 deletions x-pack/legacy/plugins/watcher/common/lib/serialization/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export declare function serializeJsonWatch(name: string, json: any): any;
export declare function serializeThresholdWatch(config: any): any;
export declare function serializeMonitoringWatch(config: any): any;
export declare function buildInput(config: any): any;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { Action } from './action';
import { LoggingAction } from './logging_action';
import { ACTION_TYPES } from '../../../common/constants';

jest.mock('./logging_action', () => ({
Expand All @@ -18,11 +17,8 @@ jest.mock('./logging_action', () => ({
}));

describe('action', () => {

describe('Action', () => {

describe('fromUpstreamJson factory method', () => {

let upstreamJson;
beforeEach(() => {
upstreamJson = {
Expand All @@ -35,43 +31,13 @@ describe('action', () => {
};
});

it(`throws an error if no 'id' property in json`, () => {
delete upstreamJson.id;
expect(() => {
Action.fromUpstreamJson(upstreamJson);
}).toThrowError('JSON argument must contain an id property');
});

it(`throws an error if no 'actionJson' property in json`, () => {
delete upstreamJson.actionJson;
expect(() => {
Action.fromUpstreamJson(upstreamJson);
}).toThrowError('JSON argument must contain an actionJson property');
});

it(`throws an error if an Action is invalid`, () => {
const message = 'Missing prop in Logging Action!';

LoggingAction.fromUpstreamJson.mockReturnValueOnce({
errors: [{ message }],
action: {},
});

expect(() => {
Action.fromUpstreamJson(upstreamJson);
}).toThrowError(message);
});

it('returns correct Action instance', () => {
const action = Action.fromUpstreamJson(upstreamJson);

expect(action.id).toBe(upstreamJson.id);
});

});

describe('type getter method', () => {

it(`returns the correct known Action type`, () => {
const options = { throwExceptions: { Action: false } };

Expand All @@ -81,7 +47,7 @@ describe('action', () => {
const upstreamEmailJson = { id: 'action2', actionJson: { email: {} } };
const emailAction = Action.fromUpstreamJson(upstreamEmailJson, options);

const upstreamSlackJson = { id: 'action3', actionJson: { slack: {} } };
const upstreamSlackJson = { id: 'action3', actionJson: { slack: { message: {} } } };
const slackAction = Action.fromUpstreamJson(upstreamSlackJson, options);

expect(loggingAction.type).toBe(ACTION_TYPES.LOGGING);
Expand All @@ -102,11 +68,9 @@ describe('action', () => {

expect(action.type).toBe(ACTION_TYPES.UNKNOWN);
});

});

describe('downstreamJson getter method', () => {

let upstreamJson;
beforeEach(() => {
upstreamJson = {
Expand All @@ -120,17 +84,12 @@ describe('action', () => {
});

it('returns correct JSON for client', () => {

const action = Action.fromUpstreamJson(upstreamJson);

const json = action.downstreamJson;

expect(json.id).toBe(action.id);
expect(json.type).toBe(action.type);
});

});

});

});
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import {
} from '@elastic/eui';

interface Props {
id: any;
close: any;
watch: any;
payload: any;
}

export class RequestFlyout extends PureComponent<Props> {
getEsJson(payload) {
getEsJson(payload: any): string {
return JSON.stringify(payload, null, 2);
}

Expand Down

This file was deleted.

Loading

0 comments on commit cc91b97

Please sign in to comment.