Skip to content

Commit fe34ee3

Browse files
authored
fix(compass-preferences): ensure cloud preferences are correctly set in storage COMPASS-10775 (#8176)
1 parent 4370345 commit fe34ee3

4 files changed

Lines changed: 48 additions & 41 deletions

File tree

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

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,7 @@ const setupPreferences = async (
3333
return preferences;
3434
};
3535

36-
const GLOBAL_PREFERENCES_SOURCES = [
37-
'cli',
38-
'global',
39-
'hardcoded',
40-
'atlasCloudUser',
41-
'atlasCloudProject',
42-
'atlasCloudOrg',
43-
] as const;
36+
const GLOBAL_PREFERENCES_SOURCES = ['cli', 'global', 'hardcoded'] as const;
4437

4538
describe('Preferences class', function () {
4639
let tmpdir: string;
@@ -324,4 +317,43 @@ describe('Preferences class', function () {
324317
);
325318
});
326319
}
320+
321+
it('sets preferences source correctly', async function () {
322+
const preferences = await setupPreferences(tmpdir, {
323+
cli: {
324+
enableMaps: true,
325+
},
326+
global: {
327+
trackUsageStatistics: true,
328+
},
329+
hardcoded: {
330+
networkTraffic: false,
331+
enableGenAIFeatures: false,
332+
},
333+
atlasCloudOrg: {
334+
enableGenAIFeaturesAtlasOrg: true,
335+
},
336+
atlasCloudProject: {
337+
enableRollingIndexes: true,
338+
},
339+
atlasCloudUser: {
340+
readOnly: true,
341+
},
342+
});
343+
const states = preferences.getPreferenceStates();
344+
345+
expect(states).to.have.a.property('enableMaps', 'set-cli');
346+
expect(states).to.have.a.property('trackUsageStatistics', 'set-global');
347+
expect(states).to.have.a.property('networkTraffic', 'hardcoded');
348+
expect(states).to.have.a.property('enableGenAIFeatures', 'hardcoded');
349+
expect(states).to.have.a.property(
350+
'enableGenAIFeaturesAtlasOrg',
351+
'set-cloud-org'
352+
);
353+
expect(states).to.have.a.property(
354+
'enableRollingIndexes',
355+
'set-cloud-project'
356+
);
357+
expect(states).to.have.a.property('readOnly', 'set-cloud-user');
358+
});
327359
});

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ export class Preferences {
195195
...this._getUserPreferenceValues(),
196196
...this._globalPreferences.cli,
197197
...this._globalPreferences.global,
198-
...this._globalPreferences.atlasCloudUser,
199-
...this._globalPreferences.atlasCloudProject,
200-
...this._globalPreferences.atlasCloudOrg,
201198
...this._globalPreferences.hardcoded,
202199
};
203200
}

packages/compass-web/src/preferences.spec.tsx

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@ describe('compass-web preferences', function () {
170170
} = await getPreferencesFromCloudApi(PROJECT_ID);
171171

172172
const preferences = new CompassWebPreferencesAccess(
173-
{ ...DEFAULT_COMPASS_WEB_PREFERENCES, ...atlasCloudUserPreferences },
173+
{
174+
...DEFAULT_COMPASS_WEB_PREFERENCES,
175+
...atlasCloudUserPreferences,
176+
...atlasCloudProjectPreferences,
177+
...atlasCloudOrgPreferences,
178+
},
174179
{
175180
atlasCloudUser: atlasCloudUserPreferences,
176181
atlasCloudProject: atlasCloudProjectPreferences,
@@ -204,35 +209,6 @@ describe('compass-web preferences', function () {
204209
expect(atlasCloudOrgPreferences).to.not.have.property('nonExistentFlag');
205210
});
206211

207-
it('if default value differs from cloud value, it should be overridden by cloud value', async function () {
208-
fetchStub.resolves(
209-
fakeResponse({
210-
...apiResponse,
211-
featureFlags: {
212-
...apiResponse.featureFlags,
213-
enableGenAIFeaturesAtlasProject: true,
214-
},
215-
})
216-
);
217-
const {
218-
atlasCloudProjectPreferences,
219-
atlasCloudUserPreferences,
220-
atlasCloudOrgPreferences,
221-
} = await getPreferencesFromCloudApi(PROJECT_ID);
222-
223-
const preferences = new CompassWebPreferencesAccess(
224-
{
225-
enableGenAIFeaturesAtlasProject: false, // Default
226-
},
227-
{
228-
atlasCloudProject: atlasCloudProjectPreferences,
229-
atlasCloudUser: atlasCloudUserPreferences,
230-
atlasCloudOrg: atlasCloudOrgPreferences,
231-
}
232-
).getPreferences();
233-
expect(preferences.enableGenAIFeaturesAtlasProject).to.equal(true);
234-
});
235-
236212
it('throws when the request is not ok', async function () {
237213
fetchStub.resolves(fakeResponse({}, false));
238214

packages/compass-web/src/preferences.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ async function _fetchAndCachePreferences(
186186
{
187187
...DEFAULT_COMPASS_WEB_PREFERENCES,
188188
...atlasCloudUserPreferences,
189+
...atlasCloudProjectPreferences,
190+
...atlasCloudOrgPreferences,
189191
},
190192
{
191193
atlasCloudUser: atlasCloudUserPreferences,

0 commit comments

Comments
 (0)