-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathchatBotValidationSpec.ts
More file actions
70 lines (61 loc) · 1.98 KB
/
Copy pathchatBotValidationSpec.ts
File metadata and controls
70 lines (61 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
* SPDX-License-Identifier: MIT
*/
import chai = require('chai')
import validateChatBot, { checkIntentWithFunctionHandlerExists } from '../../lib/startup/validateChatBot'
import sinonChai = require('sinon-chai')
const expect = chai.expect
chai.use(sinonChai)
describe('chatBotValidation', () => {
describe('checkIntentWithHandlerExists', () => {
it('should accept training data with the expected intent and handler', () => {
const trainingData = {
data: [
{
intent: 'queries.test',
answers: [
{
action: 'function',
handler: 'testHandler'
}
]
}
]
}
expect(checkIntentWithFunctionHandlerExists(trainingData, 'queries.test', 'testHandler')).to.equal(true)
})
it('should fail if the training data lacks the expected intent', () => {
const trainingData = {
data: [
{
intent: 'queries.dummy'
}
]
}
expect(checkIntentWithFunctionHandlerExists(trainingData, 'queries.test', 'testFunction')).to.equal(false)
})
it('should fail if the training data lacks the expected handler for the given intent', () => {
const trainingData = {
data: [
{
intent: 'queries.test',
answers: [
{
action: 'function',
handler: 'dummyHandler'
}
]
}
]
}
expect(checkIntentWithFunctionHandlerExists(trainingData, 'queries.test', 'testHandler')).to.equal(false)
})
})
it('should accept the default chatbot training data', () => {
expect(validateChatBot(require('../../data/static/botDefaultTrainingData.json'))).to.equal(true)
})
it('should fail if the chatbot training data is empty', () => {
expect(validateChatBot({ data: [] }, false)).to.equal(false)
})
})