Skip to content

Commit 216b575

Browse files
fix tests
1 parent 46d1c98 commit 216b575

2 files changed

Lines changed: 31 additions & 32 deletions

File tree

packages/speech/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ function Speech(options) {
8888
};
8989

9090
common.GrpcService.call(this, config, options);
91+
9192
this.api = {
9293
Speech: v1beta1(options).speechApi(options)
9394
};

packages/speech/test/index.js

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ describe('Speech', function() {
582582
Speech.findFile_ = function(files, callback) {
583583
callback(null, FOUND_FILE);
584584
};
585+
586+
speech.api.Speech.syncRecognize = util.noop;
585587
});
586588

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

596598
it('should make the correct request', function(done) {
597-
speech.request = function(protoOpts, reqOpts) {
598-
assert.deepEqual(protoOpts, {
599-
service: 'Speech',
600-
method: 'syncRecognize'
599+
speech.api.Speech.syncRecognize = function(config, file) {
600+
var expectedConfig = extend({}, CONFIG, {
601+
encoding: DETECTED_ENCODING
601602
});
603+
assert.deepEqual(config, expectedConfig);
602604

603-
assert.deepEqual(reqOpts, {
604-
config: extend({}, CONFIG, { encoding: DETECTED_ENCODING }),
605-
audio: FOUND_FILE
606-
});
605+
assert.strictEqual(file, FOUND_FILE);
607606

608607
done();
609608
};
@@ -620,8 +619,8 @@ describe('Speech', function() {
620619
done(); // Will cause test to fail.
621620
};
622621

623-
speech.request = function(protoOpts, reqOpts) {
624-
assert.strictEqual(reqOpts.config.encoding, config.encoding);
622+
speech.api.Speech.syncRecognize = function(config_) {
623+
assert.strictEqual(config_.encoding, config.encoding);
625624
done();
626625
};
627626

@@ -636,8 +635,8 @@ describe('Speech', function() {
636635
return expectedEncoding;
637636
};
638637

639-
speech.request = function(protoOpts, reqOpts) {
640-
assert.strictEqual(reqOpts.config.encoding, expectedEncoding);
638+
speech.api.Speech.syncRecognize = function(config) {
639+
assert.strictEqual(config.encoding, expectedEncoding);
641640
done();
642641
};
643642

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

664663
beforeEach(function() {
665-
speech.request = function(protoOpts, reqOpts, callback) {
664+
speech.api.Speech.syncRecognize = function(config, file, callback) {
666665
callback(error, apiResponse);
667666
};
668667
});
@@ -699,7 +698,7 @@ describe('Speech', function() {
699698
return formattedResults;
700699
};
701700

702-
speech.request = function(protoOpts, reqOpts, callback) {
701+
speech.api.Speech.syncRecognize = function(config, file, callback) {
703702
callback(null, apiResponse);
704703
};
705704
});
@@ -755,8 +754,8 @@ describe('Speech', function() {
755754
});
756755

757756
it('should delete verbose option from request object', function(done) {
758-
speech.request = function(protoOpts, reqOpts) {
759-
assert.strictEqual(reqOpts.config.verbose, undefined);
757+
speech.api.Speech.syncRecognize = function(config) {
758+
assert.strictEqual(config.verbose, undefined);
760759
done();
761760
};
762761

@@ -783,6 +782,8 @@ describe('Speech', function() {
783782
Speech.findFile_ = function(files, callback) {
784783
callback(null, FOUND_FILE);
785784
};
785+
786+
speech.api.Speech.asyncRecognize = util.noop;
786787
});
787788

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

797798
it('should make the correct request', function(done) {
798-
speech.request = function(protoOpts, reqOpts) {
799-
assert.deepEqual(protoOpts, {
800-
service: 'Speech',
801-
method: 'asyncRecognize'
799+
speech.api.Speech.asyncRecognize = function(config, file) {
800+
var expectedConfig = extend({}, CONFIG, {
801+
encoding: DETECTED_ENCODING
802802
});
803+
assert.deepEqual(config, expectedConfig);
803804

804-
assert.deepEqual(reqOpts, {
805-
config: extend({}, CONFIG, { encoding: DETECTED_ENCODING }),
806-
audio: FOUND_FILE
807-
});
805+
assert.strictEqual(file, FOUND_FILE);
808806

809807
done();
810808
};
@@ -821,8 +819,8 @@ describe('Speech', function() {
821819
done(); // Will cause test to fail.
822820
};
823821

824-
speech.request = function(protoOpts, reqOpts) {
825-
assert.strictEqual(reqOpts.config.encoding, config.encoding);
822+
speech.api.Speech.asyncRecognize = function(config_) {
823+
assert.strictEqual(config_.encoding, config.encoding);
826824
done();
827825
};
828826

@@ -837,8 +835,8 @@ describe('Speech', function() {
837835
return expectedEncoding;
838836
};
839837

840-
speech.request = function(protoOpts, reqOpts) {
841-
assert.strictEqual(reqOpts.config.encoding, expectedEncoding);
838+
speech.api.Speech.asyncRecognize = function(config) {
839+
assert.strictEqual(config.encoding, expectedEncoding);
842840
done();
843841
};
844842

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

865863
beforeEach(function() {
866-
speech.request = function(protoOpts, reqOpts, callback) {
864+
speech.api.Speech.asyncRecognize = function(config, file, callback) {
867865
callback(error, apiResponse);
868866
};
869867
});
@@ -907,7 +905,7 @@ describe('Speech', function() {
907905
return through.obj();
908906
};
909907

910-
speech.request = function(protoOpts, reqOpts, callback) {
908+
speech.api.Speech.asyncRecognize = function(config, file, callback) {
911909
callback(null, apiResponse);
912910
};
913911
});
@@ -985,8 +983,8 @@ describe('Speech', function() {
985983
});
986984

987985
it('should delete verbose option from request object', function(done) {
988-
speech.request = function(protoOpts, reqOpts) {
989-
assert.strictEqual(reqOpts.config.verbose, undefined);
986+
speech.api.Speech.asyncRecognize = function(config) {
987+
assert.strictEqual(config.verbose, undefined);
990988
done();
991989
};
992990

0 commit comments

Comments
 (0)