@@ -175,6 +175,90 @@ describe("ToolBase", () => {
175175 expect ( event . properties ) . toHaveProperty ( "test_param2" , "three" ) ;
176176 } ) ;
177177 } ) ;
178+
179+ describe ( "getConnectionInfoMetadata" , ( ) => {
180+ it ( "should return empty metadata when neither connectedAtlasCluster nor connectionStringAuthType are set" , ( ) => {
181+ ( mockSession as { connectedAtlasCluster ?: unknown } ) . connectedAtlasCluster = undefined ;
182+ ( mockSession as { connectionStringAuthType ?: unknown } ) . connectionStringAuthType = undefined ;
183+
184+ const metadata = testTool [ "getConnectionInfoMetadata" ] ( ) ;
185+
186+ expect ( metadata ) . toEqual ( { } ) ;
187+ expect ( metadata ) . not . toHaveProperty ( "project_id" ) ;
188+ expect ( metadata ) . not . toHaveProperty ( "connection_auth_type" ) ;
189+ } ) ;
190+
191+ it ( "should return metadata with project_id when connectedAtlasCluster.projectId is set" , ( ) => {
192+ ( mockSession as { connectedAtlasCluster ?: unknown } ) . connectedAtlasCluster = {
193+ projectId : "test-project-id" ,
194+ username : "test-user" ,
195+ clusterName : "test-cluster" ,
196+ expiryDate : new Date ( ) ,
197+ } ;
198+ ( mockSession as { connectionStringAuthType ?: unknown } ) . connectionStringAuthType = undefined ;
199+
200+ const metadata = testTool [ "getConnectionInfoMetadata" ] ( ) ;
201+
202+ expect ( metadata ) . toEqual ( {
203+ project_id : "test-project-id" ,
204+ } ) ;
205+ expect ( metadata ) . not . toHaveProperty ( "connection_auth_type" ) ;
206+ } ) ;
207+
208+ it ( "should return empty metadata when connectedAtlasCluster exists but projectId is falsy" , ( ) => {
209+ ( mockSession as { connectedAtlasCluster ?: unknown } ) . connectedAtlasCluster = {
210+ projectId : "" ,
211+ username : "test-user" ,
212+ clusterName : "test-cluster" ,
213+ expiryDate : new Date ( ) ,
214+ } ;
215+ ( mockSession as { connectionStringAuthType ?: unknown } ) . connectionStringAuthType = undefined ;
216+
217+ const metadata = testTool [ "getConnectionInfoMetadata" ] ( ) ;
218+
219+ expect ( metadata ) . toEqual ( { } ) ;
220+ expect ( metadata ) . not . toHaveProperty ( "project_id" ) ;
221+ } ) ;
222+
223+ it ( "should return metadata with connection_auth_type when connectionStringAuthType is set" , ( ) => {
224+ ( mockSession as { connectedAtlasCluster ?: unknown } ) . connectedAtlasCluster = undefined ;
225+ ( mockSession as { connectionStringAuthType ?: unknown } ) . connectionStringAuthType = "scram" ;
226+
227+ const metadata = testTool [ "getConnectionInfoMetadata" ] ( ) ;
228+
229+ expect ( metadata ) . toEqual ( {
230+ connection_auth_type : "scram" ,
231+ } ) ;
232+ expect ( metadata ) . not . toHaveProperty ( "project_id" ) ;
233+ } ) ;
234+
235+ it ( "should return metadata with both project_id and connection_auth_type when both are set" , ( ) => {
236+ ( mockSession as { connectedAtlasCluster ?: unknown } ) . connectedAtlasCluster = {
237+ projectId : "test-project-id" ,
238+ username : "test-user" ,
239+ clusterName : "test-cluster" ,
240+ expiryDate : new Date ( ) ,
241+ } ;
242+ ( mockSession as { connectionStringAuthType ?: unknown } ) . connectionStringAuthType = "oidc-auth-flow" ;
243+
244+ const metadata = testTool [ "getConnectionInfoMetadata" ] ( ) ;
245+
246+ expect ( metadata ) . toEqual ( {
247+ project_id : "test-project-id" ,
248+ connection_auth_type : "oidc-auth-flow" ,
249+ } ) ;
250+ } ) ;
251+
252+ it ( "should handle different connectionStringAuthType values" , ( ) => {
253+ const authTypes = [ "scram" , "ldap" , "kerberos" , "oidc-auth-flow" , "oidc-device-flow" , "x.509" ] as const ;
254+
255+ for ( const authType of authTypes ) {
256+ ( mockSession as { connectionStringAuthType ?: unknown } ) . connectionStringAuthType = authType ;
257+ const metadata = testTool [ "getConnectionInfoMetadata" ] ( ) ;
258+ expect ( metadata . connection_auth_type ) . toBe ( authType ) ;
259+ }
260+ } ) ;
261+ } ) ;
178262} ) ;
179263
180264class TestTool extends ToolBase {
0 commit comments