From 2318082bb8ac0106523edb8cd8159252c2fe976a Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 26 Aug 2025 14:54:24 -0700 Subject: [PATCH] fix advanced matching --- .../service/infrastructure/networkService.js | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/server/src/service/infrastructure/networkService.js b/server/src/service/infrastructure/networkService.js index c90096d7c..72a117e74 100644 --- a/server/src/service/infrastructure/networkService.js +++ b/server/src/service/infrastructure/networkService.js @@ -1,3 +1,5 @@ +import { match } from "assert"; + const SERVICE_NAME = "NetworkService"; class NetworkService { @@ -147,16 +149,24 @@ class NetworkService { httpResponse.payload = payload; httpResponse.timings = response.timings || {}; - if (!expectedValue) { + if (!expectedValue && !jsonPath) { return httpResponse; } - this.logger.info({ - service: this.SERVICE_NAME, - method: "requestHttp", - message: `Job: [${name}](${_id}) match result with expected value`, - details: { expectedValue, payload, jsonPath, matchMethod }, - }); + if (expectedValue) { + let ok = false; + if (matchMethod === "equal") ok = payload === expectedValue; + if (matchMethod === "include") ok = payload.includes(expectedValue); + if (matchMethod === "regex") ok = new RegExp(expectedValue).test(payload); + + if (ok === true) { + return httpResponse; + } else { + httpResponse.code = 500; + httpResponse.status = false; + return httpResponse; + } + } if (jsonPath) { const contentType = response.headers["content-type"];