Merge pull request #2862 from bluewave-labs/fix/advanced-matching
fix: advanced matching
This commit is contained in:
1 file changed
+17
-7
@@ -1,3 +1,5 @@
|
|||||||
|
import { match } from "assert";
|
||||||
|
|
||||||
const SERVICE_NAME = "NetworkService";
|
const SERVICE_NAME = "NetworkService";
|
||||||
|
|
||||||
class NetworkService {
|
class NetworkService {
|
||||||
@@ -147,16 +149,24 @@ class NetworkService {
|
|||||||
httpResponse.payload = payload;
|
httpResponse.payload = payload;
|
||||||
httpResponse.timings = response.timings || {};
|
httpResponse.timings = response.timings || {};
|
||||||
|
|
||||||
if (!expectedValue) {
|
if (!expectedValue && !jsonPath) {
|
||||||
return httpResponse;
|
return httpResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.info({
|
if (expectedValue) {
|
||||||
service: this.SERVICE_NAME,
|
let ok = false;
|
||||||
method: "requestHttp",
|
if (matchMethod === "equal") ok = payload === expectedValue;
|
||||||
message: `Job: [${name}](${_id}) match result with expected value`,
|
if (matchMethod === "include") ok = payload.includes(expectedValue);
|
||||||
details: { expectedValue, payload, jsonPath, matchMethod },
|
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) {
|
if (jsonPath) {
|
||||||
const contentType = response.headers["content-type"];
|
const contentType = response.headers["content-type"];
|
||||||
|
|||||||
Reference in new issue
Block a user