Tutorial

Custody is a Node.js program. To run, you will need to have Node.js(>6) installed.

Prerequisites

By default, Custody uses the Jasmine test framework for its testing interface. However, the choice test framework is flexible and also allows for using Mocha. This tutorial assumes some familiarity with Jasmine and we will use version 2.4.

Additional prerequisites as per the platform:

Slack

Generate a Slack user testing token. You can easily generate tester tokens using the token generator or can use an oauth token from here.

Messenger

Messenger does not support token based messaging for users. So we need to use a email/password pair to emulate a user sending mesages to the bot being tested.

Setup

Use npm to install Custody globally with:

npm install -g custody

Try running custody --version to make sure it’s working.

Step 0 - write a test

Custody needs two files to run, a spec file and a configuration.

Lets start with a simple test that evaluates a simple pizza delivery bot on slack.

Copy the following into spec.js:

describe('Pizza bot test', function() {
    it('Should reply with pizza types on initial message', function() {
        csty.postMessage('Hey ssup ?');
        expect(csty.getLastMessage(true)).toMatch(/The pizzas available are.*/);
    });
});

The describe and it syntax is from the Jasmine framework. csty is a global created by Custody, which is used for conversational commands such as posting a message with csty.postMessage.

Now create the configuration file, copy the follwing into conf.js:

exports.config = {
  framework: 'jasmine',
  platform: 'slack',
  token: $SLACK_TOKEN,
  specs: ['spec.js'],
  defaultReceiver: 'C123454'
}

This configuration tells Custody where your test files (specs) are and which messaging platform to use (platform). It specifies that we will be using Jasmine for the test framework. The token speciefies the auth token we created in the step above. The defaultReceiver is the id of the channel where our message would be posted. It will use the defaults for all other configuration options.

Now run the test with

custody conf.js

You should see in your slack window, on the channel you mentioned, a message being posted Hey ssup ?. The bot (if working as intended) should reply with the expected response. Congratulations, you’ve run your first Custody test!