Skip to content

Commit ee226c2

Browse files
authored
fix(preferences): allow empty optional string flags COMPASS-7101 (#4725)
1 parent 5544177 commit ee226c2

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

packages/compass-preferences-model/src/global-config.spec.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ forceConnectionOptions:
130130
globalConfigPaths: [],
131131
argv: ['--enable-maps=true', '--theme'],
132132
});
133-
expect(result.cli).to.deep.equal({ enableMaps: true });
133+
expect(result.cli).to.deep.equal({ enableMaps: true, theme: 'LIGHT' });
134134
});
135135

136136
it('knows the expected types of cli options when followed by an extra positional argument', async function () {
@@ -226,4 +226,28 @@ forceConnectionOptions:
226226
'See the MongoDB Compass documentation for more details.'
227227
);
228228
});
229+
230+
it('allows empty theme option and defaults to LIGHT', async function () {
231+
const result = await parseAndValidateGlobalPreferences({
232+
globalConfigPaths: [],
233+
argv: ['--theme='],
234+
});
235+
expect(result.cli).to.deep.equal({ theme: 'LIGHT' });
236+
});
237+
238+
it('allows lowercase theme value', async function () {
239+
const result = await parseAndValidateGlobalPreferences({
240+
globalConfigPaths: [],
241+
argv: ['--theme=dark'],
242+
});
243+
expect(result.cli).to.deep.equal({ theme: 'DARK' });
244+
});
245+
246+
it('allows empty optional string value', async function () {
247+
const result = await parseAndValidateGlobalPreferences({
248+
globalConfigPaths: [],
249+
argv: ['--username', '--password'],
250+
});
251+
expect(result.cli).to.deep.equal({ username: '', password: '' });
252+
});
229253
});

packages/compass-preferences-model/src/preferences.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ const storedUserPreferencesProps: Required<{
285285
},
286286
validator: Joi.string<THEMES>()
287287
.valid(...THEMES_VALUES)
288+
.uppercase() // allow lowercase and convert it to uppercase
289+
.empty('') // allow empty string and its defaulted to LIGHT
288290
.default('LIGHT'),
289291
},
290292
/**
@@ -639,7 +641,7 @@ const nonUserPreferences: Required<{
639641
description: {
640642
short: 'Specify a List of Connections for Automatically Connecting',
641643
},
642-
validator: Joi.string().optional(),
644+
validator: Joi.string().optional().allow(''),
643645
},
644646
username: {
645647
ui: false,
@@ -648,7 +650,7 @@ const nonUserPreferences: Required<{
648650
description: {
649651
short: 'Specify a Username for Automatically Connecting',
650652
},
651-
validator: Joi.string().optional(),
653+
validator: Joi.string().optional().allow(''),
652654
},
653655
password: {
654656
ui: false,
@@ -657,7 +659,7 @@ const nonUserPreferences: Required<{
657659
description: {
658660
short: 'Specify a Password for Automatically Connecting',
659661
},
660-
validator: Joi.string().optional(),
662+
validator: Joi.string().optional().allow(''),
661663
},
662664
};
663665

0 commit comments

Comments
 (0)