diff --git a/packages/compass-preferences-model/src/global-config.spec.ts b/packages/compass-preferences-model/src/global-config.spec.ts index 00511516ecb..63f41ea1200 100644 --- a/packages/compass-preferences-model/src/global-config.spec.ts +++ b/packages/compass-preferences-model/src/global-config.spec.ts @@ -130,7 +130,7 @@ forceConnectionOptions: globalConfigPaths: [], argv: ['--enable-maps=true', '--theme'], }); - expect(result.cli).to.deep.equal({ enableMaps: true }); + expect(result.cli).to.deep.equal({ enableMaps: true, theme: 'LIGHT' }); }); it('knows the expected types of cli options when followed by an extra positional argument', async function () { @@ -226,4 +226,28 @@ forceConnectionOptions: 'See the MongoDB Compass documentation for more details.' ); }); + + it('allows empty theme option and defaults to LIGHT', async function () { + const result = await parseAndValidateGlobalPreferences({ + globalConfigPaths: [], + argv: ['--theme='], + }); + expect(result.cli).to.deep.equal({ theme: 'LIGHT' }); + }); + + it('allows lowercase theme value', async function () { + const result = await parseAndValidateGlobalPreferences({ + globalConfigPaths: [], + argv: ['--theme=dark'], + }); + expect(result.cli).to.deep.equal({ theme: 'DARK' }); + }); + + it('allows empty optional string value', async function () { + const result = await parseAndValidateGlobalPreferences({ + globalConfigPaths: [], + argv: ['--username', '--password'], + }); + expect(result.cli).to.deep.equal({ username: '', password: '' }); + }); }); diff --git a/packages/compass-preferences-model/src/preferences.ts b/packages/compass-preferences-model/src/preferences.ts index 25ca750936c..1b5b5a4fb20 100644 --- a/packages/compass-preferences-model/src/preferences.ts +++ b/packages/compass-preferences-model/src/preferences.ts @@ -285,6 +285,8 @@ const storedUserPreferencesProps: Required<{ }, validator: Joi.string() .valid(...THEMES_VALUES) + .uppercase() // allow lowercase and convert it to uppercase + .empty('') // allow empty string and its defaulted to LIGHT .default('LIGHT'), }, /** @@ -639,7 +641,7 @@ const nonUserPreferences: Required<{ description: { short: 'Specify a List of Connections for Automatically Connecting', }, - validator: Joi.string().optional(), + validator: Joi.string().optional().allow(''), }, username: { ui: false, @@ -648,7 +650,7 @@ const nonUserPreferences: Required<{ description: { short: 'Specify a Username for Automatically Connecting', }, - validator: Joi.string().optional(), + validator: Joi.string().optional().allow(''), }, password: { ui: false, @@ -657,7 +659,7 @@ const nonUserPreferences: Required<{ description: { short: 'Specify a Password for Automatically Connecting', }, - validator: Joi.string().optional(), + validator: Joi.string().optional().allow(''), }, };