Skip to content

Commit 9cd4f59

Browse files
realSpokNicolas Moreau
andauthored
fix: allow filtering on date on smart field (#1080)
* fix: allow filtering on date on smart field * docs: either nested or virtual * test: add unit test --------- Co-authored-by: Nicolas Moreau <[email protected]>
1 parent e865a36 commit 9cd4f59

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/services/filters-parser.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ function FiltersParser(model, timezone, options) {
9696
}
9797

9898
const fieldPath = subfieldName ? `${fieldName}.${subfieldName}` : fieldName;
99-
const fieldType = utils.getNestedFieldType(model.schema, fieldPath);
99+
100+
// NOTICE: either nested or virtual, not both
101+
const fieldType = field.isVirtual
102+
? field.type
103+
: utils.getNestedFieldType(model.schema, fieldPath);
100104

101105
if (!fieldType) return (val) => val;
102106

test/tests/services/filters-parser.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,23 @@ describe('service > filters-parser', () => {
346346
expect(fakeParser).toHaveBeenCalledTimes(1);
347347
expect(fakeParser).toHaveBeenCalledWith('myValue');
348348

349+
spy.mockRestore();
350+
});
351+
});
352+
describe('with a virtual field', () => {
353+
it('should return the field type', async () => {
354+
expect.hasAssertions();
355+
const fakeParser = jest.fn().mockReturnValue('parsedValue');
356+
const spy = jest.spyOn(defaultParser, 'getParserForType').mockReturnValue(fakeParser);
357+
const type = Symbol('type');
358+
jest.spyOn(Interface.SchemaUtils, 'getField').mockReturnValue({ isVirtual: true, type });
359+
360+
361+
await defaultParser.getParserForField('mySmartField');
362+
363+
expect(defaultParser.getParserForType).toHaveBeenCalledTimes(1);
364+
expect(defaultParser.getParserForType).toHaveBeenCalledWith(type);
365+
349366
spy.mockRestore();
350367
});
351368
});

0 commit comments

Comments
 (0)