Skip to content

Commit

Permalink
Add unit tests and explicitly define type
Browse files Browse the repository at this point in the history
Signed-off-by: Vijayan Balasubramanian <balasvij@amazon.com>
  • Loading branch information
VijayanB committed Mar 21, 2023
1 parent 3141b8b commit 5ac7d4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,20 @@ describe('geo shape filter', function () {
const result = getGeoShapeFilterField(filter);
expect(result).toBe('geoPointField');
});
it('should return undefined if filter.geo_shape is undefined', () => {
const filter: GeoShapeFilter = {
geo_shape: undefined,
meta: {
disabled: false,
negate: false,
alias: null,
params: {
shape: undefined,
},
},
};
const result = getGeoShapeFilterField(filter);
expect(result).toBeUndefined();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export type GeoShapeFilter = Filter & {

export const isGeoShapeFilter = (filter: any): filter is GeoShapeFilter => filter?.geo_shape;

export const getGeoShapeFilterField = (filter: GeoShapeFilter) => {
export const getGeoShapeFilterField = (filter: GeoShapeFilter): string | undefined => {
if (filter?.geo_shape === undefined) {
return undefined;
}
return (
filter?.geo_shape && Object.keys(filter.geo_shape).find((key) => key !== 'ignore_unmapped')
);
Expand Down

0 comments on commit 5ac7d4e

Please sign in to comment.