Skip to content

Commit

Permalink
all modules: ensure all User-Agents are set (#1568)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored and callmehiphop committed Sep 9, 2016
1 parent 1a14c89 commit 8d55dde
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/google-cloud-translate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"translate"
],
"dependencies": {
"@google-cloud/common": "^0.2.0",
"@google-cloud/common": "^0.5.0",
"arrify": "^1.0.0",
"extend": "^3.0.0",
"is": "^3.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/google-cloud-translate/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ Translate.prototype.request = function(reqOpts, callback) {
key: this.key
},
headers: {
'User-Agent': PKG.name + '/' + PKG.version
'User-Agent': common.util.getUserAgentFromPackageJson(PKG)
}
});

Expand Down
13 changes: 10 additions & 3 deletions packages/google-cloud-translate/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ var extend = require('extend');
var proxyquire = require('proxyquire');
var util = require('@google-cloud/common').util;

var PKG = require('../package.json');

var makeRequestOverride;
var fakeUtil = extend({}, util, {
makeRequest: function() {
Expand Down Expand Up @@ -386,6 +384,15 @@ describe('Translate', function() {

describe('request', function() {
it('should make the correct request', function(done) {
var userAgent = 'user-agent/0.0.0';

var getUserAgentFn = fakeUtil.getUserAgentFromPackageJson;
fakeUtil.getUserAgentFromPackageJson = function(packageJson) {
fakeUtil.getUserAgentFromPackageJson = getUserAgentFn;
assert.deepEqual(packageJson, require('../package.json'));
return userAgent;
};

var reqOpts = {
uri: '/test',
a: 'b',
Expand All @@ -401,7 +408,7 @@ describe('Translate', function() {
key: translate.key
},
headers: {
'User-Agent': PKG.name + '/' + PKG.version
'User-Agent': userAgent
}
});
var BASE_URL = 'https://www.googleapis.com/language/translate/v2';
Expand Down

0 comments on commit 8d55dde

Please sign in to comment.