Testing in NodeJS
• Mark Eschbach
I’m trying to get some programming in before I hit the hay for the night. I’ve got a Slack chat bot. It’s conversational API leaves a bit to be desired, so I’m trying to put it under test. The bot, named Marvin, is intended to operate in two modes. A group chat mode and a direct conversation mode. In group conversation mode he had a bad habbit of replying to any message…which got a bit spammy.
So this brings me back to testing. For great fun and profit. The project currently uses the NodeJS built in asserts coupled with Mocha. If one would like to assert a value as truthy you just invoke the assert
module directly.
To speed up testing I wrote a test harness which feeds in user statements and asserts Marvin’s response. Unforunately the result shows Marvin isn’t responding. Breaks out shovel; time to go digging. Yup, as I thought. Built a test to tell me where I left off!
In the original fumbling to build an implementation, I overlooked the program structure. Now I have a bit more knowledge, I’m going to giving it another shot. The tests are currently adding to the DirectMessage case. Each DirectMessage really contains a topic which will be able to handle the details of the incoming messages. An interesting case presents itself for the initial case though. What is the topic of conversation before a conversation? I totally want ot shoot for the meta-repsonse where the initial topic of conversation is about the conversation to be had. Like the initial handshake to negotiate what is to be talked about. Once another conversation is finished it simply becomes the primary topic of which topic again, like a protocol hand shake!
Not really sure how to model the initail conversation yet. Time to paste on a topicDecider as a field to compliment a topic if it’s not set. Oops. Designing to fast. Back to the problem at hand. The test I’m currently working on is the unknown topic workflow when the bot can’t figure out what you are saying. The simplest solution right now is just have it send the terminal text. Makes that totally easy.
Next up is refactor the assertion. It’s given an array of responses to feed in and verify as it goes through a conversation. Don’t know a better name right now than assert_conversation
. Minus depending alot on the test context that was relatively painless. More to come on this subject later.