Skip to content

Commit

Permalink
chore(NA): move watcher plugin tests out of __tests__ folder (#87599)
Browse files Browse the repository at this point in the history
* chore(NA): move watcher plugin tests out of __tests__ folder

* chore(NA): renaming client_integration into tests_client_integration

* chore(NA): rename test helper config file

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
mistic and kibanamachine authored Jan 7, 2021
1 parent 6d6a805 commit 354a79a
Show file tree
Hide file tree
Showing 31 changed files with 240 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import { getActionType } from '../get_action_type';
import { ACTION_TYPES } from '../../../constants';
import { getActionType } from './get_action_type';
import { ACTION_TYPES } from '../../constants';

describe('get_action_type', () => {
describe('getActionType', () => {
Expand All @@ -18,7 +17,7 @@ describe('get_action_type', () => {
};
const type = getActionType(actionJson);

expect(type).to.be(ACTION_TYPES.EMAIL);
expect(type).toBe(ACTION_TYPES.EMAIL);
});

it(`correctly calculates ACTION_TYPES.WEBHOOK`, () => {
Expand All @@ -29,7 +28,7 @@ describe('get_action_type', () => {
};
const type = getActionType(actionJson);

expect(type).to.be(ACTION_TYPES.WEBHOOK);
expect(type).toBe(ACTION_TYPES.WEBHOOK);
});

it(`correctly calculates ACTION_TYPES.INDEX`, () => {
Expand All @@ -40,7 +39,7 @@ describe('get_action_type', () => {
};
const type = getActionType(actionJson);

expect(type).to.be(ACTION_TYPES.INDEX);
expect(type).toBe(ACTION_TYPES.INDEX);
});

it(`correctly calculates ACTION_TYPES.LOGGING`, () => {
Expand All @@ -51,7 +50,7 @@ describe('get_action_type', () => {
};
const type = getActionType(actionJson);

expect(type).to.be(ACTION_TYPES.LOGGING);
expect(type).toBe(ACTION_TYPES.LOGGING);
});

it(`correctly calculates ACTION_TYPES.SLACK`, () => {
Expand All @@ -62,7 +61,7 @@ describe('get_action_type', () => {
};
const type = getActionType(actionJson);

expect(type).to.be(ACTION_TYPES.SLACK);
expect(type).toBe(ACTION_TYPES.SLACK);
});

it(`correctly calculates ACTION_TYPES.PAGERDUTY`, () => {
Expand All @@ -73,7 +72,7 @@ describe('get_action_type', () => {
};
const type = getActionType(actionJson);

expect(type).to.be(ACTION_TYPES.PAGERDUTY);
expect(type).toBe(ACTION_TYPES.PAGERDUTY);
});

it(`correctly calculates ACTION_TYPES.UNKNOWN`, () => {
Expand All @@ -84,7 +83,7 @@ describe('get_action_type', () => {
};
const type = getActionType(actionJson);

expect(type).to.be(ACTION_TYPES.UNKNOWN);
expect(type).toBe(ACTION_TYPES.UNKNOWN);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import { getMoment } from '../get_moment';
import { getMoment } from './get_moment';

describe('get_moment', () => {
describe('getMoment', () => {
it(`returns a moment object when passed a date`, () => {
const moment = getMoment('2017-03-30T14:53:08.121Z');

expect(moment.constructor.name).to.be('Moment');
expect(moment.constructor.name).toBe('Moment');
});

it(`returns null when passed falsy`, () => {
Expand All @@ -26,7 +25,7 @@ describe('get_moment', () => {
];

results.forEach((result) => {
expect(result).to.be(null);
expect(result).toBe(null);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import sinon from 'sinon';
import { fetchAllFromScroll } from '../fetch_all_from_scroll';
import { fetchAllFromScroll } from './fetch_all_from_scroll';
import { set } from '@elastic/safer-lodash-set';

describe('fetch_all_from_scroll', () => {
Expand All @@ -16,29 +14,31 @@ describe('fetch_all_from_scroll', () => {
beforeEach(() => {
mockResponse = {};

stubCallWithRequest = sinon.stub();
stubCallWithRequest.onCall(0).returns(
new Promise((resolve) => {
const mockInnerResponse = {
hits: {
hits: ['newhit'],
},
_scroll_id: 'newScrollId',
};
return resolve(mockInnerResponse);
})
);
stubCallWithRequest = jest.fn();

stubCallWithRequest.onCall(1).returns(
new Promise((resolve) => {
const mockInnerResponse = {
hits: {
hits: [],
},
};
return resolve(mockInnerResponse);
})
);
// TODO: That mocking needs to be migrated to jest
// stubCallWithRequest.onCall(0).returns(
// new Promise((resolve) => {
// const mockInnerResponse = {
// hits: {
// hits: ['newhit'],
// },
// _scroll_id: 'newScrollId',
// };
// return resolve(mockInnerResponse);
// })
// );
//
// stubCallWithRequest.onCall(1).returns(
// new Promise((resolve) => {
// const mockInnerResponse = {
// hits: {
// hits: [],
// },
// };
// return resolve(mockInnerResponse);
// })
// );
});

describe('#fetchAllFromScroll', () => {
Expand All @@ -49,38 +49,39 @@ describe('fetch_all_from_scroll', () => {

it('should return an empty array of hits', () => {
return fetchAllFromScroll(mockResponse).then((hits) => {
expect(hits).to.eql([]);
expect(hits).toEqual([]);
});
});

it('should not call callWithRequest', () => {
return fetchAllFromScroll(mockResponse, stubCallWithRequest).then(() => {
expect(stubCallWithRequest.called).to.be(false);
expect(stubCallWithRequest).not.toHaveBeenCalled();
});
});
});

describe('when the passed-in response has some hits', () => {
// TODO: tests were not running and are not up to date
describe.skip('when the passed-in response has some hits', () => {
beforeEach(() => {
set(mockResponse, 'hits.hits', ['foo', 'bar']);
set(mockResponse, '_scroll_id', 'originalScrollId');
});

it('should return the hits from the response', () => {
return fetchAllFromScroll(mockResponse, stubCallWithRequest).then((hits) => {
expect(hits).to.eql(['foo', 'bar', 'newhit']);
expect(hits).toEqual(['foo', 'bar', 'newhit']);
});
});

it('should call callWithRequest', () => {
return fetchAllFromScroll(mockResponse, stubCallWithRequest).then(() => {
expect(stubCallWithRequest.calledTwice).to.be(true);
expect(stubCallWithRequest.calledTwice).toBe(true);

const firstCallWithRequestCallArgs = stubCallWithRequest.args[0];
expect(firstCallWithRequestCallArgs[1].body.scroll_id).to.eql('originalScrollId');
expect(firstCallWithRequestCallArgs[1].body.scroll_id).toEqual('originalScrollId');

const secondCallWithRequestCallArgs = stubCallWithRequest.args[1];
expect(secondCallWithRequestCallArgs[1].body.scroll_id).to.eql('newScrollId');
expect(secondCallWithRequestCallArgs[1].body.scroll_id).toEqual('newScrollId');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import { kibanaResponseFactory } from '../../../../../../../src/core/server';
import { licensePreRoutingFactory } from '../license_pre_routing_factory';
import { kibanaResponseFactory } from '../../../../../../src/core/server';
import { licensePreRoutingFactory } from './license_pre_routing_factory';

describe('license_pre_routing_factory', () => {
describe('#reportingFeaturePreRoutingFactory', () => {
Expand All @@ -23,7 +22,7 @@ describe('license_pre_routing_factory', () => {
const routeWithLicenseCheck = licensePreRoutingFactory(mockDeps, () => {});
const stubRequest = {};
const response = routeWithLicenseCheck({}, stubRequest, kibanaResponseFactory);
expect(response.status).to.be(403);
expect(response.status).toBe(403);
});
});

Expand All @@ -33,7 +32,7 @@ describe('license_pre_routing_factory', () => {
const routeWithLicenseCheck = licensePreRoutingFactory(mockDeps, () => null);
const stubRequest = {};
const response = routeWithLicenseCheck({}, stubRequest, kibanaResponseFactory);
expect(response).to.be(null);
expect(response).toBe(null);
});
});
});
Expand Down
Loading

0 comments on commit 354a79a

Please sign in to comment.