@@ -6,6 +6,11 @@ import Sinon from 'sinon';
6
6
import AppRegistry from '@mongodb-js/compass-app-registry' ;
7
7
import { expect } from 'chai' ;
8
8
import type { workspacesServiceLocator } from '@mongodb-js/compass-workspaces/provider' ;
9
+ import type { experimentationServiceLocator } from '@mongodb-js/compass-telemetry' ;
10
+ import type { connectionInfoRefLocator } from '@mongodb-js/compass-connections/provider' ;
11
+ import { createNoopLogger } from '@mongodb-js/compass-logging/provider' ;
12
+ import { ReadOnlyPreferenceAccess } from 'compass-preferences-model/provider' ;
13
+ import { ExperimentTestName } from '@mongodb-js/compass-telemetry/provider' ;
9
14
10
15
const defaultMetadata = {
11
16
namespace : 'test.foo' ,
@@ -32,6 +37,32 @@ const mockCollection = {
32
37
} ,
33
38
} ;
34
39
40
+ const mockAtlasConnectionInfo = {
41
+ current : {
42
+ id : 'test-connection' ,
43
+ title : 'Test Connection' ,
44
+ connectionOptions : {
45
+ connectionString : 'mongodb://localhost:27017' ,
46
+ } ,
47
+ atlasMetadata : {
48
+ clusterName : 'test-cluster' ,
49
+ projectId : 'test-project' ,
50
+ orgId : 'test-org' ,
51
+ clusterUniqueId : 'test-cluster-unique-id' ,
52
+ clusterType : 'REPLICASET' as const ,
53
+ clusterState : 'IDLE' as const ,
54
+ metricsId : 'test-metrics-id' ,
55
+ metricsType : 'replicaSet' as const ,
56
+ regionalBaseUrl : null ,
57
+ instanceSize : 'M10' ,
58
+ supports : {
59
+ globalWrites : false ,
60
+ rollingIndexes : true ,
61
+ } ,
62
+ } ,
63
+ } ,
64
+ } ;
65
+
35
66
describe ( 'Collection Tab Content store' , function ( ) {
36
67
const sandbox = Sinon . createSandbox ( ) ;
37
68
@@ -42,7 +73,19 @@ describe('Collection Tab Content store', function () {
42
73
43
74
const configureStore = async (
44
75
options : Partial < CollectionTabOptions > = { } ,
45
- workspaces : Partial < ReturnType < typeof workspacesServiceLocator > > = { }
76
+ workspaces : Partial < ReturnType < typeof workspacesServiceLocator > > = { } ,
77
+ experimentationServices : Partial <
78
+ ReturnType < typeof experimentationServiceLocator >
79
+ > = { } ,
80
+ connectionInfoRef : Partial <
81
+ ReturnType < typeof connectionInfoRefLocator >
82
+ > = { } ,
83
+ logger = createNoopLogger ( 'COMPASS-COLLECTION-TEST' ) ,
84
+ preferences = new ReadOnlyPreferenceAccess ( {
85
+ enableGenAIFeatures : true ,
86
+ enableGenAIFeaturesAtlasOrg : true ,
87
+ cloudFeatureRolloutAccess : { GEN_AI_COMPASS : true } ,
88
+ } )
46
89
) => {
47
90
( { store, deactivate } = activatePlugin (
48
91
{
@@ -54,6 +97,10 @@ describe('Collection Tab Content store', function () {
54
97
localAppRegistry,
55
98
collection : mockCollection as any ,
56
99
workspaces : workspaces as any ,
100
+ experimentationServices : experimentationServices as any ,
101
+ connectionInfoRef : connectionInfoRef as any ,
102
+ logger,
103
+ preferences,
57
104
} ,
58
105
{ on ( ) { } , cleanup ( ) { } } as any
59
106
) ) ;
@@ -76,11 +123,112 @@ describe('Collection Tab Content store', function () {
76
123
const store = await configureStore ( undefined , {
77
124
openCollectionWorkspaceSubtab,
78
125
} ) ;
79
- store . dispatch ( selectTab ( 'Documents' ) ) ;
126
+ store . dispatch ( selectTab ( 'Documents' ) as any ) ;
80
127
expect ( openCollectionWorkspaceSubtab ) . to . have . been . calledWith (
81
128
'workspace-tab-id' ,
82
129
'Documents'
83
130
) ;
84
131
} ) ;
85
132
} ) ;
133
+
134
+ describe ( 'experimentation integration' , function ( ) {
135
+ it ( 'should assign experiment when Atlas metadata is available' , async function ( ) {
136
+ const assignExperiment = sandbox . spy ( ( ) => Promise . resolve ( null ) ) ;
137
+
138
+ await configureStore (
139
+ undefined ,
140
+ { } ,
141
+ { assignExperiment } ,
142
+ mockAtlasConnectionInfo
143
+ ) ;
144
+
145
+ await waitFor ( ( ) => {
146
+ expect ( assignExperiment ) . to . have . been . calledOnceWith (
147
+ ExperimentTestName . mockDataGenerator ,
148
+ {
149
+ team : 'Atlas Growth' ,
150
+ }
151
+ ) ;
152
+ } ) ;
153
+ } ) ;
154
+
155
+ it ( 'should not assign experiment when Atlas metadata is missing' , async function ( ) {
156
+ const assignExperiment = sandbox . spy ( ( ) => Promise . resolve ( null ) ) ;
157
+ const mockConnectionInfoRef = {
158
+ current : {
159
+ id : 'test-connection' ,
160
+ title : 'Test Connection' ,
161
+ connectionOptions : {
162
+ connectionString : 'mongodb://localhost:27017' ,
163
+ } ,
164
+ // No atlasMetadata
165
+ } ,
166
+ } ;
167
+
168
+ await configureStore (
169
+ undefined ,
170
+ { } ,
171
+ { assignExperiment } ,
172
+ mockConnectionInfoRef
173
+ ) ;
174
+
175
+ // Wait a bit to ensure assignment would have happened if it was going to
176
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) ) ;
177
+ expect ( assignExperiment ) . to . not . have . been . called ;
178
+ } ) ;
179
+
180
+ it ( 'should not assign experiment when AI features are disabled at the org level' , async function ( ) {
181
+ const assignExperiment = sandbox . spy ( ( ) => Promise . resolve ( null ) ) ;
182
+
183
+ const mockPreferences = new ReadOnlyPreferenceAccess ( {
184
+ enableGenAIFeatures : true ,
185
+ enableGenAIFeaturesAtlasOrg : false , // Disabled at org level
186
+ cloudFeatureRolloutAccess : { GEN_AI_COMPASS : true } ,
187
+ } ) ;
188
+
189
+ const store = await configureStore (
190
+ undefined ,
191
+ { } ,
192
+ { assignExperiment } ,
193
+ mockAtlasConnectionInfo ,
194
+ undefined ,
195
+ mockPreferences
196
+ ) ;
197
+
198
+ // Wait a bit to ensure assignment would have happened if it was going to
199
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) ) ;
200
+ expect ( assignExperiment ) . to . not . have . been . called ;
201
+
202
+ // Store should still be functional
203
+ await waitFor ( ( ) => {
204
+ expect ( store . getState ( ) )
205
+ . to . have . property ( 'metadata' )
206
+ . deep . eq ( defaultMetadata ) ;
207
+ } ) ;
208
+ } ) ;
209
+
210
+ it ( 'should handle assignment errors gracefully' , async function ( ) {
211
+ const assignExperiment = sandbox . spy ( ( ) =>
212
+ Promise . reject ( new Error ( 'Assignment failed' ) )
213
+ ) ;
214
+
215
+ await configureStore (
216
+ undefined ,
217
+ { } ,
218
+ { assignExperiment } ,
219
+ mockAtlasConnectionInfo
220
+ ) ;
221
+
222
+ await waitFor ( ( ) => {
223
+ expect ( assignExperiment ) . to . have . been . calledOnce ;
224
+ } ) ;
225
+
226
+ // Store should still be functional despite assignment error
227
+ await waitFor ( ( ) => {
228
+ expect ( store . getState ( ) )
229
+ . to . have . property ( 'metadata' )
230
+ . deep . eq ( defaultMetadata ) ;
231
+ } ) ;
232
+ } ) ;
233
+ } ) ;
86
234
} ) ;
0 commit comments