Skip to content

Commit 02b4408

Browse files
Merge branch 'dev'
2 parents f7407dc + 49741fc commit 02b4408

File tree

11 files changed

+79
-21
lines changed

11 files changed

+79
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ coverage
55
test/resources/auth.js
66
test/integration/
77
test/resources/tts-output.ogg
8+
.idea

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ script:
99
after_success:
1010
- npm run coveralls
1111
before_install:
12-
- openssl aes-256-cbc -K $encrypted_d4f181ef7c79_key -iv $encrypted_d4f181ef7c79_iv
13-
-in auth.js.enc -out test/resources/auth.js -d
12+
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && openssl aes-256-cbc -K $encrypted_cb4d3d070e32_key -iv $encrypted_cb4d3d070e32_iv -in auth.js.enc -out test/resources/auth.js -d || true'

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ If you want to contribute to the repository, follow these steps:
2828

2929
1. Fork the repo.
3030
1. Develop and test your code changes: `npm install -d && npm test`. Make sure you work in the `dev` branch. PLEASE don't do your work in `master`.
31-
1. In order to run the tests locally you should comment out `test.integration-all-services.js` because the integration tests require you to have service credentials for all the services.
32-
Travis will run the integration tests for all services once the changes are merged in.
31+
1. Travis-CI will run the integration tests for all services once your changes are merged.
32+
If you wish to run integration tests locally you must provide service credentials for all the services. See `test/test.integration-all-services.js`.
3333
1. Add a test for your changes. Only refactoring and documentation changes require no new tests.
3434
1. Make the test pass.
3535
1. Commit your changes.

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,26 @@ var watson = require('watson-developer-cloud');
294294
var fs = require('fs');
295295

296296
var document_conversion = watson.document_conversion({
297-
username: '<username>',
298-
password: '<password>',
299-
version: 'v1-experimental'
297+
username: '<username>',
298+
password: '<password>',
299+
version: 'v1-experimental',
300+
version_date: '2015-12-01'
300301
});
301302

