From 7d8fb76723c7df0a9121006d1deee16e6dadc934 Mon Sep 17 00:00:00 2001 From: Florian Treml Date: Tue, 11 Oct 2022 10:46:36 +0200 Subject: [PATCH 1/2] BOT-3336 allow empty JSONPath assertion --- src/scripting/logichook/LogicHookUtils.js | 6 +++--- .../logichook/asserter/JsonPathAsserter.js | 7 ++++--- test/scripting/asserters/jsonpathAsserter.spec.js | 14 +++++++------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/scripting/logichook/LogicHookUtils.js b/src/scripting/logichook/LogicHookUtils.js index ba0ff4a9..1db68c62 100644 --- a/src/scripting/logichook/LogicHookUtils.js +++ b/src/scripting/logichook/LogicHookUtils.js @@ -111,19 +111,19 @@ module.exports = class LogicHookUtils { // 1 gives possibility to use default asserter as global asserter if (hookType === 'asserter') { - const asserter = DEFAULT_ASSERTERS.find(asserter => src === asserter.className) + const asserter = DEFAULT_ASSERTERS.find(asserter => src === asserter.className || src === asserter.name) if (asserter) { return new (asserter.Class)({ ref, ...this.buildScriptContext }, this.caps, args) } } if (hookType === 'logichook') { - const lh = DEFAULT_LOGIC_HOOKS.find(lh => src === lh.className) + const lh = DEFAULT_LOGIC_HOOKS.find(lh => src === lh.className || src === lh.name) if (lh) { return new (lh.Class)({ ref, ...this.buildScriptContext }, this.caps, args) } } if (hookType === 'userinput') { - const ui = DEFAULT_USER_INPUTS.find(ui => src === ui.className) + const ui = DEFAULT_USER_INPUTS.find(ui => src === ui.className || src === ui.name) if (ui) { return new (ui.Class)({ ref, ...this.buildScriptContext }, this.caps, args) } diff --git a/src/scripting/logichook/asserter/JsonPathAsserter.js b/src/scripting/logichook/asserter/JsonPathAsserter.js index c9deafdb..634c1c12 100644 --- a/src/scripting/logichook/asserter/JsonPathAsserter.js +++ b/src/scripting/logichook/asserter/JsonPathAsserter.js @@ -126,7 +126,8 @@ module.exports = class JsonPathAsserter { )) } } - if (assert) { + + if (!_.isNil(assert)) { const actual = (_.isArray(jsonPathValues) && jsonPathValues.length === 1) ? jsonPathValues[0] : jsonPathValues let matchFn = this.context.Match @@ -137,7 +138,7 @@ module.exports = class JsonPathAsserter { const match = jsonPathValues.find(a => matchFn(a, assert)) if (not && match) { - return Promise.reject(new BotiumError(`${convoStep.stepTag}: Not expected: ${toString(actual)} in jsonPath ${path}"`, + return Promise.reject(new BotiumError(`${convoStep.stepTag}: Not expected: "${toString(actual)}" in jsonPath ${path}"`, { type: 'asserter', source: this.name, @@ -158,7 +159,7 @@ module.exports = class JsonPathAsserter { )) } if (!not && !match) { - return Promise.reject(new BotiumError(`${convoStep.stepTag}: Expected: ${assert} in jsonPath ${path}: Actual: ${toString(actual)}`, + return Promise.reject(new BotiumError(`${convoStep.stepTag}: Expected: "${assert}" in jsonPath ${path}, actual: ${toString(actual)}`, { type: 'asserter', source: this.name, diff --git a/test/scripting/asserters/jsonpathAsserter.spec.js b/test/scripting/asserters/jsonpathAsserter.spec.js index d1c95be4..f3b9094f 100644 --- a/test/scripting/asserters/jsonpathAsserter.spec.js +++ b/test/scripting/asserters/jsonpathAsserter.spec.js @@ -63,7 +63,7 @@ describe('scripting.asserters.jsonPathAsserter', function () { }) } catch (err) { console.log(err.message) - assert.isTrue(err.message.includes('Expected: message4 in jsonPath $.messages[*].label: Actual: message1,message2,message3')) + assert.isTrue(err.message.includes('Expected: "message4" in jsonPath $.messages[*].label, actual: message1,message2,message3')) } }) it('should fail on not existing jsonpath', async function () { @@ -133,7 +133,7 @@ describe('scripting.asserters.jsonPathAsserter', function () { } }) } catch (err) { - assert.isTrue(err.message.indexOf('Expected: {"label":"message2"} in jsonPath $.messages[0]: Actual: {"label":"message1"}') > 0) + assert.isTrue(err.message.indexOf('Expected: "{"label":"message2"}" in jsonPath $.messages[0], actual: {"label":"message1"}') > 0) assert.isNotNull(err.context) assert.isNotNull(err.context.cause) assert.isNotTrue(err.context.cause.not) @@ -155,7 +155,7 @@ describe('scripting.asserters.jsonPathAsserter', function () { }) assert.fail('should have failed') } catch (err) { - assert.isTrue(err.message.indexOf('Expected: test2 in jsonPath $.test') > 0) + assert.isTrue(err.message.indexOf('Expected: "test2" in jsonPath $.test') > 0) assert.isNotNull(err.context) assert.isNotNull(err.context.cause) assert.isNotTrue(err.context.cause.not) @@ -196,7 +196,7 @@ describe('scripting.asserters.jsonPathAsserter', function () { }) assert.fail('should have failed') } catch (err) { - assert.isTrue(err.message.indexOf('Not expected: test1 in jsonPath $.test') > 0) + assert.isTrue(err.message.indexOf('Not expected: "test1" in jsonPath $.test') > 0) assert.isNotNull(err.context) assert.isNotNull(err.context.cause) assert.isTrue(err.context.cause.not) @@ -252,7 +252,7 @@ describe('scripting.asserters.jsonPathAsserter', function () { }) assert.fail('should have failed') } catch (err) { - assert.isTrue(err.message.indexOf('Expected: test2 in jsonPath $.test') > 0) + assert.isTrue(err.message.indexOf('Expected: "test2" in jsonPath $.test') > 0) assert.isNotNull(err.context) assert.isNotNull(err.context.cause) assert.isNotTrue(err.context.cause.not) @@ -332,7 +332,7 @@ describe('scripting.asserters.jsonPathAsserter', function () { }) assert.fail('should have failed') } catch (err) { - assert.isTrue(err.message.indexOf('Expected: value in jsonPath $.test') > 0) + assert.isTrue(err.message.indexOf('Expected: "value" in jsonPath $.test') > 0) } }) it('should succeed on setting matching mode in global args', async function () { @@ -373,7 +373,7 @@ describe('scripting.asserters.jsonPathAsserter', function () { }) assert.fail('should have failed') } catch (err) { - assert.isTrue(err.message.indexOf('Expected: value1 in jsonPath $.test') > 0) + assert.isTrue(err.message.indexOf('Expected: "value1" in jsonPath $.test') > 0) } }) }) From e5d83eb95b8799ce3789851abc8e9c9613bd1060 Mon Sep 17 00:00:00 2001 From: Florian Treml Date: Tue, 11 Oct 2022 11:55:03 +0200 Subject: [PATCH 2/2] Version Bump --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1b8451d3..76d895f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "botium-core", - "version": "1.13.6", + "version": "1.13.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 55e7c83e..bfce596f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "botium-core", - "version": "1.13.6", + "version": "1.13.7", "description": "The Selenium for Chatbots", "main": "index.js", "module": "dist/botium-es.js",