From e03d5d4c3e874256d02c3c8a8741e24e61bafbe2 Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Thu, 11 Jul 2024 17:30:34 +0200 Subject: [PATCH] first tests --- .../src/connections-manager.spec.ts | 50 ++++++ .../compass/src/app/utils/telemetry.spec.ts | 153 ++++++++++++++++-- 2 files changed, 186 insertions(+), 17 deletions(-) diff --git a/packages/compass-connections/src/connections-manager.spec.ts b/packages/compass-connections/src/connections-manager.spec.ts index ff030e57027..d77c0a453ba 100644 --- a/packages/compass-connections/src/connections-manager.spec.ts +++ b/packages/compass-connections/src/connections-manager.spec.ts @@ -479,6 +479,25 @@ describe('ConnectionsManager', function () { ).to.equal(ConnectionStatus.Connected); }); + it('#getConnectionIdsByStatus(ConnectionStatus.Connected) should return the connected connections', async function () { + await Promise.all([ + connectionsManager.connect( + connectedConnectionInfo1, + getConnectionConfigurationOptions() + ), + connectionsManager.connect( + connectedConnectionInfo2, + getConnectionConfigurationOptions() + ), + ]); + const connections = connectionsManager.getConnectionIdsByStatus( + ConnectionStatus.Connected + ); + expect(connections).to.have.length(2); + expect(connections).to.contain(connectedConnectionInfo1.id); + expect(connections).to.contain(connectedConnectionInfo2.id); + }); + it('#getDataServiceForConnection should be able to return connected dataService', async function () { await Promise.all([ connectionsManager.connect( @@ -564,6 +583,20 @@ describe('ConnectionsManager', function () { ); }); + it('#getConnectionIdsByStatus(ConnectionStatus.Failed) should return the failed connection', async function () { + try { + await connectionsManager.connect( + failedConnectionInfo, + getConnectionConfigurationOptions() + ); + } catch (error) { + // nothing + } + expect( + connectionsManager.getConnectionIdsByStatus(ConnectionStatus.Failed) + ).to.deep.equal([failedConnectionInfo.id]); + }); + it('#getDataServiceForConnection should not return anything for failed connection', async function () { try { await connectionsManager.connect( @@ -632,6 +665,23 @@ describe('ConnectionsManager', function () { ); }); + it('#getConnectionIdsByStatus(ConnectionStatus.Disconnected) should return the connection after disconnecting', async function () { + await connectionsManager.connect( + activeConnectionInfo, + getConnectionConfigurationOptions() + ); + expect( + connectionsManager.getConnectionIdsByStatus(ConnectionStatus.Connected) + ).to.deep.equal([activeConnectionInfo.id]); + + await connectionsManager.closeConnection(activeConnectionInfo.id); + expect( + connectionsManager.getConnectionIdsByStatus( + ConnectionStatus.Disconnected + ) + ).to.deep.equal([activeConnectionInfo.id]); + }); + it('#getDataServiceForConnection should not return anything for disconnected connection', async function () { await connectionsManager.connect( activeConnectionInfo, diff --git a/packages/compass/src/app/utils/telemetry.spec.ts b/packages/compass/src/app/utils/telemetry.spec.ts index 0bf9b63aa68..1cab91bf686 100644 --- a/packages/compass/src/app/utils/telemetry.spec.ts +++ b/packages/compass/src/app/utils/telemetry.spec.ts @@ -42,7 +42,12 @@ const connectionInfo: ConnectionInfo = { }, }; -describe('connection tracking', function () { +const activeInactiveConnectionsCount = { + active: 3, + inactive: 7, +}; + +describe.only('connection tracking', function () { let trackUsageStatistics: boolean; const logger = createLogger('TEST-CONNECTION'); const track = createIpcTrack(); @@ -142,7 +147,13 @@ describe('connection tracking', function () { }, }; - trackNewConnectionEvent(connection, dataService, logger, track); + trackNewConnectionEvent( + connection, + dataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; const expected = { is_localhost: true, @@ -170,6 +181,8 @@ describe('connection tracking', function () { has_kms_kmip: false, has_kms_azure: false, connection_id: 'TEST', + active_connections_count: activeInactiveConnectionsCount.active, + inactive_connections_count: activeInactiveConnectionsCount.inactive, }; expect(properties).to.deep.equal(expected); @@ -184,7 +197,13 @@ describe('connection tracking', function () { }, }; - trackNewConnectionEvent(connection, dataService, logger, track); + trackNewConnectionEvent( + connection, + dataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; const expected = { @@ -213,6 +232,8 @@ describe('connection tracking', function () { has_kms_kmip: false, has_kms_azure: false, connection_id: 'TEST', + active_connections_count: activeInactiveConnectionsCount.active, + inactive_connections_count: activeInactiveConnectionsCount.inactive, }; expect(properties).to.deep.equal(expected); @@ -240,7 +261,13 @@ describe('connection tracking', function () { }, }; - trackNewConnectionEvent(connection, dataService, logger, track); + trackNewConnectionEvent( + connection, + dataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; const expected = { @@ -270,6 +297,8 @@ describe('connection tracking', function () { is_public_cloud: true, public_cloud_name: 'AWS', connection_id: 'TEST', + active_connections_count: activeInactiveConnectionsCount.active, + inactive_connections_count: activeInactiveConnectionsCount.inactive, }; expect(properties).to.deep.equal(expected); @@ -313,7 +342,13 @@ describe('connection tracking', function () { }, }; - trackNewConnectionEvent(connection, mockDataService, logger, track); + trackNewConnectionEvent( + connection, + mockDataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; const expected = { @@ -342,6 +377,8 @@ describe('connection tracking', function () { has_kms_kmip: false, has_kms_azure: false, connection_id: 'TEST', + active_connections_count: activeInactiveConnectionsCount.active, + inactive_connections_count: activeInactiveConnectionsCount.inactive, }; expect(properties).to.deep.equal(expected); @@ -356,7 +393,13 @@ describe('connection tracking', function () { }, }; - trackNewConnectionEvent(connection, dataService, logger, track); + trackNewConnectionEvent( + connection, + dataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; const expected = { @@ -386,6 +429,8 @@ describe('connection tracking', function () { has_kms_kmip: false, has_kms_azure: false, connection_id: 'TEST', + active_connections_count: activeInactiveConnectionsCount.active, + inactive_connections_count: activeInactiveConnectionsCount.inactive, }; expect(properties).to.deep.equal(expected); @@ -400,7 +445,13 @@ describe('connection tracking', function () { }, }; - trackNewConnectionEvent(connection, dataService, logger, track); + trackNewConnectionEvent( + connection, + dataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; const expected = { @@ -429,6 +480,8 @@ describe('connection tracking', function () { has_kms_kmip: false, has_kms_azure: false, connection_id: 'TEST', + active_connections_count: activeInactiveConnectionsCount.active, + inactive_connections_count: activeInactiveConnectionsCount.inactive, }; expect(properties).to.deep.equal(expected); @@ -443,7 +496,13 @@ describe('connection tracking', function () { }, }; - trackNewConnectionEvent(connection, dataService, logger, track); + trackNewConnectionEvent( + connection, + dataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; const expected = { @@ -471,6 +530,8 @@ describe('connection tracking', function () { has_kms_kmip: false, has_kms_azure: false, connection_id: 'TEST', + active_connections_count: activeInactiveConnectionsCount.active, + inactive_connections_count: activeInactiveConnectionsCount.inactive, }; expect(properties).to.deep.equal(expected); @@ -485,7 +546,13 @@ describe('connection tracking', function () { }, }; - trackNewConnectionEvent(connection, dataService, logger, track); + trackNewConnectionEvent( + connection, + dataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; const expected = { @@ -513,6 +580,8 @@ describe('connection tracking', function () { has_kms_kmip: false, has_kms_azure: false, connection_id: 'TEST', + active_connections_count: activeInactiveConnectionsCount.active, + inactive_connections_count: activeInactiveConnectionsCount.inactive, }; expect(properties).to.deep.equal(expected); @@ -531,7 +600,13 @@ describe('connection tracking', function () { connectionString: `mongodb://root:pwd@127.0.0.1?authMechanism=${authMechanism}`, }, }; - trackNewConnectionEvent(connection, dataService, logger, track); + trackNewConnectionEvent( + connection, + dataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; expect(properties.auth_type).to.equal(authMechanism || 'DEFAULT'); }); @@ -546,7 +621,13 @@ describe('connection tracking', function () { connectionString: 'mongodb://127.0.0.1?authMechanism=', }, }; - trackNewConnectionEvent(connection, dataService, logger, track); + trackNewConnectionEvent( + connection, + dataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; expect(properties.auth_type).to.equal('NONE'); }); @@ -559,7 +640,13 @@ describe('connection tracking', function () { connectionString: 'mongodb://127.0.0.1?authMechanism=', }, }; - trackNewConnectionEvent(connection, dataService, logger, track); + trackNewConnectionEvent( + connection, + dataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; expect(properties.tunnel).to.equal('none'); }); @@ -577,7 +664,13 @@ describe('connection tracking', function () { }, }, }; - trackNewConnectionEvent(connection, dataService, logger, track); + trackNewConnectionEvent( + connection, + dataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; expect(properties.tunnel).to.equal('ssh'); }); @@ -590,7 +683,13 @@ describe('connection tracking', function () { connectionString: 'mongodb+srv://127.0.0.1', }, }; - trackNewConnectionEvent(connection, dataService, logger, track); + trackNewConnectionEvent( + connection, + dataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; expect(properties.is_srv).to.equal(true); }); @@ -632,7 +731,13 @@ describe('connection tracking', function () { connectionString: 'mongodb://127.0.0.1', }, }; - trackNewConnectionEvent(connection, mockDataService, logger, track); + trackNewConnectionEvent( + connection, + mockDataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; expect(properties.is_atlas).to.equal(true); @@ -683,7 +788,13 @@ describe('connection tracking', function () { connectionString: 'mongodb://127.0.0.1', }, }; - trackNewConnectionEvent(connection, mockDataService, logger, track); + trackNewConnectionEvent( + connection, + mockDataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; expect(properties.is_atlas).to.equal(false); @@ -756,7 +867,13 @@ describe('connection tracking', function () { }, }; - trackNewConnectionEvent(connection, dataService, logger, track); + trackNewConnectionEvent( + connection, + dataService, + logger, + track, + activeInactiveConnectionsCount + ); const [{ properties }] = await trackEvent; const expected = { @@ -785,6 +902,8 @@ describe('connection tracking', function () { has_kms_kmip: false, has_kms_azure: false, connection_id: 'TEST', + active_connections_count: activeInactiveConnectionsCount.active, + inactive_connections_count: activeInactiveConnectionsCount.inactive, }; expect(properties).to.deep.equal(expected);