Skip to content

Commit c0a08d3

Browse files
committed
update jsdoc, end of asynchronous methods, test passed
1 parent df9406b commit c0a08d3

File tree

3 files changed

+82
-9
lines changed

3 files changed

+82
-9
lines changed

speech-to-text/v1.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,26 @@ SpeechToTextV1.prototype.getRecognitionJobs = function(callback) {
188188
return requestFactory(parameters, callback);
189189
};
190190

191+
/**
192+
* Returns the status and ID of all outstanding jobs associated with the service credentials with which it is called.
193+
*
194+
* @param params
195+
* @param params.id - id of the Job
196+
* @param callback
197+
* @returns {ReadableStream|undefined}
198+
*/
191199
SpeechToTextV1.prototype.getRecognitionJob = function(params, callback) {
192200
const missingParams = helper.getMissingParams(params, ['id']);
193201
if (missingParams) {
194202
callback(missingParams);
195203
return;
196204
}
197-
205+
198206
const parameters = {
199207
options: {
200-
requiredParams: ['id'],
201208
method: 'GET',
202209
url: '/v1/recognitions/{id}',
203-
path: pick(params, ['id'])
210+
path: pick(params, ['id']),
204211
json: true
205212
},
206213
defaultOptions: this._options
@@ -209,19 +216,26 @@ SpeechToTextV1.prototype.getRecognitionJob = function(params, callback) {
209216
return requestFactory(parameters, callback);
210217
};
211218

219+
/**
220+
* Deletes the specified job. You cannot delete a job that the service is actively processing.
221+
*
222+
* @param params - The parameters
223+
* @param params.id - id of the Job
224+
* @param callback
225+
* @returns {ReadableStream|undefined}
226+
*/
212227
SpeechToTextV1.prototype.deleteRecognitionJob = function(params, callback) {
213228
const missingParams = helper.getMissingParams(params, ['id']);
214229
if (missingParams) {
215230
callback(missingParams);
216231
return;
217232
}
218-
233+
219234
const parameters = {
220235
options: {
221-
requiredParams: ['id'],
222236
method: 'DELETE',
223237
url: '/v1/recognitions/{id}',
224-
path: pick(params, ['id'])
238+
path: pick(params, ['id']),
225239
json: true
226240
},
227241
defaultOptions: this._options

test/integration/test.speech_to_text.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,16 @@ describe('speech_to_text_integration', function() {
398398
speech_to_text.createRecognitionJob(params, done);
399399
});
400400

401+
it('getRecognitionJobs()', function(done) {
402+
speech_to_text.getRecognitionJobs(done);
403+
});
404+
401405
it('getRecognitionJob()', function(done) {
402-
speech_to_text.getRecognitionsJob(done);
406+
speech_to_text.getRecognitionJob({ id: 'Job01' }, done);
403407
});
404408

409+
it('deleteRecognitionJob()', function(done) {
410+
speech_to_text.getRecognitionJob({ id: 'Job01' }, done);
411+
});
405412
});
406413
});

test/unit/test.speech_to_text.v1.js

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ describe('speech_to_text', function() {
254254
fs.createReadStream(__dirname + '/../resources/weather.wav').pipe(recognizeStream);
255255
recognizeStream.setEncoding('utf8');
256256

257-
// note: none of these tests actually run (or even register with mocha), but the callbacks let the previous test pass :(
257+
// note: none of these tests actually run(or even register with mocha), but the callbacks let the previous test pass :(
258258
recognizeStream.on('connect', function(socket) {
259259
it('should have a socket connection with a correct config', function(done) {
260260
assert.notStrictEqual(socket, socket.config, socket.config.fragmentOutgoingMessages);
@@ -429,10 +429,62 @@ describe('speech_to_text', function() {
429429
assert.equal(JSON.stringify(err), JSON.stringify(null));
430430
assert.equal(JSON.stringify(res), JSON.stringify(response));
431431
};
432-
const req = speech_to_text.getRecognitionsJob(checkRes);
432+
const req = speech_to_text.getRecognitionJobs(checkRes);
433433

434434
assert.equal(req.path, path);
435435
assert.equal(req.method, 'GET');
436436
});
437+
438+
it('should get status of jobs', function() {
439+
const path = '/v1/recognitions/Job01';
440+
const response = {
441+
id: '4bd734c0-e575-21f3-de03-f932aa0468a0',
442+
results: [
443+
{
444+
result_index: 0,
445+
results: [
446+
{
447+
final: true,
448+
alternatives: [
449+
{
450+
transcript: 'several tornadoes touch down as a line of severe thunderstorms swept through Colorado on Sunday ',
451+
timestamps: [['several', 1, 1.52]],
452+
confidence: 0.885
453+
}
454+
]
455+
}
456+
]
457+
}
458+
],
459+
created: '2016-08-17T19:11:04.298Z',
460+
updated: '2016-08-17T19:11:16.003Z',
461+
status: 'completed'
462+
};
463+
464+
nock(service.url).persist().get(path).delay(200).reply(200, response);
465+
466+
const checkRes = function(err, res) {
467+
assert.equal(JSON.stringify(err), JSON.stringify(null));
468+
assert.equal(JSON.stringify(res), JSON.stringify(response));
469+
};
470+
const req = speech_to_text.getRecognitionJob({ id: 'Job01' }, checkRes);
471+
472+
assert.equal(req.path, path);
473+
assert.equal(req.method, 'GET');
474+
});
475+
});
476+
477+
it('should delete a recognition job', function() {
478+
const path = '/v1/recognitions/Job01';
479+
480+
nock(service.url).persist().delete(path).delay(200).reply(200);
481+
482+
const checkRes = function(err, res) {
483+
assert.equal(JSON.stringify(err), JSON.stringify(null));
484+
};
485+
const req = speech_to_text.deleteRecognitionJob({ id: 'Job01' }, checkRes);
486+
487+
assert.equal(req.path, path);
488+
assert.equal(req.method, 'DELETE');
437489
});
438490
});

0 commit comments

Comments
 (0)