302303
// convert a single document
303304
document_conversion.convert({
304305
// (JSON) ANSWER_UNITS, NORMALIZED_HTML, or NORMALIZED_TEXT
305306
file: fs.createReadStream('sample-docx.docx'),
306-
conversion_target: document_conversion.conversion_target.ANSWER_UNITS
307+
conversion_target: document_conversion.conversion_target.ANSWER_UNITS,
308+
// Add custom configuration properties or omit for defaults
309+
word: {
310+
heading: {
311+
fonts: [
312+
{ level: 1, min_size: 24 },
313+
{ level: 2, min_size: 16, max_size: 24 }
314+
]
315+
}
316+
}
307317
}, function (err, response) {
308318
if (err) {
309319
console.error(err);

auth.js.enc

-928 Bytes
Binary file not shown.

examples/visual_recognition.v2-beta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var visual_recognition = watson.visual_recognition({
88
username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE',
99
password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE',
1010
version: 'v2-beta',
11-
version_date: '2015-11-24'
11+
version_date: '2015-12-02'
1212
});
1313

1414
var params = {

services/document_conversion/v1-experimental.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,19 @@ var isStream = require('isstream');
2222
var omit = require('object.omit');
2323

2424
function DocumentConversion(options) {
25+
// Warn if not specifying version date
26+
var version_date = "2015-12-01"
27+
if(options && options.version_date) {
28+
version_date = options.version_date
29+
} else {
30+
console.warn("[DocumentConversion] WARNING: No version_date specified. Using a (possibly old) default. " +
31+
"e.g. watson.document_conversion({ version_date: '2015-12-01' })")
32+
}
33+
2534
// Default URL
2635
var serviceDefaults = {
27-
url: 'https://gateway.watsonplatform.net/document-conversion-experimental/api'
36+
url: 'https://gateway.watsonplatform.net/document-conversion-experimental/api',
37+
qs: { version: version_date }
2838
};
2939

3040
// Replace default options with user provided

services/visual_recognition/v2-beta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function verifyStream(value, name) {
4141
function VisualRecognition(options) {
4242
// Check if 'version_date' was provided
4343
if (typeof options.version_date === 'undefined') {
44-
throw new Error('Argument error: version_date was not specified, use 2015-11-24');
44+
throw new Error('Argument error: version_date was not specified, use 2015-12-02');
4545
}
4646

4747
// Default URL

test/test.document_conversion.v1-experimental.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var assert = require('assert');
44
var pick = require('object.pick');
5+
var extend = require('extend');
56
var watson = require('../lib/index');
67
var nock = require('nock');
78
var fs = require('fs');
@@ -11,7 +12,7 @@ describe('document_conversion', function() {
1112
var noop = function() {};
1213

1314
// Test params
14-
var service = {
15+
var service_options = {
1516
username: 'batman',
1617
password: 'bruce-wayne',
1718
url: 'http://ibm.com:80',
@@ -21,6 +22,14 @@ describe('document_conversion', function() {
2122

2223
var payload = {
2324
conversion_target: 'ANSWER_UNITS',
25+
word: {
26+
heading: {
27+
fonts: [
28+
{ level: 1, min_size: 24 },
29+
{ level: 2, min_size: 16, max_size: 24 }
30+
]
31+
}
32+
},
2433
file: fs.createReadStream(__dirname + '/resources/sampleWORD.docx'),
2534
};
2635

@@ -32,7 +41,7 @@ describe('document_conversion', function() {
3241
nock.cleanAll();
3342
});
3443

35-
var servInstance = watson.document_conversion(service);
44+
var servInstance = watson.document_conversion(service_options);
3645

3746
var missingParameter = function(err) {
3847
assert.ok((err instanceof Error) && /required parameters/.test(err));
@@ -64,9 +73,28 @@ describe('document_conversion', function() {
6473

6574
it('should generate a valid payload', function() {
6675
var req = servInstance.convert(payload, noop);
67-
assert.equal(req.uri.href, service.url + convertPath);
76+
var url = service_options.url + convertPath;
77+
assert.equal(req.uri.href.slice(0, url.length), url);
6878
assert.equal(req.method, 'POST');
6979
assert(req.formData);
7080
});
81+
82+
it('should send extra config params', function() {
83+
var req = servInstance.convert(payload, noop);
84+
var config = JSON.parse(req.formData.config.value);
85+
assert(config.word.heading.fonts);
86+
});
87+
88+
it('should send the version query param', function() {
89+
var req = servInstance.convert(payload, noop);
90+
assert(req.uri.query);
91+
assert(req.uri.query.indexOf("version=") > -1)
92+
});
93+
94+
it('should allow the version query param to be overridden', function() {
95+
var custServInstance = watson.document_conversion(extend(service_options, { version_date: "2015-11-30"}));
96+
var req = custServInstance.convert(payload, noop);
97+
assert(req.uri.query.indexOf("version=2015-11-30" > -1));
98+
});
7199
});
72100
});

test/test.integration-all-services.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
'use strict';
22

3+
var fs = require('fs');
4+
5+
if (fs.existsSync(__dirname + '/resources/auth.js')) {
6+
37
var nock = require('nock');
48
var watson = require('../lib/index');
59
var auth = require('./resources/auth');
6-
var fs = require('fs');
710
var assert = require('assert');
811

912
var mobydick = fs.readFileSync(__dirname + '/resources/mobydick.txt', 'utf8');
1013

1114
var concat = require('concat-stream');
1215
var TWENTY_SECONDS = 20000;
16+
var THIRTY_SECONDS = 30000;
1317
var TEN_SECONDS = 10000;
1418
var FIVE_SECONDS = 5000;
1519
var TWO_SECONDS = 2000;
1620

17-
if (fs.existsSync(__dirname + '/resources/auth.js')) {
18-
1921
describe('integration-all-services', function() {
2022

2123
this.slow(TWO_SECONDS); // this controls when the tests get a colored warning for taking too long
@@ -313,7 +315,7 @@ describe('integration-all-services', function() {
313315
});
314316

315317
describe('functional_dialog', function() {
316-
this.timeout(TWENTY_SECONDS);
318+
this.timeout(THIRTY_SECONDS);
317319
var dialog = watson.dialog(auth.dialog);
318320
var dialog_id = auth.dialog.dialog_id;
319321
var client_id = 31;
@@ -558,7 +560,7 @@ describe('integration-all-services', function() {
558560

559561
it('getImageLinks() with html', function(done) {
560562
alchemy_vision.getImageLinks({
561-
html: '<div><img src="http://visual-recognition-demo.mybluemix.net/images/horses.jpg" /></div>'
563+
html: '<div><img src="https://visual-recognition-demo.mybluemix.net/images/samples/6.jpg" /></div>'
562564
}, failIfError.bind(failIfError, done));
563565
});
564566

@@ -590,7 +592,15 @@ describe('integration-all-services', function() {
590592
it('convertFile()', function(done) {
591593
document_conversion.convert({
592594
file: fs.createReadStream(__dirname + '/resources/sampleWORD.docx'),
593-
conversion_target: 'ANSWER_UNITS'
595+
conversion_target: 'ANSWER_UNITS',
596+
word: {
597+
heading: {
598+
fonts: [
599+
{ level: 1, min_size: 24 },
600+
{ level: 2, min_size: 16, max_size: 24 }
601+
]
602+
}
603+
}
594604
}, failIfError.bind(failIfError, done));
595605
});
596606
});

0 commit comments

Comments
 (0)