Skip to content

Commit 180d1df

Browse files
Add unit test for extension numeric properties with between operator
1 parent f829846 commit 180d1df

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { elasticSearchFormatForJSONLogic } from './QueryBuilderElasticsearchFormatUtils';
2+
3+
describe('QueryBuilderElasticsearchFormatUtils', () => {
4+
it('should format between operator correctly for extension numerical properties', () => {
5+
// Mock the immutable RAQB tree properties
6+
const propertiesMap = new Map([
7+
['field', 'extension.table.customNum'],
8+
['operator', 'between'],
9+
['value', { toJS: () => [10, 20] }], // between passes an array of 2 values
10+
['valueSrc', { get: () => 'value' }]
11+
]);
12+
13+
const tree = new Map([
14+
['type', 'rule'],
15+
['properties', propertiesMap],
16+
]);
17+
18+
// Mock minimal config that works with RAQB
19+
const config = {
20+
fields: {
21+
'extension.table.customNum': {
22+
type: 'number'
23+
}
24+
},
25+
conjunctions: {},
26+
operators: {
27+
between: {
28+
elasticSearchQueryType: 'range'
29+
}
30+
}
31+
};
32+
33+
// The method elasticSearchFormatForJSONLogic internally uses tree.get()
34+
const result = elasticSearchFormatForJSONLogic(tree, config);
35+
36+
// Stringify and assert the presence of upper bound (20) and lower bound (10)
37+
// inside the nested Elasticsearch range query structure.
38+
const resultStr = JSON.stringify(result);
39+
40+
// Ensures property matches and range captures both sides
41+
expect(resultStr).toContain('customNum');
42+
expect(resultStr).toContain('"gte":10');
43+
expect(resultStr).toContain('"lte":20');
44+
});
45+
});

0 commit comments

Comments
 (0)