diff --git a/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx b/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx index e44682f6..b6d9590d 100644 --- a/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx +++ b/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx @@ -10,12 +10,13 @@ */ import { INITIAL_DETECTOR_DEFINITION_VALUES } from '../../utils/constants'; +import { DATA_TYPES } from '../../../../utils/constants'; import { getRandomDetector } from '../../../../redux/reducers/__tests__/utils'; import { detectorDefinitionToFormik, filtersToFormik, } from '../../utils/helpers'; -import { Detector } from '../../../../models/interfaces'; +import { Detector, OPERATORS_MAP, FILTER_TYPES } from '../../../../models/interfaces'; describe('detectorDefinitionToFormik', () => { test('should return initialValues if detector is null', () => { @@ -53,4 +54,61 @@ describe('detectorDefinitionToFormik', () => { windowDelay: randomDetector.windowDelay.period.interval, }); }); + test('upgrade old detector\'s filters to include filter type', () => { + const randomDetector = getRandomDetector(); + randomDetector.uiMetadata = { + features: {}, + filters : [ + { + fieldInfo : [ + { + label : 'service', + type : DATA_TYPES.KEYWORD + } + ], + fieldValue : "app_3", + operator : OPERATORS_MAP.IS + }, + { + fieldInfo : [ + { + label : "host", + type : DATA_TYPES.KEYWORD + } + ], + fieldValue : "server_2", + operator : OPERATORS_MAP.IS + } + ], + filterType : FILTER_TYPES.SIMPLE + }; + const adFormikValues = filtersToFormik(randomDetector); + expect(adFormikValues).toEqual( + [ + { + fieldInfo : [ + { + label : 'service', + type : DATA_TYPES.KEYWORD + } + ], + fieldValue : "app_3", + operator : OPERATORS_MAP.IS, + filterType : FILTER_TYPES.SIMPLE + }, + { + fieldInfo : [ + { + label : "host", + type : DATA_TYPES.KEYWORD + } + ], + fieldValue : "server_2", + operator : OPERATORS_MAP.IS, + filterType : FILTER_TYPES.SIMPLE + } + ] + ); + }); + }); diff --git a/public/pages/DefineDetector/utils/helpers.ts b/public/pages/DefineDetector/utils/helpers.ts index 579a500f..fd427913 100644 --- a/public/pages/DefineDetector/utils/helpers.ts +++ b/public/pages/DefineDetector/utils/helpers.ts @@ -89,12 +89,8 @@ export function filtersToFormik(detector: Detector): UIFilter[] { }, ]; } else { - curFilters.forEach((filter: UIFilter) => { - return { - ...filter, - filterType: curFilterType, - }; - }); + curFilters.forEach((filter: UIFilter) => + filter.filterType = curFilterType); } } return curFilters;