Skip to content

Commit

Permalink
fix: we now allow empty lambda operations (#822)
Browse files Browse the repository at this point in the history
The code was always expecting an expression.
Fixes internal issue 247
  • Loading branch information
nlunets committed Jun 6, 2024
1 parent b7112e8 commit 35c9236
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/ten-bags-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-ux/fe-mockserver-core': patch
---

fix: allow empty lambda operations
5 changes: 4 additions & 1 deletion packages/fe-mockserver-core/src/data/entitySets/entitySet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ export class MockDataEntitySet implements EntitySetInterface {
if (!Array.isArray(mockDataToCheckValue)) {
mockDataToCheckValue = [mockDataToCheckValue];
}
if (expression.expression.expressions) {
if (expression.expression?.expressions) {
expression.expression.expressions.forEach((entry: any) => {
const replaceValue = expression.propertyPath || expression.target;
if (typeof entry.identifier === 'string') {
Expand All @@ -426,6 +426,9 @@ export class MockDataEntitySet implements EntitySetInterface {
);
}
});
} else {
// no expressions, so empty lambda
return true;
}

const check = (subMockData: any) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/fe-mockserver-core/test/unit/data/entitySet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ describe('EntitySet', () => {
expect(filteredData).toBe(false);
filteredData = myEntitySet.checkFilter(mockData[3], v4ComplexLambda, 'default', fakeRequest);
expect(filteredData).toBe(false);
const v4SimpleLambda = parseFilter('ArrayData/any()')!;
filteredData = myEntitySet.checkFilter(mockData[0], v4SimpleLambda, 'default', fakeRequest);
expect(filteredData).toBe(true);
});
it('works on deep lambda expression with methods', async () => {
const myEntitySet = new MockDataEntitySet(
Expand Down

0 comments on commit 35c9236

Please sign in to comment.