Commit ba95810c authored by Gerd Watmann's avatar Gerd Watmann
Browse files

adding standard + some refactoring

parent 7220bf11
{
// Place your settings in this file to overwrite default and user settings.
"editor.tabSize": 2,
"editor.formatOnSave": true,
"javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": true,
"files.insertFinalNewline": true,
"prettier.singleQuote": true
}
"javascript.validate.enable": false,
"standard.enable": true,
"standard.autoFixOnSave": true
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ Sample project that demonstrates how you can write regression tests for Watson A
2. ASSISTANT_USERNAME= Watson Assistent - Instance Username
3. ASSISTANT_PASSWORD= Watson Assistent - Instance Password
4. ASSISTANT_WORKSPACEID= Watson Assistent - WorkspaceID you want to leverage
5. ASSISTANT_VERSION = Watson Assistant - API Version to be used, e.g. 2018-02-16
* Run npm install to fetch the development dependencies
......
This diff is collapsed.
......@@ -3,7 +3,7 @@
"version": "0.0.1",
"private": true,
"scripts": {
"test": "mocha --timeout 10000 --recursive --exit"
"test": "standard && mocha --timeout 10000 --recursive --exit"
},
"devDependencies": {
"chai": "^4.1.2",
......@@ -11,6 +11,7 @@
"chai-subset": "^1.6.0",
"dotenv": "^5.0.1",
"mocha": "^5.1.1",
"standard": "^11.0.1",
"watson-developer-cloud": "^3.4.1",
"winston": "^2.4.2"
},
......
/* eslint-env node, mocha */
const chai = require('chai');
const dotenv = require('dotenv');
const AssistantV1 = require('watson-developer-cloud/assistant/v1');
const winston = require('winston');
const chai = require('chai')
const dotenv = require('dotenv')
const AssistantV1 = require('watson-developer-cloud/assistant/v1')
const winston = require('winston')
const expect = chai.expect;
winston.level = 'debug';
dotenv.config();
const expect = chai.expect
winston.level = 'debug'
dotenv.config()
let ASSISTANT_WORKSPACEID = process.env.ASSISTANT_WORKSPACEID;
let ASSISTANT_USERNAME = process.env.ASSISTANT_USERNAME;
let ASSISTANT_PASSWORD = process.env.ASSISTANT_PASSWORD;
let ASSISTANT_URL = process.env.ASSISTANT_URL;
let ASSISTANT_VERSION = process.env.ASSISTANT_VERSION;
const ASSISTANT_WORKSPACEID = process.env.ASSISTANT_WORKSPACEID
const ASSISTANT_USERNAME = process.env.ASSISTANT_USERNAME
const ASSISTANT_PASSWORD = process.env.ASSISTANT_PASSWORD
const ASSISTANT_URL = process.env.ASSISTANT_URL
const ASSISTANT_VERSION = process.env.ASSISTANT_VERSION
var assistant;
var min_confidence = 0.5;
let assistant
const minConfidence = 0.5
// Open Watson Assistant service
before(function(done) {
before(function (done) {
assistant = new AssistantV1({
username: ASSISTANT_USERNAME,
password: ASSISTANT_PASSWORD,
url: ASSISTANT_URL,
version: ASSISTANT_VERSION
});
done();
});
})
done()
})
describe('Validating intent #turn_off', function() {
var flow = false;
var context = null;
var tests = [
describe('Validating intent #turn_off', function () {
let flow = false
let context = null
let tests = [
{
question: 'Turn off the wipers',
expected_intent: 'turn_off',
......@@ -51,17 +51,17 @@ describe('Validating intent #turn_off', function() {
expected_entity_type: 'appliance',
expected_entity_value: 'lights'
}
];
]
tests.forEach(function(test) {
it('should return the following' + ' #' + test.expected_intent, function(
tests.forEach(function (test) {
it('should return the following' + ' #' + test.expected_intent, function (
done
) {
this.timeout(5000);
this.timeout(5000)
intent = null;
entity_type = null;
entity_value = null;
let intent
let entityType
let entityValue
assistant.message(
{
......@@ -71,38 +71,39 @@ describe('Validating intent #turn_off', function() {
},
context: context
},
function(err, response) {
if (err) winston.error('error:', err);
if (flow) context = response.context;
function (err, response) {
if (err) winston.error('error:', err)
if (flow) context = response.context
intent = response.intents[0].intent;
confidence = response.intents[0].confidence;
intent = response.intents[0].intent
const confidence = response.intents[0].confidence
expect(intent).to.be.equal(test.expected_intent);
expect(confidence).to.be.least(min_confidence);
expect(intent).to.be.equal(test.expected_intent)
expect(confidence).to.be.least(minConfidence)
// tbd deep equal
if (test.expected_entity_type) {
entity_type = response.entities[0].entity;
expect(entity_type).to.be.equal(test.expected_entity_type);
entityType = response.entities[0].entity
expect(entityType).to.be.equal(test.expected_entity_type)
}
if (test.expected_entity_value) {
entity_value = response.entities[0].value;
expect(entity_value).to.be.equal(test.expected_entity_value);
entityValue = response.entities[0].value
expect(entityValue).to.be.equal(test.expected_entity_value)
}
if (flow) winston.info('answer: ' + response.output.text);
else
if (flow) winston.info('answer: ' + response.output.text)
else {
winston.info(
'intent: ',
intent,
' confidence: ',
parseFloat(confidence).toFixed(2)
);
done();
)
}
done()
}
);
});
});
});
)
})
})
})
/* eslint-env node, mocha */
const chai = require('chai');
const dotenv = require('dotenv');
const AssistantV1 = require('watson-developer-cloud/assistant/v1');
const winston = require('winston');
const chai = require('chai')
const dotenv = require('dotenv')
const AssistantV1 = require('watson-developer-cloud/assistant/v1')
const winston = require('winston')
const expect = chai.expect;
winston.level = 'debug';
dotenv.config();
const expect = chai.expect
winston.level = 'debug'
dotenv.config()
let ASSISTANT_WORKSPACEID = process.env.ASSISTANT_WORKSPACEID;
let ASSISTANT_USERNAME = process.env.ASSISTANT_USERNAME;
let ASSISTANT_PASSWORD = process.env.ASSISTANT_PASSWORD;
let ASSISTANT_URL = process.env.ASSISTANT_URL;
let ASSISTANT_VERSION = process.env.ASSISTANT_VERSION;
const ASSISTANT_WORKSPACEID = process.env.ASSISTANT_WORKSPACEID
const ASSISTANT_USERNAME = process.env.ASSISTANT_USERNAME
const ASSISTANT_PASSWORD = process.env.ASSISTANT_PASSWORD
const ASSISTANT_URL = process.env.ASSISTANT_URL
const ASSISTANT_VERSION = process.env.ASSISTANT_VERSION
var assistant;
var min_confidence = 0.5;
let assistant
const minConfidence = 0.5
// Open Watson Assistant service
before(function(done) {
before(function (done) {
assistant = new AssistantV1({
username: ASSISTANT_USERNAME,
password: ASSISTANT_PASSWORD,
url: ASSISTANT_URL,
version: ASSISTANT_VERSION
});
done();
});
})
done()
})
describe('Validating dialog flows that use intent #turn_on', function() {
var flow = true;
var context = null;
var tests = [
describe('Validating dialog flows that use intent #turn_on', function () {
const flow = true
let context = null
let tests = [
{
question: 'Hi',
expected_intent: 'greetings'
......@@ -60,17 +60,17 @@ describe('Validating dialog flows that use intent #turn_on', function() {
expected_entity_type: 'appliance',
expected_entity_value: 'lights'
}
];
]
tests.forEach(function(test) {
it('should return the following' + ' #' + test.expected_intent, function(
tests.forEach(function (test) {
it('should return the following' + ' #' + test.expected_intent, function (
done
) {
this.timeout(5000);
this.timeout(5000)
intent = null;
entity_type = null;
entity_value = null;
let intent
let entityType
let entityValue
assistant.message(
{
......@@ -80,31 +80,31 @@ describe('Validating dialog flows that use intent #turn_on', function() {
},
context: context
},
function(err, response) {
if (err) winston.error('error:', err);
if (flow) context = response.context;
function (err, response) {
if (err) winston.error('error:', err)
if (flow) context = response.context
intent = response.intents[0].intent;
confidence = response.intents[0].confidence;
intent = response.intents[0].intent
const confidence = response.intents[0].confidence
expect(intent).to.be.equal(test.expected_intent);
expect(confidence).to.be.least(min_confidence);
expect(intent).to.be.equal(test.expected_intent)
expect(confidence).to.be.least(minConfidence)
// tbd deep equal
if (test.expected_entity_type) {
entity_type = response.entities[0].entity;
expect(entity_type).to.be.equal(test.expected_entity_type);
entityType = response.entities[0].entity
expect(entityType).to.be.equal(test.expected_entity_type)
}
if (test.expected_entity_value) {
entity_value = response.entities[0].value;
expect(entity_value).to.be.equal(test.expected_entity_value);
entityValue = response.entities[0].value
expect(entityValue).to.be.equal(test.expected_entity_value)
}
winston.info('answer: ' + response.output.text);
done();
winston.info('answer: ' + response.output.text)
done()
}
);
});
});
});
)
})
})
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment