Skip to content

Commit 3a6eb32

Browse files
author
Joshua B. Smith
committed
add error if version_date isn't passed in on construction
1 parent 0912f60 commit 3a6eb32

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

examples/natural_language_understanding.v1.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const fs = require('fs');
22
const NaturalLanguageUnderstandingV1 = require('../natural-language-understanding/v1.js');
33

4-
const auth = {username: '<USERNAME>',password: '<PASSWORD>'};
4+
const auth = {username: '<USERNAME>',
5+
password: '<PASSWORD>',
6+
version_date= NaturalLanguageUnderstandingV1.VERSION_DATE};
57
const nlu = new NaturalLanguageUnderstandingV1(auth);
68

79
const query = new nlu.QueryBuilder();

natural-language-understanding/v1.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ var BaseService = require('../lib/base_service');
2828
*/
2929
function NaturalLanguageUnderstandingV1(options) {
3030
BaseService.call(this, options);
31+
if (typeof this._options.version_date === 'undefined') {
32+
throw new Error('Argument error: version_date was not specified, use 2016-01-23');
33+
}
34+
this._options.qs.version = this._options.version_date;
3135
}
3236
util.inherits(NaturalLanguageUnderstandingV1, BaseService);
3337
NaturalLanguageUnderstandingV1.prototype.name = 'natural_language_understanding';
@@ -164,14 +168,12 @@ NaturalLanguageUnderstandingV1.prototype.analyze = function(query, params, callb
164168
params = params || {};
165169
}
166170

167-
params.version = params.version || NaturalLanguageUnderstandingV1.VERSION_DATE;
168171

169172
var parameters = {
170173
options: {
171174
url: '/v1/analyze',
172175
method: 'POST',
173176
json: true,
174-
qs: pick(params, ['version']),
175177
body: query.object()
176178
},
177179
defaultOptions: this._options

test/unit/test.natural_language_understanding.v1.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,25 @@ describe('natural_language_understanding', function() {
1616
var nlu;
1717

1818
before(function() {
19-
nlu = new watson.NaturalLanguageUnderstandingV1({username: 'user', password: 'pass'});
19+
nlu = new watson.NaturalLanguageUnderstandingV1({username: 'user',
20+
password: 'pass',
21+
version_date: watson.NaturalLanguageUnderstandingV1.VERSION_DATE});
2022
nock.disableNetConnect();
2123
});
2224

2325
after(function() {
2426
nock.cleanAll();
2527
});
2628

29+
it('should throw if no version is present', function(done) {
30+
assert.throws(function() {
31+
const badnlu = new watson.NaturalLanguageUnderstandingV1({username: 'user',
32+
password: 'pass'});
33+
assert(badnlu);
34+
});
35+
done();
36+
});
37+
2738
it('analyze()', function(done) {
2839
nock(watson.NaturalLanguageUnderstandingV1.URL)
2940
.persist()

0 commit comments

Comments
 (0)