@@ -13,12 +13,12 @@ describe('visual_recognition', function() {
1313
1414 // Test params
1515 const service = {
16- api_key : 'batman' ,
16+ username : 'batman' ,
17+ password : 'robin' ,
1718 url : 'http://ibm.com:80/visual-recognition/api' ,
1819 version : '2016-05-20' ,
1920 } ;
2021
21- const api_key_qs = 'api_key=' + service . api_key ;
2222 const version_qs = 'version=' + service . version ;
2323 const fake_file = fs . createReadStream ( __dirname + '/../resources/car.png' ) ;
2424 const fake_buffer = fs . readFileSync ( __dirname + '/../resources/car.png' ) ;
@@ -29,10 +29,10 @@ describe('visual_recognition', function() {
2929 } ,
3030 } ;
3131
32- const classify_path = '/v3/classify?' + api_key_qs + '&' + version_qs ;
33- const detect_faces_path = '/v3/detect_faces?' + api_key_qs + '&' + version_qs ;
34- const classifiers_path = '/v3/classifiers?' + api_key_qs + '&' + version_qs ;
35- const foo_classifiers_path = '/v3/classifiers/foo?' + api_key_qs + '&' + version_qs ;
32+ const classify_path = '/v3/classify?' + version_qs ;
33+ const detect_faces_path = '/v3/detect_faces?' + version_qs ;
34+ const classifiers_path = '/v3/classifiers?' + version_qs ;
35+ const foo_classifiers_path = '/v3/classifiers/foo?' + version_qs ;
3636 const mock_classify = {
3737 images : [
3838 {
@@ -117,70 +117,24 @@ describe('visual_recognition', function() {
117117 ) ;
118118 } ) ;
119119
120- it ( 'should accept an API key for regular usage' , ( ) =>
121- new watson . VisualRecognitionV3 ( {
122- api_key : 'foo' ,
123- version : '2016-05-20' ,
124- } ) ) ;
125-
126120 it ( 'should accept username/password for regular usage' , ( ) =>
127121 new watson . VisualRecognitionV3 ( {
128122 username : 'foo' ,
129123 password : 'bar' ,
130124 version : '2016-05-20' ,
131125 } ) ) ;
132126
133- it ( 'should accept VISUAL_RECOGNITION_API_KEY env property' , ( ) => {
134- process . env . VISUAL_RECOGNITION_API_KEY = 'foo' ;
135- return new watson . VisualRecognitionV3 ( { version : '2016-05-20' } ) ;
136- } ) ;
137-
138- it ( 'should read VISUAL_RECOGNITION_API_KEY environment property' , function ( ) {
139- process . env = {
140- VISUAL_RECOGNITION_API_KEY : 'foo' ,
141- } ;
142- const instance = new watson . VisualRecognitionV3 ( {
143- version : '2016-05-20' ,
144- } ) ;
145- assert . equal ( instance . _options . api_key , 'foo' ) ;
146- assert . equal ( instance . _options . username , undefined ) ;
147- assert . equal ( instance . _options . password , undefined ) ;
148- } ) ;
149-
150127 it ( 'should read VISUAL_RECOGNITION_USERNAME / PASSWORD from environment properties' , function ( ) {
151128 process . env . VISUAL_RECOGNITION_USERNAME = 'foo' ;
152129 process . env . VISUAL_RECOGNITION_PASSWORD = 'bar' ;
153130 const instance = new watson . VisualRecognitionV3 ( {
154131 version : '2016-05-20' ,
155132 } ) ;
156- assert . equal ( instance . _options . api_key , undefined ) ;
133+
157134 assert . equal ( instance . _options . username , 'foo' ) ;
158135 assert . equal ( instance . _options . password , 'bar' ) ;
159136 } ) ;
160137
161- it ( 'should read api_key from cf/bluemix environment properties' , function ( ) {
162- process . env . VCAP_SERVICES = JSON . stringify ( {
163- watson_vision_combined : [
164- {
165- name : 'Visual Recognition-mj' ,
166- label : 'watson_vision_combined' ,
167- plan : 'free' ,
168- credentials : {
169- url : 'https://gateway-a.watsonplatform.net/visual-recognition/api' ,
170- note : 'It may take up to 5 minutes for this key to become active' ,
171- api_key : 'foo' ,
172- } ,
173- } ,
174- ] ,
175- } ) ;
176- const instance = new watson . VisualRecognitionV3 ( {
177- version : '2016-05-20' ,
178- } ) ;
179- assert . equal ( instance . _options . api_key , 'foo' ) ;
180- assert . equal ( instance . _options . username , undefined ) ;
181- assert . equal ( instance . _options . password , undefined ) ;
182- } ) ;
183-
184138 it ( 'should read username / password from cf/bluemix environment properties' , function ( ) {
185139 process . env . VCAP_SERVICES = JSON . stringify ( {
186140 watson_vision_combined : [
@@ -200,7 +154,7 @@ describe('visual_recognition', function() {
200154 const instance = new watson . VisualRecognitionV3 ( {
201155 version : '2016-05-20' ,
202156 } ) ;
203- assert . equal ( instance . _options . api_key , undefined ) ;
157+
204158 assert . equal ( instance . _options . username , 'foo' ) ;
205159 assert . equal ( instance . _options . password , 'bar' ) ;
206160 } ) ;
@@ -454,7 +408,7 @@ describe('visual_recognition', function() {
454408 it ( 'should make a DELETE request and return the result' , function ( done ) {
455409 const scope = nock ( 'http://ibm.com:80' , { encodedQueryParams : true } )
456410 . delete ( '/visual-recognition/api/v3/classifiers/foo_123' )
457- . query ( { api_key : 'batman' , version : '2016-05-20' } )
411+ . query ( { version : '2016-05-20' } )
458412 . reply ( 200 , { } ) ;
459413
460414 visual_recognition . deleteClassifier (
@@ -498,7 +452,7 @@ describe('visual_recognition', function() {
498452 } ;
499453 const scope = nock ( 'http://ibm.com:80' , { encodedQueryParams : true } )
500454 . get ( '/visual-recognition/api/v3/classifiers/fruit_679357912' )
501- . query ( { api_key : 'batman' , version : '2016-05-20' } )
455+ . query ( { version : '2016-05-20' } )
502456 . reply ( 200 , expected ) ;
503457
504458 visual_recognition . getClassifier (
@@ -526,64 +480,6 @@ describe('visual_recognition', function() {
526480 afterEach ( function ( ) {
527481 process . env = env ;
528482 } ) ;
529- it ( 'should have the correct URL depending on rc/cf' , function ( done ) {
530- const visual_recognition_cf = new watson . VisualRecognitionV3 ( {
531- api_key : 'apikey' ,
532- version : '2018-03-19' ,
533- } ) ;
534- const visual_recognition_rc = new watson . VisualRecognitionV3 ( {
535- iam_apikey : 'iam_apikey' ,
536- version : '2018-03-19' ,
537- } ) ;
538- const visual_recognition_url = new watson . VisualRecognitionV3 ( {
539- api_key : 'apikey' ,
540- url : 'hello.com' ,
541- version : '2018-03-19' ,
542- } ) ;
543-
544- assert . equal (
545- visual_recognition_cf . _options . url ,
546- 'https://gateway-a.watsonplatform.net/visual-recognition/api'
547- ) ;
548- assert . equal (
549- visual_recognition_rc . _options . url ,
550- 'https://gateway.watsonplatform.net/visual-recognition/api'
551- ) ;
552- assert . equal ( visual_recognition_url . _options . url , 'hello.com' ) ;
553- done ( ) ;
554- } ) ;
555-
556- it ( 'should load its credentials from bluemix (VR) with correct url' , function ( ) {
557- process . env . VCAP_SERVICES = JSON . stringify ( {
558- watson_vision_combined : [
559- {
560- credentials : {
561- api_key : 'somekey' ,
562- } ,
563- } ,
564- ] ,
565- } ) ;
566- const visual_recognition_bluemix = new watson . VisualRecognitionV3 ( {
567- version : '2018-03-19' ,
568- } ) ;
569- assert ( visual_recognition_bluemix ) ;
570- assert . equal (
571- visual_recognition_bluemix . getCredentials ( ) . url ,
572- 'https://gateway-a.watsonplatform.net/visual-recognition/api'
573- ) ;
574- } ) ;
575-
576- it ( 'should load its credentials from environment (VR)' , function ( ) {
577- process . env . VISUAL_RECOGNITION_API_KEY = 'key' ;
578- const visual_recognition_env = new watson . VisualRecognitionV3 ( {
579- version : '2018-03-19' ,
580- } ) ;
581- assert ( visual_recognition_env ) ;
582- assert . equal (
583- visual_recognition_env . getCredentials ( ) . url ,
584- 'https://gateway-a.watsonplatform.net/visual-recognition/api'
585- ) ;
586- } ) ;
587483
588484 it ( 'should load its credentials from bluemix (VR) with correct url (RC)' , function ( ) {
589485 process . env . VCAP_SERVICES = JSON . stringify ( {
@@ -629,10 +525,7 @@ describe('visual_recognition', function() {
629525 const params = { classifier_id : 'foo' } ;
630526
631527 const req = visual_recognition . getCoreMlModel ( params , noop ) ;
632- assert . equal (
633- req . uri . href ,
634- service . url + '/v3/classifiers/foo/core_ml_model?' + api_key_qs + '&' + version_qs
635- ) ;
528+ assert . equal ( req . uri . href , service . url + '/v3/classifiers/foo/core_ml_model?' + version_qs ) ;
636529 assert . equal ( req . method , 'GET' ) ;
637530 } ) ;
638531 } ) ;
0 commit comments