Skip to content

Commit

Permalink
upgrade filter bug
Browse files Browse the repository at this point in the history
Previously, we didn't actually add filter type when loading old detector. This PR fixed that.

Testing done:
1. added a unit tes
2. verified e2et

Signed-off-by: Kaituo Li <kaituo@amazon.com>
  • Loading branch information
kaituo committed Jan 28, 2023
1 parent 4ea29db commit fea3456
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 7 deletions.
60 changes: 59 additions & 1 deletion public/pages/DefineDetector/utils/__tests__/helpers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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
}
]
);
});

});
8 changes: 2 additions & 6 deletions public/pages/DefineDetector/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fea3456

Please sign in to comment.