Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

darvin-testing-framework

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

darvin-testing-framework - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

33

index.js

@@ -36,2 +36,11 @@ 'use strict';

});
if (spec.dynamic && typeof spec.dynamic === 'function') {
const sender = { id: 'tempuser-' + uuid() };
const context = {
send: message => this._send(spec, sender, message)
};
spec.dynamic(context);
}
});

@@ -64,3 +73,3 @@ }

BbPromise.each(scenario.steps, step => that._executeStep(spec, sender, step))
BbPromise.each(scenario.steps, step => that._executeStep(spec, scenario, step, sender))
.then(done)

@@ -70,7 +79,13 @@ .catch(done.fail);

_executeStep(spec, sender, step) {
_executeStep(spec, scenario, step, sender) {
const message = Object.assign({}, step.user, { mocks: Object.assign({}, scenario.mocks, step.mocks) });
return this._send(spec, sender, message)
.then(response => this._verifyStep(step, response));
}
_send(spec, sender, message) {
const channelUrl = `${this._apiUrl}v1/bots/${spec.botId}/channels/${spec.channel.id}/darvin`;
const message = {
const payload = {
sender,
message: step.user
message
};

@@ -84,6 +99,5 @@

},
body: JSON.stringify(message)
body: JSON.stringify(payload)
};
const that = this;
return fetch(channelUrl, options)

@@ -96,8 +110,9 @@ .then(response => {

return response.json();
})
.then(response => that._verifyStep(step, response));
});
}
_verifyStep(step, response) {
expect(step.bot.map(JSON.stringify)).toContain(JSON.stringify(response));
if (step.bot) {
expect(step.bot.map(JSON.stringify)).toContain(JSON.stringify(response));
}
}

@@ -104,0 +119,0 @@ }

{
"name": "darvin-testing-framework",
"version": "1.0.0",
"version": "1.1.0",
"description": "A framework for testing Darvin.ai bots.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -31,4 +31,29 @@ # Darvin Testing Framework

## JSON chatbot specifications format
## API Reference
```javascript
const DarvinTestingFramework = require('darvin-testing-framework');
```
### Contructor
```javascript
const tf = new DarvinTestingFramework(config)
```
`config` is optional. It allows to specify the Darvin.ai api URL. The default value for `config` is `{ apiUrl: 'https://api.darvin.ai/' }`.
### describe
```javascript
tf.describe(spec, options)
```
- `spec` is required and described [below](#specs)
- `options` is optional. It is an object that may contain
- `setup` - a function that is called [`beforeAll`](https://jasmine.github.io/2.1/introduction#section-Setup_and_Teardown) specs
- `teardown` - a function that is called [`afterAll`](https://jasmine.github.io/2.1/introduction#section-Setup_and_Teardown) specs
## <a name="specs"></a> Chatbot specifications reference
The JSON specification must have the following properties:

@@ -41,2 +66,37 @@

- `token` - Verification token of the system communication channel of the target chatbot
- `dynamic` - a function that can be used to write your own scenarios imperatively while using the same chatbot context. A `context` object will be passed to this function.
- `send` is a function that is a member of `context`. It expect a message and returns a Promise which resolves into the chatbot response.
Example:
```javascript
const spec = {
name: 'Introduction Bot',
botId: '5977605bd9e084db0e278836',
channel: {
id: '597753c6194052ef4930f4af',
token: 'darvin-channel-secret'
},
dynamic: context => {
it('responds to Hello itself', done => {
context.send({ text: 'Hello' })
.then(response => {
expect(response.length).toBe(1);
expect(response[0].text).toBe('Hi there!');
return context.send({ text: 'What is up?' });
})
.then(response => {
expect(response.length).toBe(1);
expect(response[0].text).toBe('Not much');
})
.then(done)
.catch(done.fail);;
});
}
};
tf.describe(spec);
```
- `scenarios` - an array of scenarios describing the chatbot's behavior

@@ -50,7 +110,35 @@ - `it` - follows the idea of [behavior-driven development](https://en.wikipedia.org/wiki/Behavior-driven_development) and serves as the first word in the test name, which should be a complete sentence

- `quickReplies` - array of quick reply options
- `mocks` - a dictionary that allows you to mock the responses of specific URLs and HTTP actions against those URLs
Example:
```json
"mocks": {
"https://api.everlive.com/v1/niuqpjk7bubu0282/Functions/GetDoctorDays?doctorId=24806": {
"GET": ["2017-08-07", "2017-08-15", "2017-08-24"]
}
}
```
## Example spec
_This mocked response applies only when the bot is responding to the message in the current step._
The following example spec verifies that the `Sample bot introduces itself and enters into a conversation`.
- `mocks` - a dictionary that allows you to mock the responses of specific URLs and HTTP actions against those URLs
Example:
```json
"mocks": {
"https://api.everlive.com/v1/niuqpjk7bubu0282/Functions/ValidateDate?doctorId=24806&date=2017.08.07": {
"GET": "OK"
}
}
```
_This mocked response applies for the whole scenario._
## Example specification
The following example specification verifies that the `Sample bot introduces itself and enters into a conversation`.
```json

@@ -95,2 +183,2 @@ {

_Our QuickStart sample has specifications with it. Feel free to explore it in order to get more familiar with the format. Click [here](https://github.com/darvinai/samples/blob/master/QuickStart/en/spec.json) to get it. It only has `scenarios` since it is a general specification and it is not targeted at a specific chatbot isntance._
_Our QuickStart sample has specifications with it. Feel free to explore it in order to get more familiar with the format. Click [here](https://github.com/darvinai/samples/blob/master/QuickStart/en/tests.json) to get it. It only has `scenarios` since it is a general specification and it is not targeted at a specific chatbot isntance._
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc