@@ -19,6 +19,7 @@ const assert = require('assert');
1919const Client = require ( '../lib/client.js' ) ;
2020const Cloudant = require ( '../cloudant.js' ) ;
2121const nock = require ( './nock.js' ) ;
22+ const u = require ( 'url' ) ;
2223const uuidv4 = require ( 'uuid/v4' ) ; // random
2324
2425const ME = process . env . cloudant_username || 'nodejs' ;
@@ -53,7 +54,7 @@ describe('#db README Examples', function() {
5354 . put ( `/${ DBNAME } ` )
5455 . reply ( 201 , { ok : true } ) ;
5556
56- var cloudant = Cloudant ( { account : ME , password : PASSWORD } ) ;
57+ var cloudant = Cloudant ( { username : ME , password : PASSWORD , url : SERVER } ) ;
5758 cloudant . db . create ( DBNAME ) . then ( ( ) => {
5859 mocks . done ( ) ;
5960 done ( ) ;
@@ -67,7 +68,7 @@ describe('#db README Examples', function() {
6768 . put ( `/${ DBNAME } /rabbit` , { happy : true } )
6869 . reply ( 200 , { ok : true , _id : 'rabbit' } ) ;
6970
70- var cloudant = Cloudant ( { account : ME , password : PASSWORD } ) ;
71+ var cloudant = Cloudant ( { username : ME , password : PASSWORD , url : SERVER } ) ;
7172
7273 async function asyncCall ( ) {
7374 await cloudant . db . create ( DBNAME ) ;
@@ -88,7 +89,7 @@ describe('#db README Examples', function() {
8889 . put ( `/${ DBNAME } /rabbit` , { happy : true } )
8990 . reply ( 200 , { ok : true , _id : 'rabbit' } ) ;
9091
91- var cloudant = Cloudant ( { account : ME , password : PASSWORD } ) ;
92+ var cloudant = Cloudant ( { username : ME , password : PASSWORD , url : SERVER } ) ;
9293
9394 cloudant . db . create ( DBNAME ) . then ( ( ) => {
9495 cloudant . use ( DBNAME ) . insert ( { happy : true } , 'rabbit' ) . then ( ( data ) => {
@@ -106,7 +107,7 @@ describe('#db README Examples', function() {
106107 . put ( `/${ DBNAME } /rabbit` , { happy : true } )
107108 . reply ( 200 , { ok : true , _id : 'rabbit' } ) ;
108109
109- var cloudant = Cloudant ( { account : ME , password : PASSWORD } ) ;
110+ var cloudant = Cloudant ( { username : ME , password : PASSWORD , url : SERVER } ) ;
110111
111112 cloudant . db . create ( DBNAME , ( err ) => {
112113 assert . ifError ( err ) ;
@@ -126,7 +127,7 @@ describe('#db README Examples', function() {
126127 . get ( '/_session' )
127128 . reply ( 200 , { userCtx : { name : null } } ) ;
128129
129- var cloudant = Cloudant ( `https:// ${ ME } .cloudant.com` ) ;
130+ var cloudant = Cloudant ( SERVER ) ;
130131 cloudant . session ( ) . then ( ( session ) => {
131132 assert . equal ( session . userCtx . name , null ) ;
132133 mocks . done ( ) ;
@@ -139,10 +140,13 @@ describe('#db README Examples', function() {
139140 . get ( '/_session' )
140141 . reply ( 200 , { userCtx : { name : ME } } ) ;
141142
142- var cloudant = Cloudant ( { username : ME , password : PASSWORD , url : `https:// ${ ME } .cloudant.com` } ) ;
143+ var cloudant = Cloudant ( { username : ME , password : PASSWORD , url : SERVER } ) ;
143144 cloudant . session ( ) . then ( ( session ) => {
144145 assert . equal ( session . userCtx . name , ME ) ;
145- assert . equal ( cloudant . config . url , `https://${ ME } :${ PASSWORD } @${ ME } .cloudant.com` ) ;
146+ let actual = new u . URL ( cloudant . config . url ) ;
147+ assert . equal ( actual . username , ME ) ;
148+ assert . equal ( actual . password , PASSWORD ) ;
149+ assert . equal ( actual . origin , SERVER ) ;
146150 mocks . done ( ) ;
147151 done ( ) ;
148152 } ) . catch ( done ) ;
@@ -153,10 +157,13 @@ describe('#db README Examples', function() {
153157 . get ( '/_session' )
154158 . reply ( 200 , { userCtx : { name : ME } } ) ;
155159
156- var cloudant = Cloudant ( { account : ME , password : PASSWORD } ) ;
160+ var cloudant = Cloudant ( { username : ME , password : PASSWORD , url : SERVER } ) ;
157161 cloudant . session ( ) . then ( ( session ) => {
158162 assert . equal ( session . userCtx . name , ME ) ;
159- assert . equal ( cloudant . config . url , `https://${ ME } :${ PASSWORD } @${ ME } .cloudant.com` ) ;
163+ let actual = new u . URL ( cloudant . config . url ) ;
164+ assert . equal ( actual . username , ME ) ;
165+ assert . equal ( actual . password , PASSWORD ) ;
166+ assert . equal ( actual . origin , SERVER ) ;
160167 mocks . done ( ) ;
161168 done ( ) ;
162169 } ) . catch ( done ) ;
@@ -193,7 +200,7 @@ describe('#db README Examples', function() {
193200 . get ( '/_all_dbs' )
194201 . reply ( 200 , [ 'animaldb' ] ) ;
195202
196- Cloudant ( { account : ME , password : PASSWORD } , function ( err , cloudant , pong ) {
203+ Cloudant ( { username : ME , password : PASSWORD , url : SERVER } , function ( err , cloudant , pong ) {
197204 assert . ifError ( err ) ;
198205 assert . equal ( pong . couchdb , 'Welcome' ) ;
199206
@@ -212,7 +219,7 @@ describe('#db README Examples', function() {
212219 . get ( '/animaldb/non-existent-doc' )
213220 . reply ( 404 , { error : 'not_found' , reason : 'missing' } ) ;
214221
215- var cloudant = Cloudant ( { account : ME , password : PASSWORD } ) ;
222+ var cloudant = Cloudant ( { username : ME , password : PASSWORD , url : SERVER } ) ;
216223 var db = cloudant . db . use ( 'animaldb' ) ;
217224 db . get ( 'non-existent-doc' , function ( err , data ) {
218225 assert . equal ( err . name , 'Error' ) ;
@@ -229,7 +236,7 @@ describe('#db README Examples', function() {
229236 . get ( '/animaldb/panda' )
230237 . reply ( 200 , { _id : 'panda' , 'max_weight' : 115 } ) ;
231238
232- var cloudant = Cloudant ( { account : ME , password : PASSWORD } ) ;
239+ var cloudant = Cloudant ( { username : ME , password : PASSWORD , url : SERVER } ) ;
233240 var db = cloudant . db . use ( 'animaldb' ) ;
234241 db . get ( 'panda' , function ( err , data ) {
235242 assert . ifError ( err ) ;
@@ -244,7 +251,7 @@ describe('#db README Examples', function() {
244251 . get ( '/animaldb/panda' )
245252 . reply ( 200 , { _id : 'panda' } ) ;
246253
247- var cloudant = Cloudant ( { account : ME , password : PASSWORD } ) ;
254+ var cloudant = Cloudant ( { username : ME , password : PASSWORD , url : SERVER } ) ;
248255 var db = cloudant . db . use ( 'animaldb' ) ;
249256 db . get ( 'panda' , function ( err , data , headers ) {
250257 assert . ifError ( err ) ;
@@ -329,7 +336,7 @@ describe('#db README Examples', function() {
329336 . get ( '/_api/v2/db/animaldb/_security' )
330337 . reply ( 200 , { ok : true } ) ;
331338
332- var cloudant = Cloudant ( { account : ME , password : PASSWORD } ) ;
339+ var cloudant = Cloudant ( { username : ME , password : PASSWORD , url : SERVER } ) ;
333340 cloudant . generate_api_key ( function ( err , api ) {
334341 assert . ifError ( err ) ;
335342 assert . equal ( api . key , 'foo' ) ;
@@ -368,7 +375,7 @@ describe('#db README Examples', function() {
368375 } )
369376 . reply ( 200 , { ok : true } ) ;
370377
371- var cloudant = Cloudant ( { account : ME , password : PASSWORD } ) ;
378+ var cloudant = Cloudant ( { username : ME , password : PASSWORD , url : SERVER } ) ;
372379 cloudant . set_cors ( {
373380 enable_cors : true ,
374381 allow_credentials : true ,
@@ -393,7 +400,7 @@ describe('#db README Examples', function() {
393400 } )
394401 . reply ( 200 , { ok : true } ) ;
395402
396- var cloudant = Cloudant ( { account : ME , password : PASSWORD } ) ;
403+ var cloudant = Cloudant ( { username : ME , password : PASSWORD , url : SERVER } ) ;
397404 cloudant . set_cors ( {
398405 enable_cors : true ,
399406 allow_credentials : true ,
@@ -416,7 +423,7 @@ describe('#db README Examples', function() {
416423 } )
417424 . reply ( 200 , { ok : true } ) ;
418425
419- var cloudant = Cloudant ( { account : ME , password : PASSWORD } ) ;
426+ var cloudant = Cloudant ( { username : ME , password : PASSWORD , url : SERVER } ) ;
420427 cloudant . set_cors ( {
421428 enable_cors : true ,
422429 origins : [ ]
@@ -440,7 +447,7 @@ describe('#db README Examples', function() {
440447 origins : [ 'https://example.com' ]
441448 } ) ;
442449
443- var cloudant = Cloudant ( { account : ME , password : PASSWORD } ) ;
450+ var cloudant = Cloudant ( { username : ME , password : PASSWORD , url : SERVER } ) ;
444451 cloudant . get_cors ( ) . then ( ( data ) => {
445452 assert . ok ( data . enable_cors ) ;
446453 assert . ok ( data . allow_credentials ) ;
0 commit comments