Skip to content

Commit

Permalink
test(filters): add tests on the Not In filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Molinié committed Aug 2, 2024
1 parent a0f5422 commit ecc3031
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions packages/agent/test/utils/condition-tree-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ describe('ConditionTreeParser', () => {
});

expect(tree).toStrictEqual(new ConditionTreeLeaf('id', 'In', ['id1', 'id2', 'id3']));

const treeWithArray = ConditionTreeParser.fromPlainObject(collection, {
field: 'id',
operator: 'in',
value: ['id1', 'id2', 'id3'],
});

expect(treeWithArray).toStrictEqual(new ConditionTreeLeaf('id', 'In', ['id1', 'id2', 'id3']));
});

test('should work with in and number', () => {
Expand All @@ -66,6 +74,14 @@ describe('ConditionTreeParser', () => {
});

expect(tree).toStrictEqual(new ConditionTreeLeaf('number', 'In', [1, 2, 3]));

const treeWithArray = ConditionTreeParser.fromPlainObject(collection, {
field: 'number',
operator: 'in',
value: [1, 2, 3, 'invalid'],
});

expect(treeWithArray).toStrictEqual(new ConditionTreeLeaf('number', 'In', [1, 2, 3]));
});

test('should work with in and boolean', () => {
Expand All @@ -78,6 +94,74 @@ describe('ConditionTreeParser', () => {
expect(tree).toStrictEqual(
new ConditionTreeLeaf('boolean', 'In', [true, false, false, true, false]),
);

const treeWithArray = ConditionTreeParser.fromPlainObject(collection, {
field: 'boolean',
operator: 'in',
value: [true, 0, false, 'yes', 'no'],
});

expect(treeWithArray).toStrictEqual(
new ConditionTreeLeaf('boolean', 'In', [true, false, false, true, false]),
);
});

test('should work with not_in and string', () => {
const tree = ConditionTreeParser.fromPlainObject(collection, {
field: 'id',
operator: 'not_in',
value: 'id1,id2 , id3',
});

expect(tree).toStrictEqual(new ConditionTreeLeaf('id', 'In', ['id1', 'id2', 'id3']));

const treeWithArray = ConditionTreeParser.fromPlainObject(collection, {
field: 'id',
operator: 'not_in',
value: ['id1', 'id2', 'id3'],
});

expect(treeWithArray).toStrictEqual(new ConditionTreeLeaf('id', 'In', ['id1', 'id2', 'id3']));
});

test('should work with not_in and number', () => {
const tree = ConditionTreeParser.fromPlainObject(collection, {
field: 'number',
operator: 'not_in',
value: '1, 2, 3 , invalid',
});

expect(tree).toStrictEqual(new ConditionTreeLeaf('number', 'In', [1, 2, 3]));

const treeWithArray = ConditionTreeParser.fromPlainObject(collection, {
field: 'number',
operator: 'not_in',
value: [1, 2, 3, 'invalid'],
});

expect(treeWithArray).toStrictEqual(new ConditionTreeLeaf('number', 'In', [1, 2, 3]));
});

test('should work with not_in and boolean', () => {
const tree = ConditionTreeParser.fromPlainObject(collection, {
field: 'boolean',
operator: 'not_in',
value: 'true, 0, false, yes, no',
});

expect(tree).toStrictEqual(
new ConditionTreeLeaf('boolean', 'In', [true, false, false, true, false]),
);

const treeWithArray = ConditionTreeParser.fromPlainObject(collection, {
field: 'boolean',
operator: 'not_in',
value: [true, 0, false, 'yes', 'no'],
});

expect(treeWithArray).toStrictEqual(
new ConditionTreeLeaf('boolean', 'In', [true, false, false, true, false]),
);
});

test('should work with ShorterThan and string', () => {
Expand Down

0 comments on commit ecc3031

Please sign in to comment.