Skip to content

Commit d9e7582

Browse files
committed
Add botium test scripts
1 parent d734375 commit d9e7582

22 files changed

+3613
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
1-
# chatbot-test
1+
# chatbot-test
2+
3+
Test a specific task reminder chatbot running on WebSocket - ws://localhost:5555 and http://localhost:7777
4+
5+
This repo uses the chatbot test framework, [Botium](https://botium-docs.readthedocs.io/en/latest/)
6+
7+
8+
# Installation
9+
10+
Please install node.js if you have not done so.
11+
12+
```
13+
npm install -g botium-bindings
14+
npm install -g botium-connector-websocket
15+
botium-bindings init mocha
16+
npm install && npm run mocha
17+
```
18+
19+
# Unit Tests
20+
21+
Simply run:
22+
```
23+
$ npm test
24+
```
25+
26+
# NOTE
27+
28+
## spec/convo/give_me_a_picture.convo.txt
29+
30+
This file is installed by one of botium packages. I couldn't figure out how to avoid it.
31+
32+
# TODOs
33+
34+
1. Test when there are at least 2 reminders in the queue

botium.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"botium": {
3+
"Capabilities": {
4+
"PROJECTNAME": "ChatBot Project Websocket",
5+
"CONTAINERMODE": "websocket",
6+
"WEBSOCKET_URL": "ws://127.0.0.1:5555",
7+
"WEBSOCKET_REQUEST_BODY_RAW": true,
8+
"WEBSOCKET_RESPONSE_RAW": true,
9+
"WEBSOCKET_RESPONSE_HOOK": "handle-response-reminders.js"
10+
}
11+
}
12+
}

handle-response-reminders.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Response hook to pre-process response before calling unit testing scripts (botiumscripts)
3+
*/
4+
module.exports = ({ botMsg }) => {
5+
// return "HELP" when handling the help reminder
6+
// what is returned is what we match with in the convo text (botiumscript) file
7+
if (botMsg.messageText.includes('I am a reminder bot')) {
8+
botMsg.messageText = 'HELP'
9+
return botMsg
10+
}
11+
12+
// return if not dealing with a list of reminders in the queue
13+
if (!botMsg.messageText.includes('<table')) {
14+
return botMsg
15+
}
16+
17+
// return "id: <id>, text: <text of action>" when handling list of reminders in the queue
18+
// what is returned is what we match with in the convo text (botiumscript) file
19+
let actual
20+
const regex = RegExp('<td>(.*?)</td>', 'gi')
21+
22+
let arr
23+
let i = 0
24+
while ((arr = regex.exec(botMsg.sourceData)) !== null) {
25+
arr[0] = arr[0].replace('<td>', '').replace('</td>', '')
26+
if (i === 0) {
27+
actual = `id: ${arr[0]}, text: `
28+
} else if (i === 2) {
29+
actual += arr[0]
30+
}
31+
i++
32+
}
33+
botMsg.messageText = actual
34+
35+
return botMsg
36+
}

0 commit comments

Comments
 (0)