[ML] Migrate Mocha unit tests to Jest: migrate job utils and query utils tests (#63775)

* migrate mocha tests to jest for query utils

* update jobUtils test to jest from mocha

* update tests to use jest syntax
This commit is contained in:
Melissa Alvarez 2020-04-17 13:55:46 -04:00 committed by GitHub
parent c0c21d1ba4
commit dc5c2f0e3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 181 additions and 193 deletions

View file

@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import expect from '@kbn/expect';
import {
calculateDatafeedFrequencyDefaultSeconds,
isTimeSeriesViewJob,
@ -20,38 +19,38 @@ import {
prefixDatafeedId,
getSafeAggregationName,
getLatestDataOrBucketTimestamp,
} from '../job_utils';
} from './job_utils';
describe('ML - job utils', () => {
describe('calculateDatafeedFrequencyDefaultSeconds', () => {
it('returns correct frequency for 119', () => {
test('returns correct frequency for 119', () => {
const result = calculateDatafeedFrequencyDefaultSeconds(119);
expect(result).to.be(60);
expect(result).toBe(60);
});
it('returns correct frequency for 120', () => {
test('returns correct frequency for 120', () => {
const result = calculateDatafeedFrequencyDefaultSeconds(120);
expect(result).to.be(60);
expect(result).toBe(60);
});
it('returns correct frequency for 300', () => {
test('returns correct frequency for 300', () => {
const result = calculateDatafeedFrequencyDefaultSeconds(300);
expect(result).to.be(150);
expect(result).toBe(150);
});
it('returns correct frequency for 601', () => {
test('returns correct frequency for 601', () => {
const result = calculateDatafeedFrequencyDefaultSeconds(601);
expect(result).to.be(300);
expect(result).toBe(300);
});
it('returns correct frequency for 43200', () => {
test('returns correct frequency for 43200', () => {
const result = calculateDatafeedFrequencyDefaultSeconds(43200);
expect(result).to.be(600);
expect(result).toBe(600);
});
it('returns correct frequency for 43201', () => {
test('returns correct frequency for 43201', () => {
const result = calculateDatafeedFrequencyDefaultSeconds(43201);
expect(result).to.be(3600);
expect(result).toBe(3600);
});
});
describe('isTimeSeriesViewJob', () => {
it('returns true when job has a single detector with a metric function', () => {
test('returns true when job has a single detector with a metric function', () => {
const job = {
analysis_config: {
detectors: [
@ -64,10 +63,10 @@ describe('ML - job utils', () => {
},
};
expect(isTimeSeriesViewJob(job)).to.be(true);
expect(isTimeSeriesViewJob(job)).toBe(true);
});
it('returns true when job has at least one detector with a metric function', () => {
test('returns true when job has at least one detector with a metric function', () => {
const job = {
analysis_config: {
detectors: [
@ -86,10 +85,10 @@ describe('ML - job utils', () => {
},
};
expect(isTimeSeriesViewJob(job)).to.be(true);
expect(isTimeSeriesViewJob(job)).toBe(true);
});
it('returns false when job does not have at least one detector with a metric function', () => {
test('returns false when job does not have at least one detector with a metric function', () => {
const job = {
analysis_config: {
detectors: [
@ -108,10 +107,10 @@ describe('ML - job utils', () => {
},
};
expect(isTimeSeriesViewJob(job)).to.be(false);
expect(isTimeSeriesViewJob(job)).toBe(false);
});
it('returns false when job has a single count by category detector', () => {
test('returns false when job has a single count by category detector', () => {
const job = {
analysis_config: {
detectors: [
@ -124,7 +123,7 @@ describe('ML - job utils', () => {
},
};
expect(isTimeSeriesViewJob(job)).to.be(false);
expect(isTimeSeriesViewJob(job)).toBe(false);
});
});
@ -171,24 +170,24 @@ describe('ML - job utils', () => {
},
};
it('returns true for a detector with a metric function', () => {
expect(isTimeSeriesViewDetector(job, 0)).to.be(true);
test('returns true for a detector with a metric function', () => {
expect(isTimeSeriesViewDetector(job, 0)).toBe(true);
});
it('returns false for a detector with a non-metric function', () => {
expect(isTimeSeriesViewDetector(job, 1)).to.be(false);
test('returns false for a detector with a non-metric function', () => {
expect(isTimeSeriesViewDetector(job, 1)).toBe(false);
});
it('returns false for a detector using count on an mlcategory field', () => {
expect(isTimeSeriesViewDetector(job, 2)).to.be(false);
test('returns false for a detector using count on an mlcategory field', () => {
expect(isTimeSeriesViewDetector(job, 2)).toBe(false);
});
it('returns false for a detector using a script field as a by field', () => {
expect(isTimeSeriesViewDetector(job, 3)).to.be(false);
test('returns false for a detector using a script field as a by field', () => {
expect(isTimeSeriesViewDetector(job, 3)).toBe(false);
});
it('returns false for a detector using a script field as a metric field_name', () => {
expect(isTimeSeriesViewDetector(job, 4)).to.be(false);
test('returns false for a detector using a script field as a metric field_name', () => {
expect(isTimeSeriesViewDetector(job, 4)).toBe(false);
});
});
@ -233,7 +232,7 @@ describe('ML - job utils', () => {
{ function: 'time_of_day' }, // 34
{ function: 'time_of_week' }, // 35
{ function: 'lat_long' }, // 36
{ function: 'mean', field_name: 'NetworkDiff' }, //37
{ function: 'mean', field_name: 'NetworkDiff' }, // 37
],
},
datafeed_config: {
@ -254,48 +253,48 @@ describe('ML - job utils', () => {
},
};
it('returns true for expected detectors', () => {
expect(isSourceDataChartableForDetector(job, 0)).to.be(true);
expect(isSourceDataChartableForDetector(job, 1)).to.be(true);
expect(isSourceDataChartableForDetector(job, 2)).to.be(true);
expect(isSourceDataChartableForDetector(job, 3)).to.be(true);
expect(isSourceDataChartableForDetector(job, 4)).to.be(true);
expect(isSourceDataChartableForDetector(job, 5)).to.be(true);
expect(isSourceDataChartableForDetector(job, 6)).to.be(true);
expect(isSourceDataChartableForDetector(job, 7)).to.be(true);
expect(isSourceDataChartableForDetector(job, 8)).to.be(true);
expect(isSourceDataChartableForDetector(job, 9)).to.be(true);
expect(isSourceDataChartableForDetector(job, 10)).to.be(true);
expect(isSourceDataChartableForDetector(job, 11)).to.be(true);
expect(isSourceDataChartableForDetector(job, 12)).to.be(true);
expect(isSourceDataChartableForDetector(job, 13)).to.be(true);
expect(isSourceDataChartableForDetector(job, 14)).to.be(true);
expect(isSourceDataChartableForDetector(job, 15)).to.be(true);
expect(isSourceDataChartableForDetector(job, 16)).to.be(true);
expect(isSourceDataChartableForDetector(job, 17)).to.be(true);
expect(isSourceDataChartableForDetector(job, 18)).to.be(true);
expect(isSourceDataChartableForDetector(job, 19)).to.be(true);
expect(isSourceDataChartableForDetector(job, 20)).to.be(true);
expect(isSourceDataChartableForDetector(job, 21)).to.be(true);
expect(isSourceDataChartableForDetector(job, 22)).to.be(true);
expect(isSourceDataChartableForDetector(job, 23)).to.be(true);
expect(isSourceDataChartableForDetector(job, 24)).to.be(true);
test('returns true for expected detectors', () => {
expect(isSourceDataChartableForDetector(job, 0)).toBe(true);
expect(isSourceDataChartableForDetector(job, 1)).toBe(true);
expect(isSourceDataChartableForDetector(job, 2)).toBe(true);
expect(isSourceDataChartableForDetector(job, 3)).toBe(true);
expect(isSourceDataChartableForDetector(job, 4)).toBe(true);
expect(isSourceDataChartableForDetector(job, 5)).toBe(true);
expect(isSourceDataChartableForDetector(job, 6)).toBe(true);
expect(isSourceDataChartableForDetector(job, 7)).toBe(true);
expect(isSourceDataChartableForDetector(job, 8)).toBe(true);
expect(isSourceDataChartableForDetector(job, 9)).toBe(true);
expect(isSourceDataChartableForDetector(job, 10)).toBe(true);
expect(isSourceDataChartableForDetector(job, 11)).toBe(true);
expect(isSourceDataChartableForDetector(job, 12)).toBe(true);
expect(isSourceDataChartableForDetector(job, 13)).toBe(true);
expect(isSourceDataChartableForDetector(job, 14)).toBe(true);
expect(isSourceDataChartableForDetector(job, 15)).toBe(true);
expect(isSourceDataChartableForDetector(job, 16)).toBe(true);
expect(isSourceDataChartableForDetector(job, 17)).toBe(true);
expect(isSourceDataChartableForDetector(job, 18)).toBe(true);
expect(isSourceDataChartableForDetector(job, 19)).toBe(true);
expect(isSourceDataChartableForDetector(job, 20)).toBe(true);
expect(isSourceDataChartableForDetector(job, 21)).toBe(true);
expect(isSourceDataChartableForDetector(job, 22)).toBe(true);
expect(isSourceDataChartableForDetector(job, 23)).toBe(true);
expect(isSourceDataChartableForDetector(job, 24)).toBe(true);
});
it('returns false for expected detectors', () => {
expect(isSourceDataChartableForDetector(job, 25)).to.be(false);
expect(isSourceDataChartableForDetector(job, 26)).to.be(false);
expect(isSourceDataChartableForDetector(job, 27)).to.be(false);
expect(isSourceDataChartableForDetector(job, 28)).to.be(false);
expect(isSourceDataChartableForDetector(job, 29)).to.be(false);
expect(isSourceDataChartableForDetector(job, 30)).to.be(false);
expect(isSourceDataChartableForDetector(job, 31)).to.be(false);
expect(isSourceDataChartableForDetector(job, 32)).to.be(false);
expect(isSourceDataChartableForDetector(job, 33)).to.be(false);
expect(isSourceDataChartableForDetector(job, 34)).to.be(false);
expect(isSourceDataChartableForDetector(job, 35)).to.be(false);
expect(isSourceDataChartableForDetector(job, 36)).to.be(false);
expect(isSourceDataChartableForDetector(job, 37)).to.be(false);
test('returns false for expected detectors', () => {
expect(isSourceDataChartableForDetector(job, 25)).toBe(false);
expect(isSourceDataChartableForDetector(job, 26)).toBe(false);
expect(isSourceDataChartableForDetector(job, 27)).toBe(false);
expect(isSourceDataChartableForDetector(job, 28)).toBe(false);
expect(isSourceDataChartableForDetector(job, 29)).toBe(false);
expect(isSourceDataChartableForDetector(job, 30)).toBe(false);
expect(isSourceDataChartableForDetector(job, 31)).toBe(false);
expect(isSourceDataChartableForDetector(job, 32)).toBe(false);
expect(isSourceDataChartableForDetector(job, 33)).toBe(false);
expect(isSourceDataChartableForDetector(job, 34)).toBe(false);
expect(isSourceDataChartableForDetector(job, 35)).toBe(false);
expect(isSourceDataChartableForDetector(job, 36)).toBe(false);
expect(isSourceDataChartableForDetector(job, 37)).toBe(false);
});
});
@ -315,16 +314,16 @@ describe('ML - job utils', () => {
},
};
it('returns false when model plot is not enabled', () => {
expect(isModelPlotChartableForDetector(job1, 0)).to.be(false);
test('returns false when model plot is not enabled', () => {
expect(isModelPlotChartableForDetector(job1, 0)).toBe(false);
});
it('returns true for count detector when model plot is enabled', () => {
expect(isModelPlotChartableForDetector(job2, 0)).to.be(true);
test('returns true for count detector when model plot is enabled', () => {
expect(isModelPlotChartableForDetector(job2, 0)).toBe(true);
});
it('returns true for info_content detector when model plot is enabled', () => {
expect(isModelPlotChartableForDetector(job2, 1)).to.be(true);
test('returns true for info_content detector when model plot is enabled', () => {
expect(isModelPlotChartableForDetector(job2, 1)).toBe(true);
});
});
@ -359,39 +358,29 @@ describe('ML - job utils', () => {
},
};
it('returns empty array for a detector with no partitioning fields', () => {
test('returns empty array for a detector with no partitioning fields', () => {
const resp = getPartitioningFieldNames(job, 0);
expect(resp).to.be.an('array');
expect(resp).to.be.empty();
expect(resp).toEqual([]);
});
it('returns expected array for a detector with a partition field', () => {
test('returns expected array for a detector with a partition field', () => {
const resp = getPartitioningFieldNames(job, 1);
expect(resp).to.be.an('array');
expect(resp).to.have.length(1);
expect(resp).to.contain('clientip');
expect(resp).toEqual(['clientip']);
});
it('returns expected array for a detector with by and over fields', () => {
test('returns expected array for a detector with by and over fields', () => {
const resp = getPartitioningFieldNames(job, 2);
expect(resp).to.be.an('array');
expect(resp).to.have.length(2);
expect(resp).to.contain('uri');
expect(resp).to.contain('clientip');
expect(resp).toEqual(['uri', 'clientip']);
});
it('returns expected array for a detector with partition, by and over fields', () => {
test('returns expected array for a detector with partition, by and over fields', () => {
const resp = getPartitioningFieldNames(job, 3);
expect(resp).to.be.an('array');
expect(resp).to.have.length(3);
expect(resp).to.contain('uri');
expect(resp).to.contain('clientip');
expect(resp).to.contain('method');
expect(resp).toEqual(['method', 'uri', 'clientip']);
});
});
describe('isModelPlotEnabled', () => {
it('returns true for a job in which model plot has been enabled', () => {
test('returns true for a job in which model plot has been enabled', () => {
const job = {
analysis_config: {
detectors: [
@ -407,10 +396,10 @@ describe('ML - job utils', () => {
},
};
expect(isModelPlotEnabled(job, 0)).to.be(true);
expect(isModelPlotEnabled(job, 0)).toBe(true);
});
it('returns expected values for a job in which model plot has been enabled with terms', () => {
test('returns expected values for a job in which model plot has been enabled with terms', () => {
const job = {
analysis_config: {
detectors: [
@ -433,23 +422,23 @@ describe('ML - job utils', () => {
{ fieldName: 'country', fieldValue: 'US' },
{ fieldName: 'airline', fieldValue: 'AAL' },
])
).to.be(true);
expect(isModelPlotEnabled(job, 0, [{ fieldName: 'country', fieldValue: 'US' }])).to.be(false);
).toBe(true);
expect(isModelPlotEnabled(job, 0, [{ fieldName: 'country', fieldValue: 'US' }])).toBe(false);
expect(
isModelPlotEnabled(job, 0, [
{ fieldName: 'country', fieldValue: 'GB' },
{ fieldName: 'airline', fieldValue: 'AAL' },
])
).to.be(false);
).toBe(false);
expect(
isModelPlotEnabled(job, 0, [
{ fieldName: 'country', fieldValue: 'JP' },
{ fieldName: 'airline', fieldValue: 'JAL' },
])
).to.be(false);
).toBe(false);
});
it('returns true for jobs in which model plot has not been enabled', () => {
test('returns true for jobs in which model plot has not been enabled', () => {
const job1 = {
analysis_config: {
detectors: [
@ -466,8 +455,8 @@ describe('ML - job utils', () => {
};
const job2 = {};
expect(isModelPlotEnabled(job1, 0)).to.be(false);
expect(isModelPlotEnabled(job2, 0)).to.be(false);
expect(isModelPlotEnabled(job1, 0)).toBe(false);
expect(isModelPlotEnabled(job2, 0)).toBe(false);
});
});
@ -476,115 +465,115 @@ describe('ML - job utils', () => {
job_version: '6.1.1',
};
it('returns true for later job version', () => {
expect(isJobVersionGte(job, '6.1.0')).to.be(true);
test('returns true for later job version', () => {
expect(isJobVersionGte(job, '6.1.0')).toBe(true);
});
it('returns true for equal job version', () => {
expect(isJobVersionGte(job, '6.1.1')).to.be(true);
test('returns true for equal job version', () => {
expect(isJobVersionGte(job, '6.1.1')).toBe(true);
});
it('returns false for earlier job version', () => {
expect(isJobVersionGte(job, '6.1.2')).to.be(false);
test('returns false for earlier job version', () => {
expect(isJobVersionGte(job, '6.1.2')).toBe(false);
});
});
describe('mlFunctionToESAggregation', () => {
it('returns correct ES aggregation type for ML function', () => {
expect(mlFunctionToESAggregation('count')).to.be('count');
expect(mlFunctionToESAggregation('low_count')).to.be('count');
expect(mlFunctionToESAggregation('high_count')).to.be('count');
expect(mlFunctionToESAggregation('non_zero_count')).to.be('count');
expect(mlFunctionToESAggregation('low_non_zero_count')).to.be('count');
expect(mlFunctionToESAggregation('high_non_zero_count')).to.be('count');
expect(mlFunctionToESAggregation('distinct_count')).to.be('cardinality');
expect(mlFunctionToESAggregation('low_distinct_count')).to.be('cardinality');
expect(mlFunctionToESAggregation('high_distinct_count')).to.be('cardinality');
expect(mlFunctionToESAggregation('metric')).to.be('avg');
expect(mlFunctionToESAggregation('mean')).to.be('avg');
expect(mlFunctionToESAggregation('low_mean')).to.be('avg');
expect(mlFunctionToESAggregation('high_mean')).to.be('avg');
expect(mlFunctionToESAggregation('min')).to.be('min');
expect(mlFunctionToESAggregation('max')).to.be('max');
expect(mlFunctionToESAggregation('sum')).to.be('sum');
expect(mlFunctionToESAggregation('low_sum')).to.be('sum');
expect(mlFunctionToESAggregation('high_sum')).to.be('sum');
expect(mlFunctionToESAggregation('non_null_sum')).to.be('sum');
expect(mlFunctionToESAggregation('low_non_null_sum')).to.be('sum');
expect(mlFunctionToESAggregation('high_non_null_sum')).to.be('sum');
expect(mlFunctionToESAggregation('rare')).to.be('count');
expect(mlFunctionToESAggregation('freq_rare')).to.be(null);
expect(mlFunctionToESAggregation('info_content')).to.be(null);
expect(mlFunctionToESAggregation('low_info_content')).to.be(null);
expect(mlFunctionToESAggregation('high_info_content')).to.be(null);
expect(mlFunctionToESAggregation('median')).to.be('percentiles');
expect(mlFunctionToESAggregation('low_median')).to.be('percentiles');
expect(mlFunctionToESAggregation('high_median')).to.be('percentiles');
expect(mlFunctionToESAggregation('varp')).to.be(null);
expect(mlFunctionToESAggregation('low_varp')).to.be(null);
expect(mlFunctionToESAggregation('high_varp')).to.be(null);
expect(mlFunctionToESAggregation('time_of_day')).to.be(null);
expect(mlFunctionToESAggregation('time_of_week')).to.be(null);
expect(mlFunctionToESAggregation('lat_long')).to.be(null);
test('returns correct ES aggregation type for ML function', () => {
expect(mlFunctionToESAggregation('count')).toBe('count');
expect(mlFunctionToESAggregation('low_count')).toBe('count');
expect(mlFunctionToESAggregation('high_count')).toBe('count');
expect(mlFunctionToESAggregation('non_zero_count')).toBe('count');
expect(mlFunctionToESAggregation('low_non_zero_count')).toBe('count');
expect(mlFunctionToESAggregation('high_non_zero_count')).toBe('count');
expect(mlFunctionToESAggregation('distinct_count')).toBe('cardinality');
expect(mlFunctionToESAggregation('low_distinct_count')).toBe('cardinality');
expect(mlFunctionToESAggregation('high_distinct_count')).toBe('cardinality');
expect(mlFunctionToESAggregation('metric')).toBe('avg');
expect(mlFunctionToESAggregation('mean')).toBe('avg');
expect(mlFunctionToESAggregation('low_mean')).toBe('avg');
expect(mlFunctionToESAggregation('high_mean')).toBe('avg');
expect(mlFunctionToESAggregation('min')).toBe('min');
expect(mlFunctionToESAggregation('max')).toBe('max');
expect(mlFunctionToESAggregation('sum')).toBe('sum');
expect(mlFunctionToESAggregation('low_sum')).toBe('sum');
expect(mlFunctionToESAggregation('high_sum')).toBe('sum');
expect(mlFunctionToESAggregation('non_null_sum')).toBe('sum');
expect(mlFunctionToESAggregation('low_non_null_sum')).toBe('sum');
expect(mlFunctionToESAggregation('high_non_null_sum')).toBe('sum');
expect(mlFunctionToESAggregation('rare')).toBe('count');
expect(mlFunctionToESAggregation('freq_rare')).toBe(null);
expect(mlFunctionToESAggregation('info_content')).toBe(null);
expect(mlFunctionToESAggregation('low_info_content')).toBe(null);
expect(mlFunctionToESAggregation('high_info_content')).toBe(null);
expect(mlFunctionToESAggregation('median')).toBe('percentiles');
expect(mlFunctionToESAggregation('low_median')).toBe('percentiles');
expect(mlFunctionToESAggregation('high_median')).toBe('percentiles');
expect(mlFunctionToESAggregation('varp')).toBe(null);
expect(mlFunctionToESAggregation('low_varp')).toBe(null);
expect(mlFunctionToESAggregation('high_varp')).toBe(null);
expect(mlFunctionToESAggregation('time_of_day')).toBe(null);
expect(mlFunctionToESAggregation('time_of_week')).toBe(null);
expect(mlFunctionToESAggregation('lat_long')).toBe(null);
});
});
describe('isJobIdValid', () => {
it('returns true for job id: "good_job-name"', () => {
expect(isJobIdValid('good_job-name')).to.be(true);
test('returns true for job id: "good_job-name"', () => {
expect(isJobIdValid('good_job-name')).toBe(true);
});
it('returns false for job id: "_bad_job-name"', () => {
expect(isJobIdValid('_bad_job-name')).to.be(false);
test('returns false for job id: "_bad_job-name"', () => {
expect(isJobIdValid('_bad_job-name')).toBe(false);
});
it('returns false for job id: "bad_job-name_"', () => {
expect(isJobIdValid('bad_job-name_')).to.be(false);
test('returns false for job id: "bad_job-name_"', () => {
expect(isJobIdValid('bad_job-name_')).toBe(false);
});
it('returns false for job id: "-bad_job-name"', () => {
expect(isJobIdValid('-bad_job-name')).to.be(false);
test('returns false for job id: "-bad_job-name"', () => {
expect(isJobIdValid('-bad_job-name')).toBe(false);
});
it('returns false for job id: "bad_job-name-"', () => {
expect(isJobIdValid('bad_job-name-')).to.be(false);
test('returns false for job id: "bad_job-name-"', () => {
expect(isJobIdValid('bad_job-name-')).toBe(false);
});
it('returns false for job id: "bad&job-name"', () => {
expect(isJobIdValid('bad&job-name')).to.be(false);
test('returns false for job id: "bad&job-name"', () => {
expect(isJobIdValid('bad&job-name')).toBe(false);
});
});
describe('ML_MEDIAN_PERCENTS', () => {
it("is '50.0'", () => {
expect(ML_MEDIAN_PERCENTS).to.be('50.0');
test("is '50.0'", () => {
expect(ML_MEDIAN_PERCENTS).toBe('50.0');
});
});
describe('prefixDatafeedId', () => {
it('returns datafeed-prefix-job from datafeed-job"', () => {
expect(prefixDatafeedId('datafeed-job', 'prefix-')).to.be('datafeed-prefix-job');
test('returns datafeed-prefix-job from datafeed-job"', () => {
expect(prefixDatafeedId('datafeed-job', 'prefix-')).toBe('datafeed-prefix-job');
});
it('returns datafeed-prefix-job from job"', () => {
expect(prefixDatafeedId('job', 'prefix-')).to.be('datafeed-prefix-job');
test('returns datafeed-prefix-job from job"', () => {
expect(prefixDatafeedId('job', 'prefix-')).toBe('datafeed-prefix-job');
});
});
describe('getSafeAggregationName', () => {
it('"foo" should be "foo"', () => {
expect(getSafeAggregationName('foo', 0)).to.be('foo');
test('"foo" should be "foo"', () => {
expect(getSafeAggregationName('foo', 0)).toBe('foo');
});
it('"foo.bar" should be "foo.bar"', () => {
expect(getSafeAggregationName('foo.bar', 0)).to.be('foo.bar');
test('"foo.bar" should be "foo.bar"', () => {
expect(getSafeAggregationName('foo.bar', 0)).toBe('foo.bar');
});
it('"foo&bar" should be "field_0"', () => {
expect(getSafeAggregationName('foo&bar', 0)).to.be('field_0');
test('"foo&bar" should be "field_0"', () => {
expect(getSafeAggregationName('foo&bar', 0)).toBe('field_0');
});
});
describe('getLatestDataOrBucketTimestamp', () => {
it('returns expected value when no gap in data at end of bucket processing', () => {
expect(getLatestDataOrBucketTimestamp(1549929594000, 1549928700000)).to.be(1549929594000);
test('returns expected value when no gap in data at end of bucket processing', () => {
expect(getLatestDataOrBucketTimestamp(1549929594000, 1549928700000)).toBe(1549929594000);
});
it('returns expected value when there is a gap in data at end of bucket processing', () => {
expect(getLatestDataOrBucketTimestamp(1549929594000, 1562256600000)).to.be(1562256600000);
test('returns expected value when there is a gap in data at end of bucket processing', () => {
expect(getLatestDataOrBucketTimestamp(1549929594000, 1562256600000)).toBe(1562256600000);
});
it('returns expected value when job has not run', () => {
expect(getLatestDataOrBucketTimestamp(undefined, undefined)).to.be(undefined);
test('returns expected value when job has not run', () => {
expect(getLatestDataOrBucketTimestamp(undefined, undefined)).toBe(undefined);
});
});
});

View file

@ -4,12 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/
import expect from '@kbn/expect';
import {
buildBaseFilterCriteria,
buildSamplerAggregation,
getSamplerAggregationsResponsePath,
} from '../query_utils';
} from './query_utils';
describe('ML - query utils', () => {
describe('buildBaseFilterCriteria', () => {
@ -23,8 +22,8 @@ describe('ML - query utils', () => {
},
};
it('returns correct criteria for time range', () => {
expect(buildBaseFilterCriteria('timestamp', earliestMs, latestMs)).to.eql([
test('returns correct criteria for time range', () => {
expect(buildBaseFilterCriteria('timestamp', earliestMs, latestMs)).toEqual([
{
range: {
timestamp: {
@ -37,8 +36,8 @@ describe('ML - query utils', () => {
]);
});
it('returns correct criteria for time range and query', () => {
expect(buildBaseFilterCriteria('timestamp', earliestMs, latestMs, query)).to.eql([
test('returns correct criteria for time range and query', () => {
expect(buildBaseFilterCriteria('timestamp', earliestMs, latestMs, query)).toEqual([
{
range: {
timestamp: {
@ -60,8 +59,8 @@ describe('ML - query utils', () => {
},
};
it('returns wrapped sampler aggregation for sampler shard size of 1000', () => {
expect(buildSamplerAggregation(testAggs, 1000)).to.eql({
test('returns wrapped sampler aggregation for sampler shard size of 1000', () => {
expect(buildSamplerAggregation(testAggs, 1000)).toEqual({
sample: {
sampler: {
shard_size: 1000,
@ -71,18 +70,18 @@ describe('ML - query utils', () => {
});
});
it('returns un-sampled aggregation as-is for sampler shard size of 0', () => {
expect(buildSamplerAggregation(testAggs, 0)).to.eql(testAggs);
test('returns un-sampled aggregation as-is for sampler shard size of 0', () => {
expect(buildSamplerAggregation(testAggs, 0)).toEqual(testAggs);
});
});
describe('getSamplerAggregationsResponsePath', () => {
it('returns correct path for sampler shard size of 1000', () => {
expect(getSamplerAggregationsResponsePath(1000)).to.eql(['sample']);
test('returns correct path for sampler shard size of 1000', () => {
expect(getSamplerAggregationsResponsePath(1000)).toEqual(['sample']);
});
it('returns correct path for sampler shard size of 0', () => {
expect(getSamplerAggregationsResponsePath(0)).to.eql([]);
test('returns correct path for sampler shard size of 0', () => {
expect(getSamplerAggregationsResponsePath(0)).toEqual([]);
});
});
});