@@ -19,27 +19,27 @@ describeWithMongoDB("Connection Manager", (integration) => {
1919 await connectionManager ( ) . disconnect ( ) ;
2020 // for testing, force disconnecting AND setting the connection to closed to reset the
2121 // state of the connection manager
22- connectionManager ( ) . changeState ( "connection-closed " , { tag : "disconnected" } ) ;
22+ connectionManager ( ) . changeState ( "connection-close " , { tag : "disconnected" } ) ;
2323 } ) ;
2424
2525 describe ( "when successfully connected" , ( ) => {
2626 type ConnectionManagerSpies = {
27- "connection-requested " : ( event : ConnectionManagerEvents [ "connection-requested " ] [ 0 ] ) => void ;
28- "connection-succeeded " : ( event : ConnectionManagerEvents [ "connection-succeeded " ] [ 0 ] ) => void ;
29- "connection-timed -out" : ( event : ConnectionManagerEvents [ "connection-timed -out" ] [ 0 ] ) => void ;
30- "connection-closed " : ( event : ConnectionManagerEvents [ "connection-closed " ] [ 0 ] ) => void ;
31- "connection-errored " : ( event : ConnectionManagerEvents [ "connection-errored " ] [ 0 ] ) => void ;
27+ "connection-request " : ( event : ConnectionManagerEvents [ "connection-request " ] [ 0 ] ) => void ;
28+ "connection-success " : ( event : ConnectionManagerEvents [ "connection-success " ] [ 0 ] ) => void ;
29+ "connection-time -out" : ( event : ConnectionManagerEvents [ "connection-time -out" ] [ 0 ] ) => void ;
30+ "connection-close " : ( event : ConnectionManagerEvents [ "connection-close " ] [ 0 ] ) => void ;
31+ "connection-error " : ( event : ConnectionManagerEvents [ "connection-error " ] [ 0 ] ) => void ;
3232 } ;
3333
3434 let connectionManagerSpies : ConnectionManagerSpies ;
3535
3636 beforeEach ( async ( ) => {
3737 connectionManagerSpies = {
38- "connection-requested " : vi . fn ( ) ,
39- "connection-succeeded " : vi . fn ( ) ,
40- "connection-timed -out" : vi . fn ( ) ,
41- "connection-closed " : vi . fn ( ) ,
42- "connection-errored " : vi . fn ( ) ,
38+ "connection-request " : vi . fn ( ) ,
39+ "connection-success " : vi . fn ( ) ,
40+ "connection-time -out" : vi . fn ( ) ,
41+ "connection-close " : vi . fn ( ) ,
42+ "connection-error " : vi . fn ( ) ,
4343 } ;
4444
4545 for ( const [ event , spy ] of Object . entries ( connectionManagerSpies ) ) {
@@ -62,11 +62,11 @@ describeWithMongoDB("Connection Manager", (integration) => {
6262 } ) ;
6363
6464 it ( "should notify that the connection was requested" , ( ) => {
65- expect ( connectionManagerSpies [ "connection-requested " ] ) . toHaveBeenCalledOnce ( ) ;
65+ expect ( connectionManagerSpies [ "connection-request " ] ) . toHaveBeenCalledOnce ( ) ;
6666 } ) ;
6767
6868 it ( "should notify that the connection was successful" , ( ) => {
69- expect ( connectionManagerSpies [ "connection-succeeded " ] ) . toHaveBeenCalledOnce ( ) ;
69+ expect ( connectionManagerSpies [ "connection-success " ] ) . toHaveBeenCalledOnce ( ) ;
7070 } ) ;
7171
7272 describe ( "when disconnects" , ( ) => {
@@ -75,7 +75,7 @@ describeWithMongoDB("Connection Manager", (integration) => {
7575 } ) ;
7676
7777 it ( "should notify that it was disconnected before connecting" , ( ) => {
78- expect ( connectionManagerSpies [ "connection-closed " ] ) . toHaveBeenCalled ( ) ;
78+ expect ( connectionManagerSpies [ "connection-close " ] ) . toHaveBeenCalled ( ) ;
7979 } ) ;
8080
8181 it ( "should be marked explicitly as disconnected" , ( ) => {
@@ -91,11 +91,11 @@ describeWithMongoDB("Connection Manager", (integration) => {
9191 } ) ;
9292
9393 it ( "should notify that it was disconnected before connecting" , ( ) => {
94- expect ( connectionManagerSpies [ "connection-closed " ] ) . toHaveBeenCalled ( ) ;
94+ expect ( connectionManagerSpies [ "connection-close " ] ) . toHaveBeenCalled ( ) ;
9595 } ) ;
9696
9797 it ( "should notify that it was connected again" , ( ) => {
98- expect ( connectionManagerSpies [ "connection-succeeded " ] ) . toHaveBeenCalled ( ) ;
98+ expect ( connectionManagerSpies [ "connection-success " ] ) . toHaveBeenCalled ( ) ;
9999 } ) ;
100100
101101 it ( "should be marked explicitly as connected" , ( ) => {
@@ -115,11 +115,53 @@ describeWithMongoDB("Connection Manager", (integration) => {
115115 } ) ;
116116
117117 it ( "should notify that it was disconnected before connecting" , ( ) => {
118- expect ( connectionManagerSpies [ "connection-closed " ] ) . toHaveBeenCalled ( ) ;
118+ expect ( connectionManagerSpies [ "connection-close " ] ) . toHaveBeenCalled ( ) ;
119119 } ) ;
120120
121121 it ( "should notify that it failed connecting" , ( ) => {
122- expect ( connectionManagerSpies [ "connection-errored" ] ) . toHaveBeenCalled ( ) ;
122+ expect ( connectionManagerSpies [ "connection-error" ] ) . toHaveBeenCalledWith ( {
123+ tag : "errored" ,
124+ connectedAtlasCluster : undefined ,
125+ connectionStringAuthType : "scram" ,
126+ errorReason : "Unable to parse localhost:xxxxx with URL" ,
127+ } ) ;
128+ } ) ;
129+
130+ it ( "should be marked explicitly as connected" , ( ) => {
131+ expect ( connectionManager ( ) . currentConnectionState . tag ) . toEqual ( "errored" ) ;
132+ } ) ;
133+ } ) ;
134+
135+ describe ( "when fails to connect to a new atlas cluster" , ( ) => {
136+ const atlas = {
137+ username : "" ,
138+ projectId : "" ,
139+ clusterName : "My Atlas Cluster" ,
140+ expiryDate : new Date ( ) ,
141+ } ;
142+
143+ beforeEach ( async ( ) => {
144+ try {
145+ await connectionManager ( ) . connect ( {
146+ connectionString : "mongodb://localhost:xxxxx" ,
147+ atlas,
148+ } ) ;
149+ } catch ( _error : unknown ) {
150+ void _error ;
151+ }
152+ } ) ;
153+
154+ it ( "should notify that it was disconnected before connecting" , ( ) => {
155+ expect ( connectionManagerSpies [ "connection-close" ] ) . toHaveBeenCalled ( ) ;
156+ } ) ;
157+
158+ it ( "should notify that it failed connecting" , ( ) => {
159+ expect ( connectionManagerSpies [ "connection-error" ] ) . toHaveBeenCalledWith ( {
160+ tag : "errored" ,
161+ connectedAtlasCluster : atlas ,
162+ connectionStringAuthType : "scram" ,
163+ errorReason : "Unable to parse localhost:xxxxx with URL" ,
164+ } ) ;
123165 } ) ;
124166
125167 it ( "should be marked explicitly as connected" , ( ) => {
0 commit comments