From 6c933dac3102d91943e61d331ef2218ca3d43818 Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Mon, 12 Jul 2021 14:02:41 +0200 Subject: [PATCH] feat(@mongodb-js/compass-connect): Do not override appname if provided by the user --- packages/compass-connect/src/stores/index.js | 11 ++++++-- .../test/renderer/stores/index.spec.js | 28 +++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/packages/compass-connect/src/stores/index.js b/packages/compass-connect/src/stores/index.js index 42075f7edda..3370faadc27 100644 --- a/packages/compass-connect/src/stores/index.js +++ b/packages/compass-connect/src/stores/index.js @@ -991,8 +991,15 @@ const Store = Reflux.createStore({ return; } - // Set the connection's app name to the electron app name of Compass. - connectionModel.appname = electron.remote.app.getName(); + /** + * Set the connection's app name to the electron app name only if it's not + * set by the user already + * + * See https://jira.mongodb.org/browse/COMPASS-4901 + */ + if (typeof connectionModel.appname === 'undefined') { + connectionModel.appname = electron.remote.app.getName(); + } try { const dataService = new DataService(connectionModel); diff --git a/packages/compass-connect/test/renderer/stores/index.spec.js b/packages/compass-connect/test/renderer/stores/index.spec.js index 6facd26a9a1..6013e094744 100644 --- a/packages/compass-connect/test/renderer/stores/index.spec.js +++ b/packages/compass-connect/test/renderer/stores/index.spec.js @@ -1,6 +1,7 @@ import AppRegistry from 'hadron-app-registry'; import Connection, { ConnectionCollection } from 'mongodb-connection-model'; import Reflux from 'reflux'; +import { remote } from 'electron'; import Actions from '../../../src/actions'; import { @@ -1794,14 +1795,15 @@ describe('Store', () => { }); describe('#_connect', () => { - const connection = new Connection({ - hostname: 'localhost', - port: 27018, - authStrategy: 'NONE' - }); + let connection; let appRegistryEmitStub; beforeEach(() => { + connection = new Connection({ + hostname: 'localhost', + port: 27018, + authStrategy: 'NONE' + }); const connections = { [connection._id]: connection.getAttributes({ props: true, derived: true }) }; @@ -1850,6 +1852,22 @@ describe('Store', () => { sinon.restore(); }); + describe('connection.appname', () => { + it('should set connection appname to Electron app name when undefined', async() => { + expect(connection.appname).to.be.undefined; + Store.state.currentConnectionAttempt = createConnectionAttempt(); + await Store._connect(connection); + expect(connection.appname).to.eq(remote.app.getName()); + }); + + it('should preserve appname if set on connection', async() => { + connection.appname = 'My App'; + Store.state.currentConnectionAttempt = createConnectionAttempt(); + await Store._connect(connection); + expect(connection.appname).to.eq('My App'); + }); + }); + it('connects to the database and sets the dataService on the store', async() => { Store.state.currentConnectionAttempt = createConnectionAttempt(); await Store._connect(connection);