Skip to content

Commit

Permalink
[ML] convert data_recognizer test to jest
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Feb 11, 2020
1 parent 63ea75b commit 9edbdec
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import { RequestHandlerContext } from 'kibana/server';
import { Module } from '../../../common/types/modules';
import { DataRecognizer } from '../data_recognizer';

describe('ML - data recognizer', () => {
const dr = new DataRecognizer({});
const dr = new DataRecognizer(({
ml: {
mlClient: {
callAsCurrentUser: jest.fn(),
},
},
core: {
savedObjects: {
client: {
find: jest.fn(),
bulkCreate: jest.fn(),
},
},
},
} as unknown) as RequestHandlerContext);

const moduleIds = [
'apache_ecs',
Expand All @@ -34,20 +49,20 @@ describe('ML - data recognizer', () => {
it('listModules - check all module IDs', async () => {
const modules = await dr.listModules();
const ids = modules.map(m => m.id);
expect(ids.join()).to.equal(moduleIds.join());
expect(ids.join()).toEqual(moduleIds.join());
});

it('getModule - load a single module', async () => {
const module = await dr.getModule(moduleIds[0]);
expect(module.id).to.equal(moduleIds[0]);
expect(module.id).toEqual(moduleIds[0]);
});

describe('jobOverrides', () => {
it('should apply job overrides correctly', () => {
// arrange
const prefix = 'pre-';
const testJobId = 'test-job';
const moduleConfig = {
const moduleConfig = ({
jobs: [
{
id: `${prefix}${testJobId}`,
Expand All @@ -64,7 +79,7 @@ describe('ML - data recognizer', () => {
},
},
],
};
} as unknown) as Module;
const jobOverrides = [
{
analysis_limits: {
Expand All @@ -80,7 +95,7 @@ describe('ML - data recognizer', () => {
// act
dr.applyJobConfigOverrides(moduleConfig, jobOverrides, prefix);
// assert
expect(moduleConfig.jobs).to.eql([
expect(moduleConfig.jobs).toEqual([
{
config: {
analysis_config: {
Expand Down

0 comments on commit 9edbdec

Please sign in to comment.