Skip to content

Commit 5ad0b25

Browse files
authored
Added unit tests for several services (#576)
Added unit tests for several services, fixes formatting, removes deprecated methods in conversation
1 parent a7a6abd commit 5ad0b25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2435
-354
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ examples/**/node_modules/
99
test/resources/auth.js
1010
# ignore emitted js
1111
**/*v*.js
12+
!test/**/*.js
1213
lib/*.js
1314
dialog/v1.js

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
"prettier",
1414
],
1515
"rules": {
16-
"prettier/prettier": ["error", {"singleQuote": true, "printWidth": 160}],
16+
"prettier/prettier": ["error", {"singleQuote": true, "printWidth": 100}],
1717
"prefer-const": "error",
1818
"prefer-rest-params": "off", // https://github.com/mysticatea/eslint-plugin-node/issues/63
1919
// The rest of these override rules that are enabled by one of the configs we extend but not compatible with current codebase

conversation/v1.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,12 @@ class ConversationV1 extends GeneratedConversationV1 {
3434
super(options);
3535
}
3636

37+
private static removedError: Error = new Error(
38+
'This endpoint has been deprecated.'
39+
);
40+
3741
workspaceStatus(params, callback) {
38-
const _params = extend({}, params);
39-
const _callback = callback ? callback : () => {};
40-
const requiredParams = ['workspace_id'];
41-
const missingParams = getMissingParams(_params, requiredParams);
42-
if (missingParams) {
43-
return _callback(missingParams);
44-
}
45-
const path = {
46-
workspace_id: _params.workspace_id
47-
};
48-
const parameters = {
49-
options: {
50-
url: '/v1/workspaces/{workspace_id}/status',
51-
method: 'GET',
52-
path: path
53-
},
54-
defaultOptions: extend(true, this._options, {
55-
headers: {
56-
accept: 'application/json'
57-
}
58-
})
59-
};
60-
return createRequest(parameters, _callback);
42+
console.warn(ConversationV1.removedError);
6143
}
6244

6345
getIntents(params, callback) {
@@ -221,7 +203,7 @@ class ConversationV1 extends GeneratedConversationV1 {
221203
}
222204

223205
updateSynonym(params, callback) {
224-
if (params && params.new_synonym) {
206+
if (params && (params.new_synonym || !params.old_synonym)) {
225207
return super.updateSynonym(params, callback);
226208
}
227209

examples/.eslintrc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
module.exports = {
2+
"parserOptions": { "ecmaVersion": 5 },
23
"rules": {
34
"no-console": "off",
45
"node/no-missing-require": "off",
56
"require-jsdoc": "off",
67
"valid-jsdoc": "off",
7-
"no-process-exit": "off"
8+
"no-process-exit": "off",
9+
"prefer-const": "off"
810
}
911
};

examples/browserify/public/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function getToken() {
2626
}
2727

2828
function analyze(token) {
29-
const toneAnalyzer = new ToneAnalyzerV3({
29+
var toneAnalyzer = new ToneAnalyzerV3({
3030
token: token,
3131
version_date: '2016-05-19'
3232
});

examples/browserify/server.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
2-
const express = require('express'); // eslint-disable-line node/no-missing-require
3-
const app = express();
4-
const expressBrowserify = require('express-browserify'); // eslint-disable-line node/no-missing-require
5-
const dotenv = require('dotenv');
6-
const watson = require('watson-developer-cloud');
2+
var express = require('express'); // eslint-disable-line node/no-missing-require
3+
var app = express();
4+
var expressBrowserify = require('express-browserify'); // eslint-disable-line node/no-missing-require
5+
var dotenv = require('dotenv');
6+
var watson = require('watson-developer-cloud');
77

8-
const isDev = app.get('env') === 'development';
8+
var isDev = app.get('env') === 'development';
99
app.get(
1010
'/bundle.js',
1111
expressBrowserify('public/client.js', {
@@ -20,7 +20,7 @@ app.use(express.static('public/'));
2020
dotenv.load({ silent: true });
2121

2222
// For local development, specify the username and password or set env properties
23-
const ltAuthService = new watson.AuthorizationV1({
23+
var ltAuthService = new watson.AuthorizationV1({
2424
username: process.env.TONE_ANALYZER_USERNAME || '<username>',
2525
password: process.env.TONE_ANALYZER_PASSWORD || '<password>',
2626
url: watson.ToneAnalyzerV3.URL
@@ -36,7 +36,7 @@ app.get('/api/token/tone_analyzer', function(req, res) {
3636
});
3737
});
3838

39-
const port = process.env.PORT || process.env.VCAP_APP_PORT || 3000;
39+
var port = process.env.PORT || process.env.VCAP_APP_PORT || 3000;
4040
app.listen(port, function() {
4141
console.log('Watson browserify example server running at http://localhost:%s/', port);
4242
});

examples/conversation_tone_analyzer_integration/tone_detection.js

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,13 @@ module.exports = {
5454
*/
5555
function invokeToneAsync(conversationPayload, tone_analyzer) {
5656
return new Promise(function(resolve, reject) {
57-
tone_analyzer.tone(
58-
{ text: conversationPayload.input.text },
59-
(error, data) => {
60-
if (error) {
61-
reject(error);
62-
} else {
63-
resolve(data);
64-
}
57+
tone_analyzer.tone({ text: conversationPayload.input.text }, (error, data) => {
58+
if (error) {
59+
reject(error);
60+
} else {
61+
resolve(data);
6562
}
66-
);
63+
});
6764
});
6865
}
6966

@@ -75,11 +72,7 @@ function invokeToneAsync(conversationPayload, tone_analyzer) {
7572
* @param toneAnalyzerPayload json object returned by the Watson Tone Analyzer Service
7673
* @return conversationPayload where the user object has been updated with tone information from the toneAnalyzerPayload
7774
*/
78-
function updateUserTone(
79-
conversationPayload,
80-
toneAnalyzerPayload,
81-
maintainHistory
82-
) {
75+
function updateUserTone(conversationPayload, toneAnalyzerPayload, maintainHistory) {
8376
var emotionTone = null;
8477
var languageTone = null;
8578
var socialTone = null;
@@ -97,9 +90,7 @@ function updateUserTone(
9790

9891
// Extract the tones - emotion, language and social
9992
if (toneAnalyzerPayload && toneAnalyzerPayload.document_tone) {
100-
toneAnalyzerPayload.document_tone.tone_categories.forEach(function(
101-
toneCategory
102-
) {
93+
toneAnalyzerPayload.document_tone.tone_categories.forEach(function(toneCategory) {
10394
if (toneCategory.category_id === EMOTION_TONE_LABEL) {
10495
emotionTone = toneCategory;
10596
}

examples/dialog.v1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
const DialogV1 = require('watson-developer-cloud/dialog/v1');
3+
var DialogV1 = require('watson-developer-cloud/dialog/v1');
44

5-
const dialog = new DialogV1({
5+
var dialog = new DialogV1({
66
username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE',
77
password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE'
88
});

examples/discovery.v1.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

3-
const DiscoveryV1 = require('watson-developer-cloud/discovery/v1');
4-
const fs = require('fs');
3+
var DiscoveryV1 = require('watson-developer-cloud/discovery/v1');
4+
var fs = require('fs');
55

6-
const discovery = new DiscoveryV1({
6+
var discovery = new DiscoveryV1({
77
// if left unspecified here, the SDK will fall back to the DISCOVERY_USERNAME and DISCOVERY_PASSWORD
88
// environment properties, and then Bluemix's VCAP_SERVICES environment property
99
// username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE',
@@ -18,7 +18,7 @@ discovery.getEnvironments({}, function(error, data) {
1818
});
1919

2020
// var file = fs.readFileSync('../test/resources/sampleHtml.html');
21-
const file = fs.createReadStream('../test/resources/sampleWord.docx');
21+
var file = fs.createReadStream('../test/resources/sampleWord.docx');
2222

2323
discovery.addDocument(
2424
{

examples/natural_language_understanding.v1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var fs = require('fs');
44
var NaturalLanguageUnderstandingV1 = require('watson-developer-cloud/natural-language-understanding/v1.js');
55
require('dotenv').config({ silent: true }); // optional
66

7-
const nlu = new NaturalLanguageUnderstandingV1({
7+
var nlu = new NaturalLanguageUnderstandingV1({
88
// note: if unspecified here, credentials are pulled from environment properties:
99
// NATURAL_LANGUAGE_UNDERSTANDING_USERNAME & NATURAL_LANGUAGE_UNDERSTANDING_PASSWORD
1010
// username: '<username>'.
@@ -17,7 +17,7 @@ fs.readFile(filename, 'utf-8', function(file_error, file_data) {
1717
if (file_error) {
1818
console.log(file_error);
1919
} else {
20-
const options = {
20+
var options = {
2121
html: file_data,
2222
features: {
2323
concepts: {},

0 commit comments

Comments
 (0)