Skip to content

Commit 23d653a

Browse files
committed
fix(generative-ai): when opted in and the project setting is disabled show the opt in modal
1 parent 8e96a1e commit 23d653a

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

packages/compass-generative-ai/src/store/atlas-optin-reducer.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,39 @@ describe('atlasOptInReducer', function () {
7777
);
7878
});
7979

80+
describe('when already opted in, and the project setting is set to false', function () {
81+
beforeEach(async function () {
82+
await mockPreferences.savePreferences({
83+
enableGenAIFeaturesAtlasProject: false,
84+
optInDataExplorerGenAIFeatures: true,
85+
});
86+
});
87+
88+
it('should start the opt in flow', async function () {
89+
const mockAtlasAiService = {
90+
optIntoGenAIFeaturesAtlas: sandbox.stub().resolves({ sub: '1234' }),
91+
};
92+
const store = configureStore({
93+
atlasAuthService: {} as any,
94+
atlasAiService: mockAtlasAiService as any,
95+
preferences: mockPreferences,
96+
});
97+
98+
expect(store.getState().optIn).to.have.nested.property(
99+
'state',
100+
'initial'
101+
);
102+
void store.dispatch(optIntoGenAIWithModalPrompt()).catch(() => {});
103+
await store.dispatch(optIn());
104+
expect(mockAtlasAiService.optIntoGenAIFeaturesAtlas).to.have.been
105+
.calledOnce;
106+
expect(store.getState().optIn).to.have.nested.property(
107+
'state',
108+
'optin-success'
109+
);
110+
});
111+
});
112+
80113
it('should fail opt in if opt in failed', async function () {
81114
const mockAtlasAiService = {
82115
optIntoGenAIFeaturesAtlas: sandbox

packages/compass-generative-ai/src/store/atlas-optin-reducer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ export const optIntoGenAIWithModalPrompt = ({
227227
// Nothing to do if we already opted in.
228228
const { state } = getState().optIn;
229229
if (
230-
state === 'optin-success' ||
231-
preferences.getPreferences().optInDataExplorerGenAIFeatures
230+
(state === 'optin-success' ||
231+
preferences.getPreferences().optInDataExplorerGenAIFeatures) &&
232+
preferences.getPreferences().enableGenAIFeaturesAtlasProject
232233
) {
233234
return Promise.resolve();
234235
}

0 commit comments

Comments
 (0)