@@ -15,37 +15,28 @@ describe('MONGODB-AWS', function () {
1515 }
1616 } ) ;
1717
18- it ( 'should not authorize when not authenticated' , function ( done ) {
19- const config = this . configuration ;
20- const url = removeAuthFromConnectionString ( config . url ( ) ) ;
21- const client = config . newClient ( url ) ; // strip provided URI of credentials
22- client . connect ( err => {
23- expect ( err ) . to . not . exist ;
24- this . defer ( ( ) => client . close ( ) ) ;
18+ it ( 'should not authorize when not authenticated' , async function ( ) {
19+ const url = removeAuthFromConnectionString ( this . configuration . url ( ) ) ;
20+ const client = this . configuration . newClient ( url ) ; // strip provided URI of credentials
2521
26- client . db ( 'aws' ) . command ( { count : 'test' } , ( err , count ) => {
27- expect ( err ) . to . exist ;
28- expect ( count ) . to . not . exist ;
22+ const error = await client
23+ . db ( 'aws' )
24+ . command ( { ping : 1 } )
25+ . catch ( error => error ) ;
2926
30- done ( ) ;
31- } ) ;
32- } ) ;
27+ expect ( error ) . to . be . instanceOf ( MongoAWSError ) ;
3328 } ) ;
3429
35- it ( 'should authorize when successfully authenticated' , function ( done ) {
36- const config = this . configuration ;
37- const client = config . newClient ( process . env . MONGODB_URI ) ; // use the URI built by the test environment
38- client . connect ( err => {
39- expect ( err ) . to . not . exist ;
40- this . defer ( ( ) => client . close ( ) ) ;
30+ it ( 'should authorize when successfully authenticated' , async function ( ) {
31+ const client = this . configuration . newClient ( process . env . MONGODB_URI ) ; // use the URI built by the test environment
4132
42- client . db ( 'aws' ) . command ( { count : 'test' } , ( err , count ) => {
43- expect ( err ) . to . not . exist ;
44- expect ( count ) . to . exist ;
33+ const result = await client
34+ . db ( 'aws' )
35+ . command ( { ping : 1 } )
36+ . catch ( error => error ) ;
4537
46- done ( ) ;
47- } ) ;
48- } ) ;
38+ expect ( result ) . to . not . be . instanceOf ( MongoAWSError ) ;
39+ expect ( result ) . to . have . property ( 'ok' , 1 ) ;
4940 } ) ;
5041
5142 it ( 'should allow empty string in authMechanismProperties.AWS_SESSION_TOKEN to override AWS_SESSION_TOKEN environment variable' , function ( ) {
@@ -84,10 +75,10 @@ describe('MONGODB-AWS', function () {
8475 client = config . newClient ( process . env . MONGODB_URI , { authMechanism : 'MONGODB-AWS' } ) ; // use the URI built by the test environment
8576 const startTime = performance . now ( ) ;
8677
87- let caughtError = null ;
88- await client . connect ( ) . catch ( err => {
89- caughtError = err ;
90- } ) ;
78+ const caughtError = await client
79+ . db ( )
80+ . command ( { ping : 1 } )
81+ . catch ( error => error ) ;
9182
9283 const endTime = performance . now ( ) ;
9384 const timeTaken = endTime - startTime ;
0 commit comments