@@ -33,7 +33,9 @@ var fakeUtil = extend({}, util, {
3333} ) ;
3434
3535describe ( 'Translate' , function ( ) {
36- var API_KEY = 'api-key' ;
36+ var OPTIONS = {
37+ key : 'api-key'
38+ } ;
3739
3840 var Translate ;
3941 var translate ;
@@ -49,16 +51,14 @@ describe('Translate', function() {
4951 beforeEach ( function ( ) {
5052 makeRequestOverride = null ;
5153
52- translate = new Translate ( {
53- key : API_KEY
54- } ) ;
54+ translate = new Translate ( OPTIONS ) ;
5555 } ) ;
5656
5757 describe ( 'instantiation' , function ( ) {
5858 it ( 'should normalize the arguments' , function ( ) {
5959 var normalizeArguments = fakeUtil . normalizeArguments ;
6060 var normalizeArgumentsCalled = false ;
61- var fakeOptions = { key : API_KEY } ;
61+ var fakeOptions = extend ( { } , OPTIONS ) ;
6262 var fakeContext = { } ;
6363
6464 fakeUtil . normalizeArguments = function ( context , options , cfg ) {
@@ -81,14 +81,48 @@ describe('Translate', function() {
8181 } , / A n A P I k e y i s r e q u i r e d t o u s e t h e T r a n s l a t e A P I \. / ) ;
8282 } ) ;
8383
84+ it ( 'should default baseUrl correctly' , function ( ) {
85+ assert . strictEqual (
86+ translate . baseUrl ,
87+ 'https://www.googleapis.com/language/translate/v2'
88+ ) ;
89+ } ) ;
90+
8491 it ( 'should localize the options' , function ( ) {
85- var options = { key : API_KEY } ;
92+ var options = { key : '...' } ;
8693 var translate = new Translate ( options ) ;
8794 assert . strictEqual ( translate . options , options ) ;
8895 } ) ;
8996
9097 it ( 'should localize the api key' , function ( ) {
91- assert . equal ( translate . key , API_KEY ) ;
98+ assert . equal ( translate . key , OPTIONS . key ) ;
99+ } ) ;
100+
101+ describe ( 'GOOGLE_CLOUD_TRANSLATE_ENDPOINT' , function ( ) {
102+ var CUSTOM_ENDPOINT = '...' ;
103+ var translate ;
104+
105+ before ( function ( ) {
106+ process . env . GOOGLE_CLOUD_TRANSLATE_ENDPOINT = CUSTOM_ENDPOINT ;
107+ translate = new Translate ( OPTIONS ) ;
108+ } ) ;
109+
110+ after ( function ( ) {
111+ delete process . env . GOOGLE_CLOUD_TRANSLATE_ENDPOINT ;
112+ } ) ;
113+
114+ it ( 'should correctly set the baseUrl' , function ( ) {
115+ assert . strictEqual ( translate . baseUrl , CUSTOM_ENDPOINT ) ;
116+ } ) ;
117+
118+ it ( 'should remove trailing slashes' , function ( ) {
119+ var expectedBaseUrl = 'http://localhost:8080' ;
120+
121+ process . env . GOOGLE_CLOUD_TRANSLATE_ENDPOINT = 'http://localhost:8080//' ;
122+
123+ var translate = new Translate ( OPTIONS ) ;
124+ assert . strictEqual ( translate . baseUrl , expectedBaseUrl ) ;
125+ } ) ;
92126 } ) ;
93127 } ) ;
94128
@@ -446,8 +480,8 @@ describe('Translate', function() {
446480 'User-Agent' : userAgent
447481 }
448482 } ) ;
449- var BASE_URL = 'https://www.googleapis.com/language/translate/v2' ;
450- expectedReqOpts . uri = BASE_URL + reqOpts . uri ;
483+
484+ expectedReqOpts . uri = translate . baseUrl + reqOpts . uri ;
451485
452486 makeRequestOverride = function ( reqOpts , options , callback ) {
453487 assert . deepEqual ( reqOpts , expectedReqOpts ) ;
0 commit comments