Skip to content

Commit

Permalink
1123: [Feature] Make filter helper works with nested objects
Browse files Browse the repository at this point in the history
  • Loading branch information
edtoken committed Aug 28, 2023
1 parent 825449a commit cafb48e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const filter = function (...args) {
if (typeof payload === 'object') {
const keys = Object.keys(condition);

return keys.every((k) => payload[k] === condition[k]);
return keys.every((k) => validate(payload[k], condition[k]));
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2388,5 +2388,18 @@ describe('Template parser', () => {
JSON.stringify([{ b: 'b1', a: 'a1' }, 3], null, 2)
);
});

it('should return correctly filtered array filtered by nested values', () => {
const parseResult = TemplateParser(
false,
'{{{ stringify (filter (array (object a=(object b="b1)) (object a=(object b="b2) object a=(object b="b1)) (object a=(object b="b1) ) }}}',
{} as any,
[],
{} as any
);
expect(parseResult).to.be.equal(
JSON.stringify([{ b: 'b1', a: 'a1' }, 3], null, 2)
);
});
});
});

0 comments on commit cafb48e

Please sign in to comment.