2828require ( 'dotenv' ) . config ( { silent : true } ) ;
2929
3030var should = require ( 'should' ) ;
31-
3231var nock = require ( '../nock.js' ) ;
32+ const uuid = require ( 'uuid/v4' ) ;
3333var ME = process . env . cloudant_username || 'nodejs' ;
3434var PASSWORD = process . env . cloudant_password || 'sjedon' ;
3535var SERVER = 'https://' + ME + '.cloudant.com' ;
@@ -43,13 +43,15 @@ require = function(module) {
4343
4444// Disable console.log
4545var console = { log : function ( ) { } } ;
46+ const alice = `nodejs_cloudant_test_${ uuid ( ) } `
47+ const my_db = `nodejs_cloudant_test_${ uuid ( ) } `
4648
4749describe ( 'Getting Started' , function ( ) {
4850 var mocks ;
4951 after ( function ( done ) {
5052 var Cloudant = require ( '@cloudant/cloudant' ) ;
5153 var cloudant = Cloudant ( { account : ME , password : PASSWORD , plugins : 'retry' } ) ;
52- cloudant . db . destroy ( ' alice' , function ( er , d ) {
54+ cloudant . db . destroy ( alice , function ( er , d ) {
5355 should ( er ) . equal ( null ) ;
5456 d . should . be . an . Object ;
5557 d . should . have . a . property ( 'ok' ) ;
@@ -62,10 +64,10 @@ describe('Getting Started', function() {
6264 before ( function ( ) {
6365 mocks = nock ( SERVER )
6466 . get ( '/_all_dbs' ) . reply ( 200 , [ 'database_changes' , 'third_party_db' ] )
65- . delete ( '/ alice' ) . reply ( 404 , { error : 'not_found' , reason : 'Database does not exist.' } )
66- . put ( '/ alice' ) . reply ( 201 , { ok : true } )
67- . put ( '/ alice/rabbit' ) . reply ( 201 , { ok : true , id : 'rabbit' , rev : '1-6e4cb465d49c0368ac3946506d26335d' } )
68- . delete ( '/ alice' ) . reply ( 200 , { ok : true } ) ;
67+ . delete ( `/ ${ alice } ` ) . reply ( 404 , { error : 'not_found' , reason : 'Database does not exist.' } )
68+ . put ( `/ ${ alice } ` ) . reply ( 201 , { ok : true } )
69+ . put ( `/ ${ alice } /rabbit` ) . reply ( 201 , { ok : true , id : 'rabbit' , rev : '1-6e4cb465d49c0368ac3946506d26335d' } )
70+ . delete ( `/ ${ alice } ` ) . reply ( 200 , { ok : true } ) ;
6971 } ) ;
7072
7173 it ( 'Example 1' , function ( done ) {
@@ -95,14 +97,14 @@ describe('Getting Started', function() {
9597 var cloudant = Cloudant ( { account : username , password : password , plugins : 'retry' } ) ;
9698
9799 // Remove any existing database called "alice".
98- cloudant . db . destroy ( ' alice' , function ( err ) {
100+ cloudant . db . destroy ( alice , function ( err ) {
99101 // Create a new "alice" database.
100- cloudant . db . create ( ' alice' , function ( ) {
102+ cloudant . db . create ( alice , function ( ) {
101103 // Specify the database we are going to use (alice)...
102- var alice = cloudant . db . use ( ' alice' ) ;
104+ var aliceDb = cloudant . db . use ( alice ) ;
103105
104106 // ...and insert a document in it.
105- alice . insert ( { crazy : true } , 'rabbit' , function ( err , body , header ) {
107+ aliceDb . insert ( { crazy : true } , 'rabbit' , function ( err , body , header ) {
106108 if ( err ) {
107109 return console . log ( '[alice.insert] ' , err . message ) ;
108110 }
@@ -369,30 +371,30 @@ describe('Cloudant Query', function() {
369371 var mocks ;
370372 before ( function ( ) {
371373 mocks = nock ( SERVER )
372- . put ( '/ my_db' )
374+ . put ( `/ ${ my_db } ` )
373375 . reply ( 200 , { ok : true } )
374- . get ( '/ my_db/_index' )
376+ . get ( `/ ${ my_db } /_index` )
375377 . reply ( 200 , { indexes : [ { name : '_all_docs' , type : 'special' , def : { fields : [ { _id : 'asc' } ] } } ] } )
376- . post ( '/ my_db/_index' )
378+ . post ( `/ ${ my_db } /_index` )
377379 . reply ( 200 , { result : 'created' , id : '_design/778580d5684fd367424e39735f7857f2e9fb0eb9' , name : 'first-name' } )
378- . post ( '/ my_db/_find' )
380+ . post ( `/ ${ my_db } /_find` )
379381 . reply ( 200 , { docs : [ ] } )
380- . delete ( '/ my_db' )
382+ . delete ( `/ ${ my_db } ` )
381383 . reply ( 200 , { ok : true } ) ;
382384 } ) ;
383385
384386 var cloudant , db ;
385387 before ( function ( done ) {
386388 var Cloudant = require ( '@cloudant/cloudant' ) ;
387389 cloudant = Cloudant ( { account : ME , password : process . env . cloudant_password , plugins : 'retry' } ) ;
388- cloudant . db . create ( ' my_db' , function ( er ) {
390+ cloudant . db . create ( my_db , function ( er ) {
389391 if ( er ) throw er ;
390- db = cloudant . db . use ( ' my_db' ) ;
392+ db = cloudant . db . use ( my_db ) ;
391393 done ( ) ;
392394 } ) ;
393395 } ) ;
394396 after ( function ( done ) {
395- cloudant . db . destroy ( ' my_db' , function ( er ) {
397+ cloudant . db . destroy ( my_db , function ( er ) {
396398 if ( er ) throw er ;
397399 mocks . done ( ) ;
398400 done ( ) ;
@@ -429,7 +431,7 @@ describe('Cloudant Query', function() {
429431 } ) ;
430432
431433 it ( 'Example 3' , function ( done ) {
432- db . find ( { selector : { name : 'Alice' } } , function ( er , result ) {
434+ db . find ( { selector : { name : alice } } , function ( er , result ) {
433435 if ( er ) {
434436 throw er ;
435437 }
@@ -449,32 +451,32 @@ describe('Cloudant Search', function() {
449451 var mocks ;
450452 before ( function ( ) {
451453 mocks = nock ( SERVER )
452- . put ( '/ my_db' )
454+ . put ( `/ ${ my_db } ` )
453455 . reply ( 200 , { ok : true } )
454- . post ( '/ my_db/_bulk_docs' )
456+ . post ( `/ ${ my_db } /_bulk_docs` )
455457 . reply ( 200 , [ { id : '764de7aeca95c27fdd7fb6565dcfc0fe' , rev : '1-eadaf74c0058257fcb498c3017dde3e5' } ,
456458 { id : '764de7aeca95c27fdd7fb6565dcfc4f5' , rev : '1-c22d5563f4b9cddde6f26a47cd1ce88f' } ,
457459 { id : '764de7aeca95c27fdd7fb6565dcfc727' , rev : '1-86039ff130d36c08a71b3f293fd4ea7e' } ] )
458- . post ( '/ my_db' )
460+ . post ( `/ ${ my_db } ` )
459461 . reply ( 200 , { ok : true , id : '_design/library' , rev : '1-cdbb57f890d060055b7fb8cb07628068' } )
460- . get ( '/ my_db/_design/library/_search/books' ) . query ( true )
462+ . get ( `/ ${ my_db } /_design/library/_search/books` ) . query ( true )
461463 . reply ( 200 , { total_rows : 2 , rows : [ { id : '764de7aeca95c27fdd7fb6565dcfc0fe' } , { id : '764de7aeca95c27fdd7fb6565dcfc727' } ] } )
462- . delete ( '/ my_db' )
464+ . delete ( `/ ${ my_db } ` )
463465 . reply ( 200 , { ok : true } ) ;
464466 } ) ;
465467
466468 var cloudant , db ;
467469 before ( function ( done ) {
468470 var Cloudant = require ( '@cloudant/cloudant' ) ;
469471 cloudant = Cloudant ( { account : ME , password : process . env . cloudant_password , plugins : 'retry' } ) ;
470- cloudant . db . create ( ' my_db' , function ( er ) {
472+ cloudant . db . create ( my_db , function ( er ) {
471473 if ( er ) throw er ;
472- db = cloudant . db . use ( ' my_db' ) ;
474+ db = cloudant . db . use ( my_db ) ;
473475 done ( ) ;
474476 } ) ;
475477 } ) ;
476478 after ( function ( done ) {
477- cloudant . db . destroy ( ' my_db' , function ( er ) {
479+ cloudant . db . destroy ( my_db , function ( er ) {
478480 if ( er ) throw er ;
479481 mocks . done ( ) ;
480482 done ( ) ;
@@ -554,22 +556,22 @@ describe('Cookie Authentication', function() {
554556 after ( function ( done ) {
555557 var Cloudant = require ( '@cloudant/cloudant' ) ;
556558 cloudant = Cloudant ( { account : ME , password : process . env . cloudant_password , plugins : [ ] } ) ;
557- cloudant . db . destroy ( ' alice' , function ( ) {
559+ cloudant . db . destroy ( alice , function ( ) {
558560 mocks . done ( ) ;
559561 done ( ) ;
560562 } ) ;
561563 } ) ;
562564 before ( function ( done ) {
563565 mocks = nock ( SERVER )
564566 . post ( '/_session' ) . reply ( 200 , { ok : true , name : ME , roles : [ ] } , { 'set-cookie' : [ 'AuthSession=bm9kZWpzOjU1RTA1NDdEOsUsoq9lykQCEBhwTpIyEbgmYpvX; Version=1; Expires=Sat, 29 Aug 2015 12:30:53 GMT; Max-Age=86400; Path=/; HttpOnly; Secure' ] } )
565- . put ( '/ alice' ) . reply ( 200 , { ok : true } )
566- . post ( '/ alice' ) . reply ( 200 , { ok : true , id : '72e0367f3e195340e239948164bbb7e7' , rev : '1-feb5539029f4fc50dc3f827b164a2088' } )
567+ . put ( `/ ${ alice } ` ) . reply ( 200 , { ok : true } )
568+ . post ( `/ ${ alice } ` ) . reply ( 200 , { ok : true , id : '72e0367f3e195340e239948164bbb7e7' , rev : '1-feb5539029f4fc50dc3f827b164a2088' } )
567569 . get ( '/_session' ) . reply ( 200 , { ok : true , userCtx : { name : ME , roles : [ '_admin' , '_reader' , '_writer' ] } } )
568- . delete ( '/ alice' ) . reply ( 200 , { ok : true } ) ;
570+ . delete ( `/ ${ alice } ` ) . reply ( 200 , { ok : true } ) ;
569571
570572 var Cloudant = require ( '@cloudant/cloudant' ) ;
571573 cloudant = Cloudant ( { account : ME , password : process . env . cloudant_password , plugins : [ ] } ) ;
572- cloudant . db . create ( ' alice' , function ( ) {
574+ cloudant . db . create ( alice , function ( ) {
573575 done ( ) ;
574576 } ) ;
575577 } ) ;
@@ -611,8 +613,8 @@ describe('Cookie Authentication', function() {
611613 var username = ME ; // Set this to your own account
612614 var other_cloudant = Cloudant ( { account : username , cookie : cookies [ username ] , plugins : [ ] } ) ;
613615
614- var alice = other_cloudant . db . use ( ' alice' ) ;
615- alice . insert ( { 'I use cookies' : true } , function ( er , body , headers ) {
616+ var aliceDb = other_cloudant . db . use ( alice ) ;
617+ aliceDb . insert ( { 'I use cookies' : true } , function ( er , body , headers ) {
616618 if ( er ) {
617619 return console . log ( 'Failed to insert into alice database: ' + er . message ) ;
618620 }
0 commit comments