Skip to content

Commit

Permalink
Add botium test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
developertogo committed Sep 13, 2021
1 parent d734375 commit d9e7582
Show file tree
Hide file tree
Showing 22 changed files with 3,613 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
# chatbot-test
# chatbot-test

Test a specific task reminder chatbot running on WebSocket - ws://localhost:5555 and http://localhost:7777

This repo uses the chatbot test framework, [Botium](https://botium-docs.readthedocs.io/en/latest/)


# Installation

Please install node.js if you have not done so.

```
npm install -g botium-bindings
npm install -g botium-connector-websocket
botium-bindings init mocha
npm install && npm run mocha
```

# Unit Tests

Simply run:
```
$ npm test
```

# NOTE

## spec/convo/give_me_a_picture.convo.txt

This file is installed by one of botium packages. I couldn't figure out how to avoid it.

# TODOs

1. Test when there are at least 2 reminders in the queue
12 changes: 12 additions & 0 deletions botium.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"botium": {
"Capabilities": {
"PROJECTNAME": "ChatBot Project Websocket",
"CONTAINERMODE": "websocket",
"WEBSOCKET_URL": "ws://127.0.0.1:5555",
"WEBSOCKET_REQUEST_BODY_RAW": true,
"WEBSOCKET_RESPONSE_RAW": true,
"WEBSOCKET_RESPONSE_HOOK": "handle-response-reminders.js"
}
}
}
36 changes: 36 additions & 0 deletions handle-response-reminders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Response hook to pre-process response before calling unit testing scripts (botiumscripts)
*/
module.exports = ({ botMsg }) => {
// return "HELP" when handling the help reminder
// what is returned is what we match with in the convo text (botiumscript) file
if (botMsg.messageText.includes('I am a reminder bot')) {
botMsg.messageText = 'HELP'
return botMsg
}

// return if not dealing with a list of reminders in the queue
if (!botMsg.messageText.includes('<table')) {
return botMsg
}

// return "id: <id>, text: <text of action>" when handling list of reminders in the queue
// what is returned is what we match with in the convo text (botiumscript) file
let actual
const regex = RegExp('<td>(.*?)</td>', 'gi')

let arr
let i = 0
while ((arr = regex.exec(botMsg.sourceData)) !== null) {
arr[0] = arr[0].replace('<td>', '').replace('</td>', '')
if (i === 0) {
actual = `id: ${arr[0]}, text: `
} else if (i === 2) {
actual += arr[0]
}
i++
}
botMsg.messageText = actual

return botMsg
}
Loading

0 comments on commit d9e7582

Please sign in to comment.