Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Sep 28, 2016
1 parent 46d1c98 commit 216b575
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
1 change: 1 addition & 0 deletions packages/speech/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function Speech(options) {
};

common.GrpcService.call(this, config, options);

this.api = {
Speech: v1beta1(options).speechApi(options)
};
Expand Down
62 changes: 30 additions & 32 deletions packages/speech/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,8 @@ describe('Speech', function() {
Speech.findFile_ = function(files, callback) {
callback(null, FOUND_FILE);
};

speech.api.Speech.syncRecognize = util.noop;
});

it('should find the files', function(done) {
Expand All @@ -594,16 +596,13 @@ describe('Speech', function() {
});

it('should make the correct request', function(done) {
speech.request = function(protoOpts, reqOpts) {
assert.deepEqual(protoOpts, {
service: 'Speech',
method: 'syncRecognize'
speech.api.Speech.syncRecognize = function(config, file) {
var expectedConfig = extend({}, CONFIG, {
encoding: DETECTED_ENCODING
});
assert.deepEqual(config, expectedConfig);

assert.deepEqual(reqOpts, {
config: extend({}, CONFIG, { encoding: DETECTED_ENCODING }),
audio: FOUND_FILE
});
assert.strictEqual(file, FOUND_FILE);

done();
};
Expand All @@ -620,8 +619,8 @@ describe('Speech', function() {
done(); // Will cause test to fail.
};

speech.request = function(protoOpts, reqOpts) {
assert.strictEqual(reqOpts.config.encoding, config.encoding);
speech.api.Speech.syncRecognize = function(config_) {
assert.strictEqual(config_.encoding, config.encoding);
done();
};

Expand All @@ -636,8 +635,8 @@ describe('Speech', function() {
return expectedEncoding;
};

speech.request = function(protoOpts, reqOpts) {
assert.strictEqual(reqOpts.config.encoding, expectedEncoding);
speech.api.Speech.syncRecognize = function(config) {
assert.strictEqual(config.encoding, expectedEncoding);
done();
};

Expand All @@ -662,7 +661,7 @@ describe('Speech', function() {
var apiResponse = {};

beforeEach(function() {
speech.request = function(protoOpts, reqOpts, callback) {
speech.api.Speech.syncRecognize = function(config, file, callback) {
callback(error, apiResponse);
};
});
Expand Down Expand Up @@ -699,7 +698,7 @@ describe('Speech', function() {
return formattedResults;
};

speech.request = function(protoOpts, reqOpts, callback) {
speech.api.Speech.syncRecognize = function(config, file, callback) {
callback(null, apiResponse);
};
});
Expand Down Expand Up @@ -755,8 +754,8 @@ describe('Speech', function() {
});

it('should delete verbose option from request object', function(done) {
speech.request = function(protoOpts, reqOpts) {
assert.strictEqual(reqOpts.config.verbose, undefined);
speech.api.Speech.syncRecognize = function(config) {
assert.strictEqual(config.verbose, undefined);
done();
};

Expand All @@ -783,6 +782,8 @@ describe('Speech', function() {
Speech.findFile_ = function(files, callback) {
callback(null, FOUND_FILE);
};

speech.api.Speech.asyncRecognize = util.noop;
});

it('should find the files', function(done) {
Expand All @@ -795,16 +796,13 @@ describe('Speech', function() {
});

it('should make the correct request', function(done) {
speech.request = function(protoOpts, reqOpts) {
assert.deepEqual(protoOpts, {
service: 'Speech',
method: 'asyncRecognize'
speech.api.Speech.asyncRecognize = function(config, file) {
var expectedConfig = extend({}, CONFIG, {
encoding: DETECTED_ENCODING
});
assert.deepEqual(config, expectedConfig);

assert.deepEqual(reqOpts, {
config: extend({}, CONFIG, { encoding: DETECTED_ENCODING }),
audio: FOUND_FILE
});
assert.strictEqual(file, FOUND_FILE);

done();
};
Expand All @@ -821,8 +819,8 @@ describe('Speech', function() {
done(); // Will cause test to fail.
};

speech.request = function(protoOpts, reqOpts) {
assert.strictEqual(reqOpts.config.encoding, config.encoding);
speech.api.Speech.asyncRecognize = function(config_) {
assert.strictEqual(config_.encoding, config.encoding);
done();
};

Expand All @@ -837,8 +835,8 @@ describe('Speech', function() {
return expectedEncoding;
};

speech.request = function(protoOpts, reqOpts) {
assert.strictEqual(reqOpts.config.encoding, expectedEncoding);
speech.api.Speech.asyncRecognize = function(config) {
assert.strictEqual(config.encoding, expectedEncoding);
done();
};

Expand All @@ -863,7 +861,7 @@ describe('Speech', function() {
var apiResponse = {};

beforeEach(function() {
speech.request = function(protoOpts, reqOpts, callback) {
speech.api.Speech.asyncRecognize = function(config, file, callback) {
callback(error, apiResponse);
};
});
Expand Down Expand Up @@ -907,7 +905,7 @@ describe('Speech', function() {
return through.obj();
};

speech.request = function(protoOpts, reqOpts, callback) {
speech.api.Speech.asyncRecognize = function(config, file, callback) {
callback(null, apiResponse);
};
});
Expand Down Expand Up @@ -985,8 +983,8 @@ describe('Speech', function() {
});

it('should delete verbose option from request object', function(done) {
speech.request = function(protoOpts, reqOpts) {
assert.strictEqual(reqOpts.config.verbose, undefined);
speech.api.Speech.asyncRecognize = function(config) {
assert.strictEqual(config.verbose, undefined);
done();
};

Expand Down

0 comments on commit 216b575

Please sign in to comment.