Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions projects/lib/utils/utils/resource-field-by-path.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ describe('getResourceValueByJsonPath', () => {
expect(result).toBe('test-result');
});

it('should query resource using jsonPathExpression', () => {
(jsonpath.query as jest.Mock).mockReturnValue(['test-result']);

const result = getResourceValueByJsonPath(mockResource, {
jsonPathExpression: '$.spec.value',
});

expect(jsonpath.query).toHaveBeenCalledWith(mockResource, '$.spec.value');
expect(result).toBe('test-result');
});

it('should query resource using property', () => {
(jsonpath.query as jest.Mock).mockReturnValue(['property-result']);

Expand Down
3 changes: 2 additions & 1 deletion projects/lib/utils/utils/resource-field-by-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const getResourceValueByJsonPath = (
return undefined;
}

const queryResult = jsonpath.query(resource, `$.${property}`);
const prefix = property.startsWith('$.') ? '' : '$.';
const queryResult = jsonpath.query(resource, `${prefix}${property}`);
const value = queryResult.length ? queryResult[0] : undefined;

if (value && field.propertyField) {
Expand Down