Skip to content

Commit 023359d

Browse files
committed
minor tweaks from PR feedback
1 parent 15a1262 commit 023359d

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

packages/translate/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ var translate = require('@google-cloud/translate')({
110110
It's also possible to authenticate with an API key. To create an API key:
111111

112112
1. Visit the [Google Developers Console][dev-console].
113-
2. 2. Create a new project or click on an existing project.
113+
2. Create a new project or click on an existing project.
114114
3. Navigate to **APIs & auth** > **APIs section** and turn on the following APIs (you may need to enable billing in order to use these services):
115115
* Google Translate API
116116
4. Navigate to **APIs & auth** > **Credentials** and then click on **Create new Client ID** and select **API key**. You should then be presented with a pop-up containing your newly created key.

packages/translate/src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,11 @@ Translate.prototype.getLanguages = function(target, callback) {
310310
* not, we set the format as `text`.
311311
* @param {string} options.from - The ISO 639-1 language code the source input
312312
* is written in.
313+
* @param {string} options.model - **Note:** Users must be whitelisted to use
314+
* this parameter. Set the model type requested for this translation. Please
315+
* refer to the upstread documentation for possible values.
313316
* @param {string} options.to - The ISO 639-1 language code to translate the
314317
* input to.
315-
* @param {string} options.model - **Note:** Users must be whitelisted to use
316-
* this parameter. You can use this parameter to take advantage of Neural
317-
* Machine Translation. Possible values are 'base' and 'nmt'.
318318
* @param {function} callback - The callback function.
319319
* @param {?error} callback.err - An error returned while making this request.
320320
* @param {object|object[]} callback.translations - If a single string input was

packages/translate/system-test/translate.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ var prop = require('propprop');
2323
var env = require('../../../system-test/env.js');
2424
var Translate = require('../');
2525

26+
var API_KEY = process.env.GCLOUD_TESTS_API_KEY;
27+
2628
describe('translate', function() {
2729
var translate = new Translate(extend({}, env));
2830

@@ -145,4 +147,14 @@ describe('translate', function() {
145147
});
146148
});
147149
});
150+
151+
(API_KEY ? describe : describe.skip)('authentication', function() {
152+
beforeEach(function() {
153+
translate = new Translate({ key: API_KEY });
154+
});
155+
156+
it('should use an API key to authenticate', function(done) {
157+
translate.getLanguages(done);
158+
});
159+
});
148160
});

packages/translate/test/index.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717
'use strict';
1818

1919
var assert = require('assert');
20-
var common = require('@google-cloud/common');
2120
var extend = require('extend');
22-
var nodeutil = require('util');
2321
var proxyquire = require('proxyquire');
24-
25-
var Service = common.Service;
26-
var util = common.util;
22+
var util = require('@google-cloud/common').util;
2723

2824
var makeRequestOverride;
2925
var promisified = false;
@@ -44,11 +40,8 @@ var fakeUtil = extend({}, util, {
4440

4541
function FakeService() {
4642
this.calledWith_ = arguments;
47-
Service.apply(this, arguments);
4843
}
4944

50-
nodeutil.inherits(FakeService, Service);
51-
5245
describe('Translate', function() {
5346
var OPTIONS = {
5447
projectId: 'test-project'
@@ -98,7 +91,7 @@ describe('Translate', function() {
9891
});
9992

10093
it('should inherit from Service', function() {
101-
assert(translate instanceof Service);
94+
assert(translate instanceof FakeService);
10295

10396
var calledWith = translate.calledWith_[0];
10497
var baseUrl = 'https://translation.googleapis.com/language/translate/v2';
@@ -126,7 +119,7 @@ describe('Translate', function() {
126119
});
127120

128121
it('should localize the api key', function() {
129-
assert.equal(translate.key, KEY_OPTIONS.key);
122+
assert.strictEqual(translate.key, KEY_OPTIONS.key);
130123
});
131124
});
132125

@@ -144,7 +137,9 @@ describe('Translate', function() {
144137
});
145138

146139
it('should correctly set the baseUrl', function() {
147-
assert.strictEqual(translate.baseUrl, CUSTOM_ENDPOINT);
140+
var baseUrl = translate.calledWith_[0].baseUrl;
141+
142+
assert.strictEqual(baseUrl, CUSTOM_ENDPOINT);
148143
});
149144

150145
it('should remove trailing slashes', function() {
@@ -153,7 +148,9 @@ describe('Translate', function() {
153148
process.env.GOOGLE_CLOUD_TRANSLATE_ENDPOINT = 'http://localhost:8080//';
154149

155150
var translate = new Translate(OPTIONS);
156-
assert.strictEqual(translate.baseUrl, expectedBaseUrl);
151+
var baseUrl = translate.calledWith_[0].baseUrl;
152+
153+
assert.strictEqual(baseUrl, expectedBaseUrl);
157154
});
158155
});
159156
});

0 commit comments

Comments
 (0)