diff --git a/packages/compass-generative-ai/src/store/atlas-optin-reducer.spec.ts b/packages/compass-generative-ai/src/store/atlas-optin-reducer.spec.ts index 9198624ad48..9829e033833 100644 --- a/packages/compass-generative-ai/src/store/atlas-optin-reducer.spec.ts +++ b/packages/compass-generative-ai/src/store/atlas-optin-reducer.spec.ts @@ -77,6 +77,39 @@ describe('atlasOptInReducer', function () { ); }); + describe('when already opted in, and the project setting is set to false', function () { + beforeEach(async function () { + await mockPreferences.savePreferences({ + enableGenAIFeaturesAtlasProject: false, + optInDataExplorerGenAIFeatures: true, + }); + }); + + it('should start the opt in flow', async function () { + const mockAtlasAiService = { + optIntoGenAIFeaturesAtlas: sandbox.stub().resolves({ sub: '1234' }), + }; + const store = configureStore({ + atlasAuthService: {} as any, + atlasAiService: mockAtlasAiService as any, + preferences: mockPreferences, + }); + + expect(store.getState().optIn).to.have.nested.property( + 'state', + 'initial' + ); + void store.dispatch(optIntoGenAIWithModalPrompt()).catch(() => {}); + await store.dispatch(optIn()); + expect(mockAtlasAiService.optIntoGenAIFeaturesAtlas).to.have.been + .calledOnce; + expect(store.getState().optIn).to.have.nested.property( + 'state', + 'optin-success' + ); + }); + }); + it('should fail opt in if opt in failed', async function () { const mockAtlasAiService = { optIntoGenAIFeaturesAtlas: sandbox diff --git a/packages/compass-generative-ai/src/store/atlas-optin-reducer.ts b/packages/compass-generative-ai/src/store/atlas-optin-reducer.ts index fbda8cae056..1378c26a093 100644 --- a/packages/compass-generative-ai/src/store/atlas-optin-reducer.ts +++ b/packages/compass-generative-ai/src/store/atlas-optin-reducer.ts @@ -227,8 +227,9 @@ export const optIntoGenAIWithModalPrompt = ({ // Nothing to do if we already opted in. const { state } = getState().optIn; if ( - state === 'optin-success' || - preferences.getPreferences().optInDataExplorerGenAIFeatures + (state === 'optin-success' || + preferences.getPreferences().optInDataExplorerGenAIFeatures) && + preferences.getPreferences().enableGenAIFeaturesAtlasProject ) { return Promise.resolve(); }