From 82352910bf50687fdabae5c9bd139f46fc4df4fc Mon Sep 17 00:00:00 2001 From: Matt Visnovsky Date: Mon, 10 Jun 2024 12:25:55 -0600 Subject: [PATCH] Fix: Cast to string then eval --- src/util.js | 12 ++++++------ src/util.ts | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/util.js b/src/util.js index ca09bdbc7..fb77cc957 100644 --- a/src/util.js +++ b/src/util.js @@ -413,24 +413,24 @@ async function evaluateJsonQuery(data, jsonPath, jsonPathOperator, expectedValue case ">=": case "<": case "<=": - jsonQueryExpression = `$.value ${jsonPathOperator} $.expected`; + jsonQueryExpression = `$number($.value) ${jsonPathOperator} $number($.expected)`; break; case "!=": - jsonQueryExpression = "$string($.value) != $string($.expected)"; + jsonQueryExpression = "$.value != $.expected"; break; case "==": - jsonQueryExpression = "$string($.value) = $string($.expected)"; + jsonQueryExpression = "$.value = $.expected"; break; case "contains": - jsonQueryExpression = "$contains($string($.value), $string($.expected))"; + jsonQueryExpression = "$contains($.value, $.expected)"; break; default: throw new Error(`Invalid condition ${jsonPathOperator}`); } const expression = jsonata(jsonQueryExpression); const status = await expression.evaluate({ - value: response, - expected: expectedValue + value: response.toString(), + expected: expectedValue.toString() }); if (response === undefined || status === undefined) { throw new Error("Query evaluation returned undefined. Check query syntax and the structure of the response data"); diff --git a/src/util.ts b/src/util.ts index 751424dbd..8c67090b0 100644 --- a/src/util.ts +++ b/src/util.ts @@ -674,16 +674,16 @@ export async function evaluateJsonQuery(data: any, jsonPath: string, jsonPathOpe case ">=": case "<": case "<=": - jsonQueryExpression = `$.value ${jsonPathOperator} $.expected`; + jsonQueryExpression = `$number($.value) ${jsonPathOperator} $number($.expected)`; break; case "!=": - jsonQueryExpression = "$string($.value) != $string($.expected)"; + jsonQueryExpression = "$.value != $.expected"; break; case "==": - jsonQueryExpression = "$string($.value) = $string($.expected)"; + jsonQueryExpression = "$.value = $.expected"; break; case "contains": - jsonQueryExpression = "$contains($string($.value), $string($.expected))"; + jsonQueryExpression = "$contains($.value, $.expected)"; break; default: throw new Error(`Invalid condition ${jsonPathOperator}`); @@ -692,8 +692,8 @@ export async function evaluateJsonQuery(data: any, jsonPath: string, jsonPathOpe // Evaluate the JSON Query Expression const expression = jsonata(jsonQueryExpression); const status = await expression.evaluate({ - value: response, - expected: expectedValue + value: response.toString(), + expected: expectedValue.toString() }); if (response === undefined || status === undefined) {