@@ -15,37 +15,28 @@ describe('MONGODB-AWS', function () {
15
15
}
16
16
} ) ;
17
17
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
25
21
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 ) ;
29
26
30
- done ( ) ;
31
- } ) ;
32
- } ) ;
27
+ expect ( error ) . to . be . instanceOf ( MongoAWSError ) ;
33
28
} ) ;
34
29
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
41
32
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 ) ;
45
37
46
- done ( ) ;
47
- } ) ;
48
- } ) ;
38
+ expect ( result ) . to . not . be . instanceOf ( MongoAWSError ) ;
39
+ expect ( result ) . to . have . property ( 'ok' , 1 ) ;
49
40
} ) ;
50
41
51
42
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 () {
84
75
client = config . newClient ( process . env . MONGODB_URI , { authMechanism : 'MONGODB-AWS' } ) ; // use the URI built by the test environment
85
76
const startTime = performance . now ( ) ;
86
77
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 ) ;
91
82
92
83
const endTime = performance . now ( ) ;
93
84
const timeTaken = endTime - startTime ;
0 commit comments