Skip to content

Commit

Permalink
Use dateMath to parse moments in ML/Threshold tests
Browse files Browse the repository at this point in the history
  • Loading branch information
madirey committed Jun 15, 2021
1 parent 2f9ac90 commit 956963e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import moment from 'moment';
import dateMath from '@elastic/datemath';
import { loggingSystemMock } from 'src/core/server/mocks';
import { alertsMock, AlertServicesMock } from '../../../../../../alerting/server/mocks';
import { mlExecutor } from './ml';
Expand All @@ -29,7 +29,11 @@ describe('ml_executor', () => {
let alertServices: AlertServicesMock;
const params = getMlRuleParams();
const mlSO = sampleRuleSO(params);
const tuple = { from: moment(params.from), to: moment(params.to), maxSignals: params.maxSignals };
const tuple = {
from: dateMath.parse(params.from)!,
to: dateMath.parse(params.to)!,
maxSignals: params.maxSignals,
};
const buildRuleMessage = buildRuleMessageFactory({
id: mlSO.id,
ruleId: mlSO.attributes.params.ruleId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import moment from 'moment';
import dateMath from '@elastic/datemath';
import { loggingSystemMock } from 'src/core/server/mocks';
import { alertsMock, AlertServicesMock } from '../../../../../../alerting/server/mocks';
import { thresholdExecutor } from './threshold';
Expand All @@ -18,6 +18,7 @@ describe('threshold_executor', () => {
const version = '8.0.0';
let logger: ReturnType<typeof loggingSystemMock.createLogger>;
let alertServices: AlertServicesMock;
const params = getThresholdRuleParams();
const thresholdSO = {
id: '04128c15-0d1b-4716-a4c5-46997ac7f3bd',
type: 'alert',
Expand All @@ -35,10 +36,15 @@ describe('threshold_executor', () => {
interval: '5m',
},
throttle: 'no_actions',
params: getThresholdRuleParams(),
params,
},
references: [],
};
const tuple = {
from: dateMath.parse(params.from)!,
to: dateMath.parse(params.to)!,
maxSignals: params.maxSignals,
};
const buildRuleMessage = buildRuleMessageFactory({
id: thresholdSO.id,
ruleId: thresholdSO.attributes.params.ruleId,
Expand All @@ -56,7 +62,7 @@ describe('threshold_executor', () => {
const exceptionItems = [getExceptionListItemSchemaMock({ entries: [getEntryListMock()] })];
const response = await thresholdExecutor({
rule: thresholdSO,
tuple: { to: moment(), from: moment(), maxSignals: 100 },
tuple,
exceptionItems,
services: alertServices,
version,
Expand Down

0 comments on commit 956963e

Please sign in to comment.