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 020e102
Show file tree
Hide file tree
Showing 2 changed files with 25 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,29 @@ describe('Template parser', () => {
JSON.stringify([{ b: 'b1', a: 'a1' }, 3], null, 2)
);
});

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

it('should return correctly return array filtered array when nested value not equals', () => {
const parseResult = TemplateParser(
false,
'{{{ stringify (filter (array (object parent=(object child="child-val") b="b1") (object parent=(object child="child-val2") b="b2") 2 3) (object parent="parent-val")) }}}',
{} as any,
[],
{} as any
);
expect(parseResult).to.be.equal(JSON.stringify([], null, 2));
});
});
});

0 comments on commit 020e102

Please sign in to comment.