feat: Filter parameter: Improve loose type validation for booleans (#10702)

This commit is contained in:
Elias Meire
2024-09-09 09:54:36 +02:00
committed by GitHub
parent b18313f219
commit e9b8d99084
14 changed files with 261 additions and 22 deletions

View File

@@ -19,6 +19,7 @@ const filterFactory = (data: DeepPartial<FilterValue> = {}): FilterValue =>
combinator: 'and',
conditions: [],
options: {
version: 1,
leftValue: '',
caseSensitive: false,
typeValidation: 'strict',
@@ -234,6 +235,48 @@ describe('FilterParameter', () => {
});
});
describe('options.version', () => {
describe('version 1', () => {
it('should parse "false" as true', () => {
expect(
executeFilter(
filterFactory({
conditions: [
{
id: '1',
leftValue: 'false',
rightValue: false,
operator: { operation: 'equals', type: 'boolean' },
},
],
options: { typeValidation: 'loose', version: 1 },
}),
),
).toEqual(false);
});
});
describe('version 2', () => {
it('should parse "false" as false', () => {
expect(
executeFilter(
filterFactory({
conditions: [
{
id: '1',
leftValue: 'false',
rightValue: false,
operator: { operation: 'equals', type: 'boolean' },
},
],
options: { typeValidation: 'loose', version: 2 },
}),
),
).toEqual(true);
});
});
});
describe('operators', () => {
describe('exists', () => {
it.each([