botium-core 1.13.2 → 1.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +6 -3
- package/dist/botium-cjs.js +214 -61
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +213 -61
- package/dist/botium-es.js.map +1 -1
- package/package.json +3 -1
- package/src/Capabilities.js +2 -1
- package/src/containers/plugins/SimpleRestContainer.js +20 -16
- package/src/grid/inbound/proxy.js +2 -1
- package/src/scripting/Convo.js +16 -10
- package/src/scripting/MatchFunctions.js +10 -0
- package/src/scripting/ScriptingProvider.js +106 -37
- package/src/scripting/logichook/LogicHookConsts.js +1 -1
- package/src/scripting/logichook/asserter/WerAsserter.js +59 -0
- package/src/scripting/logichook/logichooks/UpdateCustomLogicHook.js +3 -2
- package/test/compiler/compilercsv.spec.js +104 -3
- package/test/compiler/compilerjson.spec.js +0 -2
- package/test/compiler/compilerxlsx.spec.js +1 -1
- package/test/compiler/convos/csv/utterances_liveperson2.csv +12 -0
- package/test/connectors/simplerest.spec.js +1012 -969
- package/test/convo/fillAndApplyScriptingMemory.spec.js +804 -785
- package/test/convo/partialconvo.spec.js +345 -339
- package/test/driver/capabilities.spec.js +156 -151
- package/test/logichooks/hookfromsrc.spec.js +79 -73
- package/test/plugins/plugins.spec.js +44 -42
- package/test/scripting/asserters/buttonsAsserter.spec.js +257 -240
- package/test/scripting/asserters/cardsAsserter.spec.js +214 -212
- package/test/scripting/asserters/convos/wer_threshold_nok.yml +7 -0
- package/test/scripting/asserters/convos/wer_threshold_ok.yml +7 -0
- package/test/scripting/asserters/intentConfidenceAsserter.spec.js +34 -35
- package/test/scripting/asserters/jsonpathAsserter.spec.js +307 -308
- package/test/scripting/asserters/mediaAsserter.spec.js +236 -234
- package/test/scripting/asserters/werAsserter.spec.js +51 -0
- package/test/scripting/logichooks/setClearScriptingMemory.spec.js +202 -192
- package/test/scripting/matching/matchingmode.spec.js +306 -258
- package/test/scripting/scriptingProvider.spec.js +666 -633
- package/test/scripting/scriptingmemory/fillScriptingMemoryFromFile.spec.js +299 -281
- package/test/scripting/scriptingmemory/useScriptingMemoryForAssertion.spec.js +94 -80
- package/test/scripting/userinputs/defaultUserInputs.spec.js +233 -127
- package/test/scripting/userinputs/mediaInputConvos.spec.js +409 -403
- package/test/scripting/utteranceexpansion/associateByIndex.spec.js +259 -0
- package/test/scripting/utteranceexpansion/convos/associate_utterances_by_index.json +33 -0
- package/test/scripting/utteranceexpansion/convos/media.convo.txt +19 -0
- package/test/scripting/utteranceexpansion/files/step0voice0.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step0voice1.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step0voice2.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step1voice0.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice0.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice1.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice2.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice4.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice5.wav +0 -0
- package/test/security/allowUnsafe.spec.js +274 -268
- package/test/utils.spec.js +40 -38
|
@@ -4,52 +4,37 @@ const JsonPathCountAsserter = require('../../../src/scripting/logichook/asserter
|
|
|
4
4
|
const { getMatchFunction } = require('../../../src/scripting/MatchFunctions')
|
|
5
5
|
|
|
6
6
|
describe('scripting.asserters.jsonPathAsserter', function () {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
describe('jsonPathAsserter', function () {
|
|
8
|
+
beforeEach(async function () {
|
|
9
|
+
this.jsonPathAsserter = new JsonPathAsserter({
|
|
10
|
+
Match: (botresponse, utterance) => botresponse.toLowerCase().indexOf(utterance.toLowerCase()) >= 0
|
|
11
|
+
}, {})
|
|
12
|
+
this.jsonPathAsserterWildcard = new JsonPathAsserter({
|
|
13
|
+
Match: getMatchFunction('wildcardIgnoreCase')
|
|
14
|
+
}, {})
|
|
15
|
+
this.jsonPathAsserterGlobalArgs = new JsonPathAsserter({
|
|
16
|
+
Match: (botresponse, utterance) => botresponse.toLowerCase().indexOf(utterance.toLowerCase()) >= 0
|
|
17
|
+
}, {}, { path: '$.test' })
|
|
18
|
+
})
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
})
|
|
22
|
-
it('should succeed on existing jsonpath', async function () {
|
|
23
|
-
await this.jsonPathAsserter.assertConvoStep({
|
|
24
|
-
convoStep: { stepTag: 'test' },
|
|
25
|
-
args: ['$.test'],
|
|
26
|
-
botMsg: {
|
|
27
|
-
sourceData: {
|
|
28
|
-
test: true
|
|
29
|
-
}
|
|
30
|
-
}
|
|
20
|
+
it('should do nothing on no arg', async function () {
|
|
21
|
+
await this.jsonPathAsserter.assertConvoStep({})
|
|
31
22
|
})
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
{ label: 'message1' },
|
|
41
|
-
{ label: 'message2' },
|
|
42
|
-
{ label: 'message3' }
|
|
43
|
-
]
|
|
23
|
+
it('should succeed on existing jsonpath', async function () {
|
|
24
|
+
await this.jsonPathAsserter.assertConvoStep({
|
|
25
|
+
convoStep: { stepTag: 'test' },
|
|
26
|
+
args: ['$.test'],
|
|
27
|
+
botMsg: {
|
|
28
|
+
sourceData: {
|
|
29
|
+
test: true
|
|
30
|
+
}
|
|
44
31
|
}
|
|
45
|
-
}
|
|
32
|
+
})
|
|
46
33
|
})
|
|
47
|
-
|
|
48
|
-
it('should fail on not any existing jsonpath', async function () {
|
|
49
|
-
try {
|
|
34
|
+
it('should succeed on any existing jsonpath', async function () {
|
|
50
35
|
await this.jsonPathAsserter.assertConvoStep({
|
|
51
36
|
convoStep: { stepTag: 'test' },
|
|
52
|
-
args: ['$.messages[*].label', '
|
|
37
|
+
args: ['$.messages[*].label', 'message3'],
|
|
53
38
|
botMsg: {
|
|
54
39
|
sourceData: {
|
|
55
40
|
messages: [
|
|
@@ -60,68 +45,67 @@ describe('scripting.asserters.jsonPathAsserter', function () {
|
|
|
60
45
|
}
|
|
61
46
|
}
|
|
62
47
|
})
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
48
|
+
})
|
|
49
|
+
it('should fail on not any existing jsonpath', async function () {
|
|
50
|
+
try {
|
|
51
|
+
await this.jsonPathAsserter.assertConvoStep({
|
|
52
|
+
convoStep: { stepTag: 'test' },
|
|
53
|
+
args: ['$.messages[*].label', 'message4'],
|
|
54
|
+
botMsg: {
|
|
55
|
+
sourceData: {
|
|
56
|
+
messages: [
|
|
57
|
+
{ label: 'message1' },
|
|
58
|
+
{ label: 'message2' },
|
|
59
|
+
{ label: 'message3' }
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.log(err.message)
|
|
66
|
+
assert.isTrue(err.message.includes('Expected: message4 in jsonPath $.messages[*].label: Actual: message1,message2,message3'))
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
it('should fail on not existing jsonpath', async function () {
|
|
70
|
+
try {
|
|
71
|
+
await this.jsonPathAsserter.assertConvoStep({
|
|
72
|
+
convoStep: { stepTag: 'test' },
|
|
73
|
+
args: ['$.test'],
|
|
74
|
+
botMsg: {
|
|
75
|
+
sourceData: {}
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
assert.fail('expected jsonPathAsserter to fail')
|
|
79
|
+
} catch (err) {
|
|
80
|
+
assert.isTrue(err.message.includes('Could not find any element in jsonPath $.test'))
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
it('should succeed on matching jsonpath', async function () {
|
|
70
84
|
await this.jsonPathAsserter.assertConvoStep({
|
|
71
85
|
convoStep: { stepTag: 'test' },
|
|
72
|
-
args: ['$.test'],
|
|
86
|
+
args: ['$.test', 'test'],
|
|
73
87
|
botMsg: {
|
|
74
88
|
sourceData: {
|
|
89
|
+
test: 'test'
|
|
75
90
|
}
|
|
76
91
|
}
|
|
77
92
|
})
|
|
78
|
-
assert.fail('expected jsonPathAsserter to fail')
|
|
79
|
-
} catch (err) {
|
|
80
|
-
assert.isTrue(err.message.includes('Could not find any element in jsonPath $.test'))
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
it('should succeed on matching jsonpath', async function () {
|
|
84
|
-
await this.jsonPathAsserter.assertConvoStep({
|
|
85
|
-
convoStep: { stepTag: 'test' },
|
|
86
|
-
args: ['$.test', 'test'],
|
|
87
|
-
botMsg: {
|
|
88
|
-
sourceData: {
|
|
89
|
-
test: 'test'
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
93
|
})
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
})
|
|
104
|
-
})
|
|
105
|
-
it('should succeed on jsonpath object', async function () {
|
|
106
|
-
await this.jsonPathAsserterWildcard.assertConvoStep({
|
|
107
|
-
convoStep: { stepTag: 'test' },
|
|
108
|
-
args: ['$.messages[0]', '{"label":"message1"}'],
|
|
109
|
-
botMsg: {
|
|
110
|
-
sourceData: {
|
|
111
|
-
messages: [
|
|
112
|
-
{ label: 'message1' },
|
|
113
|
-
{ label: 'message2' },
|
|
114
|
-
{ label: 'message3' }
|
|
115
|
-
]
|
|
94
|
+
it('should succeed on matching jsonpath array', async function () {
|
|
95
|
+
await this.jsonPathAsserter.assertConvoStep({
|
|
96
|
+
convoStep: { stepTag: 'test' },
|
|
97
|
+
args: ['$.test[0]', 'test'],
|
|
98
|
+
botMsg: {
|
|
99
|
+
sourceData: {
|
|
100
|
+
test: ['test']
|
|
101
|
+
}
|
|
116
102
|
}
|
|
117
|
-
}
|
|
103
|
+
})
|
|
118
104
|
})
|
|
119
|
-
|
|
120
|
-
it('should fail on invalid jsonpath object', async function () {
|
|
121
|
-
try {
|
|
105
|
+
it('should succeed on jsonpath object', async function () {
|
|
122
106
|
await this.jsonPathAsserterWildcard.assertConvoStep({
|
|
123
107
|
convoStep: { stepTag: 'test' },
|
|
124
|
-
args: ['$.messages[0]', '{"label":"
|
|
108
|
+
args: ['$.messages[0]', '{"label":"message1"}'],
|
|
125
109
|
botMsg: {
|
|
126
110
|
sourceData: {
|
|
127
111
|
messages: [
|
|
@@ -132,295 +116,310 @@ describe('scripting.asserters.jsonPathAsserter', function () {
|
|
|
132
116
|
}
|
|
133
117
|
}
|
|
134
118
|
})
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
119
|
+
})
|
|
120
|
+
it('should fail on invalid jsonpath object', async function () {
|
|
121
|
+
try {
|
|
122
|
+
await this.jsonPathAsserterWildcard.assertConvoStep({
|
|
123
|
+
convoStep: { stepTag: 'test' },
|
|
124
|
+
args: ['$.messages[0]', '{"label":"message2"}'],
|
|
125
|
+
botMsg: {
|
|
126
|
+
sourceData: {
|
|
127
|
+
messages: [
|
|
128
|
+
{ label: 'message1' },
|
|
129
|
+
{ label: 'message2' },
|
|
130
|
+
{ label: 'message3' }
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
} catch (err) {
|
|
136
|
+
assert.isTrue(err.message.indexOf('Expected: {"label":"message2"} in jsonPath $.messages[0]: Actual: {"label":"message1"}') > 0)
|
|
137
|
+
assert.isNotNull(err.context)
|
|
138
|
+
assert.isNotNull(err.context.cause)
|
|
139
|
+
assert.isNotTrue(err.context.cause.not)
|
|
140
|
+
assert.equal(err.context.cause.expected, '{"label":"message2"}')
|
|
141
|
+
assert.deepEqual(err.context.cause.actual, { label: 'message1' })
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
145
|
+
it('should fail on not matching jsonpath', async function () {
|
|
146
|
+
try {
|
|
147
|
+
await this.jsonPathAsserter.assertConvoStep({
|
|
148
|
+
convoStep: { stepTag: 'test' },
|
|
149
|
+
args: ['$.test', 'test2'],
|
|
150
|
+
botMsg: {
|
|
151
|
+
sourceData: {
|
|
152
|
+
test: 'test1'
|
|
153
|
+
}
|
|
153
154
|
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
assert.equal(err.context.cause.actual, 'test1')
|
|
164
|
-
}
|
|
165
|
-
})
|
|
166
|
-
it('should succeed on non existing jsonpath', async function () {
|
|
167
|
-
await this.jsonPathAsserter.assertNotConvoStep({
|
|
168
|
-
convoStep: { stepTag: 'test' },
|
|
169
|
-
args: ['$.test'],
|
|
170
|
-
botMsg: {
|
|
171
|
-
sourceData: {
|
|
172
|
-
}
|
|
155
|
+
})
|
|
156
|
+
assert.fail('should have failed')
|
|
157
|
+
} catch (err) {
|
|
158
|
+
assert.isTrue(err.message.indexOf('Expected: test2 in jsonPath $.test') > 0)
|
|
159
|
+
assert.isNotNull(err.context)
|
|
160
|
+
assert.isNotNull(err.context.cause)
|
|
161
|
+
assert.isNotTrue(err.context.cause.not)
|
|
162
|
+
assert.equal(err.context.cause.expected, 'test2')
|
|
163
|
+
assert.equal(err.context.cause.actual, 'test1')
|
|
173
164
|
}
|
|
174
165
|
})
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
sourceData: {
|
|
182
|
-
test: 'test1'
|
|
166
|
+
it('should succeed on non existing jsonpath', async function () {
|
|
167
|
+
await this.jsonPathAsserter.assertNotConvoStep({
|
|
168
|
+
convoStep: { stepTag: 'test' },
|
|
169
|
+
args: ['$.test'],
|
|
170
|
+
botMsg: {
|
|
171
|
+
sourceData: {}
|
|
183
172
|
}
|
|
184
|
-
}
|
|
173
|
+
})
|
|
185
174
|
})
|
|
186
|
-
|
|
187
|
-
it('should fail on matching jsonpath', async function () {
|
|
188
|
-
try {
|
|
175
|
+
it('should succeed on non matching jsonpath', async function () {
|
|
189
176
|
await this.jsonPathAsserter.assertNotConvoStep({
|
|
190
177
|
convoStep: { stepTag: 'test' },
|
|
191
|
-
args: ['$.test', '
|
|
178
|
+
args: ['$.test', 'test2'],
|
|
192
179
|
botMsg: {
|
|
193
180
|
sourceData: {
|
|
194
181
|
test: 'test1'
|
|
195
182
|
}
|
|
196
183
|
}
|
|
197
184
|
})
|
|
198
|
-
assert.fail('should have failed')
|
|
199
|
-
} catch (err) {
|
|
200
|
-
assert.isTrue(err.message.indexOf('Not expected: test1 in jsonPath $.test') > 0)
|
|
201
|
-
assert.isNotNull(err.context)
|
|
202
|
-
assert.isNotNull(err.context.cause)
|
|
203
|
-
assert.isTrue(err.context.cause.not)
|
|
204
|
-
assert.equal(err.context.cause.expected, 'test1')
|
|
205
|
-
assert.equal(err.context.cause.actual, 'test1')
|
|
206
|
-
}
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
it('should succeed on existing jsonpath from globalArgs', async function () {
|
|
210
|
-
await this.jsonPathAsserterGlobalArgs.assertConvoStep({
|
|
211
|
-
convoStep: { stepTag: 'test' },
|
|
212
|
-
botMsg: {
|
|
213
|
-
sourceData: {
|
|
214
|
-
test: true
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
185
|
})
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
186
|
+
it('should fail on matching jsonpath', async function () {
|
|
187
|
+
try {
|
|
188
|
+
await this.jsonPathAsserter.assertNotConvoStep({
|
|
189
|
+
convoStep: { stepTag: 'test' },
|
|
190
|
+
args: ['$.test', 'test1'],
|
|
191
|
+
botMsg: {
|
|
192
|
+
sourceData: {
|
|
193
|
+
test: 'test1'
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
})
|
|
197
|
+
assert.fail('should have failed')
|
|
198
|
+
} catch (err) {
|
|
199
|
+
assert.isTrue(err.message.indexOf('Not expected: test1 in jsonPath $.test') > 0)
|
|
200
|
+
assert.isNotNull(err.context)
|
|
201
|
+
assert.isNotNull(err.context.cause)
|
|
202
|
+
assert.isTrue(err.context.cause.not)
|
|
203
|
+
assert.equal(err.context.cause.expected, 'test1')
|
|
204
|
+
assert.equal(err.context.cause.actual, 'test1')
|
|
227
205
|
}
|
|
228
206
|
})
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
try {
|
|
207
|
+
|
|
208
|
+
it('should succeed on existing jsonpath from globalArgs', async function () {
|
|
232
209
|
await this.jsonPathAsserterGlobalArgs.assertConvoStep({
|
|
233
210
|
convoStep: { stepTag: 'test' },
|
|
234
211
|
botMsg: {
|
|
235
212
|
sourceData: {
|
|
213
|
+
test: true
|
|
236
214
|
}
|
|
237
215
|
}
|
|
238
216
|
})
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
})
|
|
244
|
-
it('should fail on not matching jsonpath from globalArgs', async function () {
|
|
245
|
-
try {
|
|
246
|
-
await this.jsonPathAsserterGlobalArgs.assertConvoStep({
|
|
217
|
+
})
|
|
218
|
+
it('should succeed on matching jsonpath from globalArgs', async function () {
|
|
219
|
+
await this.jsonPathAsserter.assertConvoStep({
|
|
247
220
|
convoStep: { stepTag: 'test' },
|
|
248
|
-
args: ['
|
|
221
|
+
args: ['test'],
|
|
249
222
|
botMsg: {
|
|
250
223
|
sourceData: {
|
|
251
|
-
test: '
|
|
224
|
+
test: 'test'
|
|
252
225
|
}
|
|
253
226
|
}
|
|
254
227
|
})
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
228
|
+
})
|
|
229
|
+
it('should fail on not existing jsonpath from globalArgs', async function () {
|
|
230
|
+
try {
|
|
231
|
+
await this.jsonPathAsserterGlobalArgs.assertConvoStep({
|
|
232
|
+
convoStep: { stepTag: 'test' },
|
|
233
|
+
botMsg: {
|
|
234
|
+
sourceData: {}
|
|
235
|
+
}
|
|
236
|
+
})
|
|
237
|
+
assert.fail('expected jsonPathAsserter to fail')
|
|
238
|
+
} catch (err) {
|
|
239
|
+
assert.isTrue(err.message.includes('Could not find any element in jsonPath $.test'))
|
|
240
|
+
}
|
|
241
|
+
})
|
|
242
|
+
it('should fail on not matching jsonpath from globalArgs', async function () {
|
|
243
|
+
try {
|
|
244
|
+
await this.jsonPathAsserterGlobalArgs.assertConvoStep({
|
|
245
|
+
convoStep: { stepTag: 'test' },
|
|
246
|
+
args: ['test2'],
|
|
247
|
+
botMsg: {
|
|
248
|
+
sourceData: {
|
|
249
|
+
test: 'test1'
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
})
|
|
253
|
+
assert.fail('should have failed')
|
|
254
|
+
} catch (err) {
|
|
255
|
+
assert.isTrue(err.message.indexOf('Expected: test2 in jsonPath $.test') > 0)
|
|
256
|
+
assert.isNotNull(err.context)
|
|
257
|
+
assert.isNotNull(err.context.cause)
|
|
258
|
+
assert.isNotTrue(err.context.cause.not)
|
|
259
|
+
assert.equal(err.context.cause.expected, 'test2')
|
|
260
|
+
assert.equal(err.context.cause.actual, 'test1')
|
|
261
|
+
}
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
it('should fail on invalid arg length from pathPattern', async function () {
|
|
265
|
+
this.jsonPathAsserter.globalArgs = {
|
|
266
|
+
argCount: 0,
|
|
267
|
+
pathTemplate: '$.test'
|
|
268
|
+
}
|
|
269
|
+
try {
|
|
270
|
+
await this.jsonPathAsserter.assertConvoStep({
|
|
271
|
+
convoStep: { stepTag: 'test' },
|
|
272
|
+
args: ['test2'],
|
|
273
|
+
botMsg: {
|
|
274
|
+
sourceData: {
|
|
275
|
+
test: 'test1'
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
})
|
|
279
|
+
assert.fail('should have failed')
|
|
280
|
+
} catch (err) {
|
|
281
|
+
assert.isTrue(err.message.indexOf('JsonPathAsserter 0 arguments expected') > 0)
|
|
282
|
+
}
|
|
283
|
+
})
|
|
284
|
+
it('should succeed on existing jsonpath from pathPattern', async function () {
|
|
285
|
+
this.jsonPathAsserter.globalArgs = {
|
|
286
|
+
argCount: 1,
|
|
287
|
+
pathTemplate: '$.{{args.0}}'
|
|
288
|
+
}
|
|
265
289
|
|
|
266
|
-
it('should fail on invalid arg length from pathPattern', async function () {
|
|
267
|
-
this.jsonPathAsserter.globalArgs = {
|
|
268
|
-
argCount: 0,
|
|
269
|
-
pathTemplate: '$.test'
|
|
270
|
-
}
|
|
271
|
-
try {
|
|
272
290
|
await this.jsonPathAsserter.assertConvoStep({
|
|
273
291
|
convoStep: { stepTag: 'test' },
|
|
274
|
-
args: ['
|
|
292
|
+
args: ['test'],
|
|
275
293
|
botMsg: {
|
|
276
294
|
sourceData: {
|
|
277
|
-
test:
|
|
295
|
+
test: true
|
|
278
296
|
}
|
|
279
297
|
}
|
|
280
298
|
})
|
|
281
|
-
assert.fail('should have failed')
|
|
282
|
-
} catch (err) {
|
|
283
|
-
assert.isTrue(err.message.indexOf('JsonPathAsserter 0 arguments expected') > 0)
|
|
284
|
-
}
|
|
285
|
-
})
|
|
286
|
-
it('should succeed on existing jsonpath from pathPattern', async function () {
|
|
287
|
-
this.jsonPathAsserter.globalArgs = {
|
|
288
|
-
argCount: 1,
|
|
289
|
-
pathTemplate: '$.{{args.0}}'
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
await this.jsonPathAsserter.assertConvoStep({
|
|
293
|
-
convoStep: { stepTag: 'test' },
|
|
294
|
-
args: ['test'],
|
|
295
|
-
botMsg: {
|
|
296
|
-
sourceData: {
|
|
297
|
-
test: true
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
299
|
})
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
assertTemplate: '{{args.1}}'
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
await this.jsonPathAsserter.assertConvoStep({
|
|
310
|
-
convoStep: { stepTag: 'test' },
|
|
311
|
-
args: ['test', 'value'],
|
|
312
|
-
botMsg: {
|
|
313
|
-
sourceData: {
|
|
314
|
-
test: 'value'
|
|
315
|
-
}
|
|
300
|
+
it('should succeed on existing jsonpath from pathPattern and assertPattern', async function () {
|
|
301
|
+
this.jsonPathAsserter.globalArgs = {
|
|
302
|
+
argCount: 2,
|
|
303
|
+
pathTemplate: '$.{{args.0}}',
|
|
304
|
+
assertTemplate: '{{args.1}}'
|
|
316
305
|
}
|
|
317
|
-
|
|
318
|
-
})
|
|
319
|
-
it('should fail on not matching jsonpath from pathPattern and assertPattern', async function () {
|
|
320
|
-
this.jsonPathAsserter.globalArgs = {
|
|
321
|
-
argCount: 2,
|
|
322
|
-
pathTemplate: '$.{{args.0}}',
|
|
323
|
-
assertTemplate: '{{args.1}}'
|
|
324
|
-
}
|
|
325
|
-
try {
|
|
306
|
+
|
|
326
307
|
await this.jsonPathAsserter.assertConvoStep({
|
|
327
308
|
convoStep: { stepTag: 'test' },
|
|
328
309
|
args: ['test', 'value'],
|
|
329
310
|
botMsg: {
|
|
330
311
|
sourceData: {
|
|
331
|
-
test: '
|
|
312
|
+
test: 'value'
|
|
332
313
|
}
|
|
333
314
|
}
|
|
334
315
|
})
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
316
|
+
})
|
|
317
|
+
it('should fail on not matching jsonpath from pathPattern and assertPattern', async function () {
|
|
318
|
+
this.jsonPathAsserter.globalArgs = {
|
|
319
|
+
argCount: 2,
|
|
320
|
+
pathTemplate: '$.{{args.0}}',
|
|
321
|
+
assertTemplate: '{{args.1}}'
|
|
322
|
+
}
|
|
323
|
+
try {
|
|
324
|
+
await this.jsonPathAsserter.assertConvoStep({
|
|
325
|
+
convoStep: { stepTag: 'test' },
|
|
326
|
+
args: ['test', 'value'],
|
|
327
|
+
botMsg: {
|
|
328
|
+
sourceData: {
|
|
329
|
+
test: 'something else'
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
})
|
|
333
|
+
assert.fail('should have failed')
|
|
334
|
+
} catch (err) {
|
|
335
|
+
assert.isTrue(err.message.indexOf('Expected: value in jsonPath $.test') > 0)
|
|
355
336
|
}
|
|
356
337
|
})
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}
|
|
338
|
+
it('should succeed on setting matching mode in global args', async function () {
|
|
339
|
+
this.jsonPathAsserter.globalArgs = {
|
|
340
|
+
argCount: 2,
|
|
341
|
+
pathTemplate: '$.{{args.0}}',
|
|
342
|
+
assertTemplate: '{{args.1}}',
|
|
343
|
+
matchingMode: 'include'
|
|
344
|
+
}
|
|
365
345
|
|
|
366
|
-
try {
|
|
367
346
|
await this.jsonPathAsserter.assertConvoStep({
|
|
368
347
|
convoStep: { stepTag: 'test' },
|
|
369
|
-
args: ['test', '
|
|
348
|
+
args: ['test', 'value'],
|
|
370
349
|
botMsg: {
|
|
371
350
|
sourceData: {
|
|
372
|
-
test: 'value'
|
|
351
|
+
test: 'value 123'
|
|
373
352
|
}
|
|
374
353
|
}
|
|
375
354
|
})
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
beforeEach(async function () {
|
|
385
|
-
this.jsonPathCountAsserter = new JsonPathCountAsserter({}, {})
|
|
386
|
-
})
|
|
355
|
+
})
|
|
356
|
+
it('should fail on setting matching mode in global args', async function () {
|
|
357
|
+
this.jsonPathAsserter.globalArgs = {
|
|
358
|
+
argCount: 2,
|
|
359
|
+
pathTemplate: '$.{{args.0}}',
|
|
360
|
+
assertTemplate: '{{args.1}}',
|
|
361
|
+
matchingMode: 'include'
|
|
362
|
+
}
|
|
387
363
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
364
|
+
try {
|
|
365
|
+
await this.jsonPathAsserter.assertConvoStep({
|
|
366
|
+
convoStep: { stepTag: 'test' },
|
|
367
|
+
args: ['test', 'value1'],
|
|
368
|
+
botMsg: {
|
|
369
|
+
sourceData: {
|
|
370
|
+
test: 'value'
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
})
|
|
374
|
+
assert.fail('should have failed')
|
|
375
|
+
} catch (err) {
|
|
376
|
+
assert.isTrue(err.message.indexOf('Expected: value1 in jsonPath $.test') > 0)
|
|
396
377
|
}
|
|
397
378
|
})
|
|
398
379
|
})
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
380
|
+
|
|
381
|
+
describe('jsonPathCountAsserter', function () {
|
|
382
|
+
beforeEach(async function () {
|
|
383
|
+
this.jsonPathCountAsserter = new JsonPathCountAsserter({}, {})
|
|
384
|
+
})
|
|
385
|
+
|
|
386
|
+
it('should succeed on no args with one jsonpath', async function () {
|
|
387
|
+
await this.jsonPathCountAsserter.assertConvoStep({
|
|
388
|
+
convoStep: { stepTag: 'test' },
|
|
389
|
+
args: ['$.test'],
|
|
390
|
+
botMsg: {
|
|
391
|
+
sourceData: {
|
|
392
|
+
test: [{ e1: 'e1' }, { e2: 'e2' }]
|
|
393
|
+
}
|
|
406
394
|
}
|
|
407
|
-
}
|
|
395
|
+
})
|
|
408
396
|
})
|
|
409
|
-
|
|
410
|
-
it('should fail on >2 with two jsonpath', async function () {
|
|
411
|
-
try {
|
|
397
|
+
it('should succeed on <=2 with two jsonpath', async function () {
|
|
412
398
|
await this.jsonPathCountAsserter.assertConvoStep({
|
|
413
399
|
convoStep: { stepTag: 'test' },
|
|
414
|
-
args: ['$.test', '
|
|
400
|
+
args: ['$.test', '<=2'],
|
|
415
401
|
botMsg: {
|
|
416
402
|
sourceData: {
|
|
417
403
|
test: [{ e1: 'e1' }, { e2: 'e2' }]
|
|
418
404
|
}
|
|
419
405
|
}
|
|
420
406
|
})
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
407
|
+
})
|
|
408
|
+
it('should fail on >2 with two jsonpath', async function () {
|
|
409
|
+
try {
|
|
410
|
+
await this.jsonPathCountAsserter.assertConvoStep({
|
|
411
|
+
convoStep: { stepTag: 'test' },
|
|
412
|
+
args: ['$.test', '>2'],
|
|
413
|
+
botMsg: {
|
|
414
|
+
sourceData: {
|
|
415
|
+
test: [{ e1: 'e1' }, { e2: 'e2' }]
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
})
|
|
419
|
+
assert.fail('should have failed')
|
|
420
|
+
} catch (err) {
|
|
421
|
+
assert.isTrue(err.message.indexOf('Expected JsonPath count 2 to be >2') >= 0)
|
|
422
|
+
}
|
|
423
|
+
})
|
|
425
424
|
})
|
|
426
425
|
})
|