Skip to content

Commit

Permalink
minor tweaks from PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
callmehiphop committed Nov 11, 2016
1 parent 15a1262 commit 023359d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/translate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var translate = require('@google-cloud/translate')({
It's also possible to authenticate with an API key. To create an API key:

1. Visit the [Google Developers Console][dev-console].
2. 2. Create a new project or click on an existing project.
2. Create a new project or click on an existing project.
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):
* Google Translate API
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.
Expand Down
6 changes: 3 additions & 3 deletions packages/translate/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ Translate.prototype.getLanguages = function(target, callback) {
* not, we set the format as `text`.
* @param {string} options.from - The ISO 639-1 language code the source input
* is written in.
* @param {string} options.model - **Note:** Users must be whitelisted to use
* this parameter. Set the model type requested for this translation. Please
* refer to the upstread documentation for possible values.
* @param {string} options.to - The ISO 639-1 language code to translate the
* input to.
* @param {string} options.model - **Note:** Users must be whitelisted to use
* this parameter. You can use this parameter to take advantage of Neural
* Machine Translation. Possible values are 'base' and 'nmt'.
* @param {function} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
* @param {object|object[]} callback.translations - If a single string input was
Expand Down
12 changes: 12 additions & 0 deletions packages/translate/system-test/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var prop = require('propprop');
var env = require('../../../system-test/env.js');
var Translate = require('../');

var API_KEY = process.env.GCLOUD_TESTS_API_KEY;

describe('translate', function() {
var translate = new Translate(extend({}, env));

Expand Down Expand Up @@ -145,4 +147,14 @@ describe('translate', function() {
});
});
});

(API_KEY ? describe : describe.skip)('authentication', function() {
beforeEach(function() {
translate = new Translate({ key: API_KEY });
});

it('should use an API key to authenticate', function(done) {
translate.getLanguages(done);
});
});
});
21 changes: 9 additions & 12 deletions packages/translate/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@
'use strict';

var assert = require('assert');
var common = require('@google-cloud/common');
var extend = require('extend');
var nodeutil = require('util');
var proxyquire = require('proxyquire');

var Service = common.Service;
var util = common.util;
var util = require('@google-cloud/common').util;

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

function FakeService() {
this.calledWith_ = arguments;
Service.apply(this, arguments);
}

nodeutil.inherits(FakeService, Service);

describe('Translate', function() {
var OPTIONS = {
projectId: 'test-project'
Expand Down Expand Up @@ -98,7 +91,7 @@ describe('Translate', function() {
});

it('should inherit from Service', function() {
assert(translate instanceof Service);
assert(translate instanceof FakeService);

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

it('should localize the api key', function() {
assert.equal(translate.key, KEY_OPTIONS.key);
assert.strictEqual(translate.key, KEY_OPTIONS.key);
});
});

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

it('should correctly set the baseUrl', function() {
assert.strictEqual(translate.baseUrl, CUSTOM_ENDPOINT);
var baseUrl = translate.calledWith_[0].baseUrl;

assert.strictEqual(baseUrl, CUSTOM_ENDPOINT);
});

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

var translate = new Translate(OPTIONS);
assert.strictEqual(translate.baseUrl, expectedBaseUrl);
var baseUrl = translate.calledWith_[0].baseUrl;

assert.strictEqual(baseUrl, expectedBaseUrl);
});
});
});
Expand Down

0 comments on commit 023359d

Please sign in to comment.