Skip to content

Commit

Permalink
Add unit tests for filterRuleFieldsForType
Browse files Browse the repository at this point in the history
  • Loading branch information
rylnd committed Mar 23, 2020
1 parent 1ee539b commit a63ac98
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
formatScheduleStepData,
formatAboutStepData,
formatRule,
filterRuleFieldsForType,
} from './helpers';
import {
mockDefineStepRule,
Expand Down Expand Up @@ -538,4 +539,48 @@ describe('helpers', () => {
expect(result.id).toBeUndefined();
});
});

describe('filterRuleFieldsForType', () => {
let fields: DefineStepRule;

beforeEach(() => {
fields = mockDefineStepRule();
});

it('removes query fields if the type is machine learning', () => {
const result = filterRuleFieldsForType(fields, 'machine_learning');
expect(result).not.toHaveProperty('index');
expect(result).not.toHaveProperty('queryBar');
});

it('leaves ML fields if the type is machine learning', () => {
const result = filterRuleFieldsForType(fields, 'machine_learning');
expect(result).toHaveProperty('anomalyThreshold');
expect(result).toHaveProperty('machineLearningJobId');
});

it('leaves arbitrary fields if the type is machine learning', () => {
const result = filterRuleFieldsForType(fields, 'machine_learning');
expect(result).toHaveProperty('timeline');
expect(result).toHaveProperty('ruleType');
});

it('removes ML fields if the type is not machine learning', () => {
const result = filterRuleFieldsForType(fields, 'query');
expect(result).not.toHaveProperty('anomalyThreshold');
expect(result).not.toHaveProperty('machineLearningJobId');
});

it('leaves query fields if the type is query', () => {
const result = filterRuleFieldsForType(fields, 'query');
expect(result).toHaveProperty('index');
expect(result).toHaveProperty('queryBar');
});

it('leaves arbitrary fields if the type is query', () => {
const result = filterRuleFieldsForType(fields, 'query');
expect(result).toHaveProperty('timeline');
expect(result).toHaveProperty('ruleType');
});
});
});

0 comments on commit a63ac98

Please sign in to comment.