@@ -24,6 +24,8 @@ import packageJSON from '../package.json';
24
24
import optimizelyFactory from '../lib/index.react_native' ;
25
25
import configValidator from '../lib/utils/config_validator' ;
26
26
import eventProcessorConfigValidator from '../lib/utils/event_processor_config_validator' ;
27
+ import { getMockProjectConfigManager } from './mock/project_config_manager' ;
28
+ import { createProjectConfig } from '../lib/core/project_config' ;
27
29
28
30
vi . mock ( '@react-native-community/netinfo' ) ;
29
31
vi . mock ( 'react-native-get-random-values' )
@@ -71,27 +73,21 @@ describe('javascript-sdk/react-native', () => {
71
73
it ( 'should not throw if the provided config is not valid' , ( ) => {
72
74
expect ( function ( ) {
73
75
const optlyInstance = optimizelyFactory . createInstance ( {
74
- datafile : { } ,
76
+ projectConfigManager : getMockProjectConfigManager ( ) ,
75
77
// @ts -ignore
76
78
logger : silentLogger ,
77
79
} ) ;
78
- // Invalid datafile causes onReady Promise rejection - catch this error
79
- // @ts -ignore
80
- optlyInstance . onReady ( ) . catch ( function ( ) { } ) ;
81
80
} ) . not . toThrow ( ) ;
82
81
} ) ;
83
82
84
83
it ( 'should create an instance of optimizely' , ( ) => {
85
84
const optlyInstance = optimizelyFactory . createInstance ( {
86
- datafile : { } ,
85
+ projectConfigManager : getMockProjectConfigManager ( ) ,
87
86
errorHandler : fakeErrorHandler ,
88
87
eventDispatcher : fakeEventDispatcher ,
89
88
// @ts -ignore
90
89
logger : silentLogger ,
91
90
} ) ;
92
- // Invalid datafile causes onReady Promise rejection - catch this error
93
- // @ts -ignore
94
- optlyInstance . onReady ( ) . catch ( function ( ) { } ) ;
95
91
96
92
expect ( optlyInstance ) . toBeInstanceOf ( Optimizely ) ;
97
93
// @ts -ignore
@@ -100,15 +96,13 @@ describe('javascript-sdk/react-native', () => {
100
96
101
97
it ( 'should set the React Native JS client engine and javascript SDK version' , ( ) => {
102
98
const optlyInstance = optimizelyFactory . createInstance ( {
103
- datafile : { } ,
99
+ projectConfigManager : getMockProjectConfigManager ( ) ,
104
100
errorHandler : fakeErrorHandler ,
105
101
eventDispatcher : fakeEventDispatcher ,
106
102
// @ts -ignore
107
103
logger : silentLogger ,
108
104
} ) ;
109
- // Invalid datafile causes onReady Promise rejection - catch this error
110
- // @ts -ignore
111
- optlyInstance . onReady ( ) . catch ( function ( ) { } ) ;
105
+
112
106
// @ts -ignore
113
107
expect ( 'react-native-js-sdk' ) . toEqual ( optlyInstance . clientEngine ) ;
114
108
// @ts -ignore
@@ -118,15 +112,12 @@ describe('javascript-sdk/react-native', () => {
118
112
it ( 'should allow passing of "react-sdk" as the clientEngine and convert it to "react-native-sdk"' , ( ) => {
119
113
const optlyInstance = optimizelyFactory . createInstance ( {
120
114
clientEngine : 'react-sdk' ,
121
- datafile : { } ,
115
+ projectConfigManager : getMockProjectConfigManager ( ) ,
122
116
errorHandler : fakeErrorHandler ,
123
117
eventDispatcher : fakeEventDispatcher ,
124
118
// @ts -ignore
125
119
logger : silentLogger ,
126
120
} ) ;
127
- // Invalid datafile causes onReady Promise rejection - catch this error
128
- // @ts -ignore
129
- optlyInstance . onReady ( ) . catch ( function ( ) { } ) ;
130
121
// @ts -ignore
131
122
expect ( 'react-native-sdk' ) . toEqual ( optlyInstance . clientEngine ) ;
132
123
} ) ;
@@ -142,7 +133,9 @@ describe('javascript-sdk/react-native', () => {
142
133
143
134
it ( 'should call logging.setLogLevel' , ( ) => {
144
135
optimizelyFactory . createInstance ( {
145
- datafile : testData . getTestProjectConfig ( ) ,
136
+ projectConfigManager : getMockProjectConfigManager ( {
137
+ initConfig : createProjectConfig ( testData . getTestProjectConfig ( ) ) ,
138
+ } ) ,
146
139
logLevel : optimizelyFactory . enums . LOG_LEVEL . ERROR ,
147
140
} ) ;
148
141
expect ( logging . setLogLevel ) . toBeCalledTimes ( 1 ) ;
@@ -162,7 +155,9 @@ describe('javascript-sdk/react-native', () => {
162
155
it ( 'should call logging.setLogHandler with the supplied logger' , ( ) => {
163
156
const fakeLogger = { log : function ( ) { } } ;
164
157
optimizelyFactory . createInstance ( {
165
- datafile : testData . getTestProjectConfig ( ) ,
158
+ projectConfigManager : getMockProjectConfigManager ( {
159
+ initConfig : createProjectConfig ( testData . getTestProjectConfig ( ) ) ,
160
+ } ) ,
166
161
// @ts -ignore
167
162
logger : fakeLogger ,
168
163
} ) ;
@@ -184,7 +179,9 @@ describe('javascript-sdk/react-native', () => {
184
179
185
180
it ( 'should use default event flush interval when none is provided' , ( ) => {
186
181
optimizelyFactory . createInstance ( {
187
- datafile : testData . getTestProjectConfigWithFeatures ( ) ,
182
+ projectConfigManager : getMockProjectConfigManager ( {
183
+ initConfig : createProjectConfig ( testData . getTestProjectConfigWithFeatures ( ) ) ,
184
+ } ) ,
188
185
errorHandler : fakeErrorHandler ,
189
186
eventDispatcher : fakeEventDispatcher ,
190
187
// @ts -ignore
@@ -212,7 +209,9 @@ describe('javascript-sdk/react-native', () => {
212
209
213
210
it ( 'should ignore the event flush interval and use the default instead' , ( ) => {
214
211
optimizelyFactory . createInstance ( {
215
- datafile : testData . getTestProjectConfigWithFeatures ( ) ,
212
+ projectConfigManager : getMockProjectConfigManager ( {
213
+ initConfig : createProjectConfig ( testData . getTestProjectConfigWithFeatures ( ) ) ,
214
+ } ) ,
216
215
errorHandler : fakeErrorHandler ,
217
216
eventDispatcher : fakeEventDispatcher ,
218
217
// @ts -ignore
@@ -242,7 +241,9 @@ describe('javascript-sdk/react-native', () => {
242
241
243
242
it ( 'should use the provided event flush interval' , ( ) => {
244
243
optimizelyFactory . createInstance ( {
245
- datafile : testData . getTestProjectConfigWithFeatures ( ) ,
244
+ projectConfigManager : getMockProjectConfigManager ( {
245
+ initConfig : createProjectConfig ( testData . getTestProjectConfigWithFeatures ( ) ) ,
246
+ } ) ,
246
247
errorHandler : fakeErrorHandler ,
247
248
eventDispatcher : fakeEventDispatcher ,
248
249
// @ts -ignore
@@ -262,7 +263,9 @@ describe('javascript-sdk/react-native', () => {
262
263
263
264
it ( 'should use default event batch size when none is provided' , ( ) => {
264
265
optimizelyFactory . createInstance ( {
265
- datafile : testData . getTestProjectConfigWithFeatures ( ) ,
266
+ projectConfigManager : getMockProjectConfigManager ( {
267
+ initConfig : createProjectConfig ( testData . getTestProjectConfigWithFeatures ( ) ) ,
268
+ } ) ,
266
269
errorHandler : fakeErrorHandler ,
267
270
eventDispatcher : fakeEventDispatcher ,
268
271
// @ts -ignore
@@ -319,7 +322,9 @@ describe('javascript-sdk/react-native', () => {
319
322
320
323
it ( 'should use the provided event batch size' , ( ) => {
321
324
optimizelyFactory . createInstance ( {
322
- datafile : testData . getTestProjectConfigWithFeatures ( ) ,
325
+ projectConfigManager : getMockProjectConfigManager ( {
326
+ initConfig : createProjectConfig ( testData . getTestProjectConfigWithFeatures ( ) ) ,
327
+ } ) ,
323
328
errorHandler : fakeErrorHandler ,
324
329
eventDispatcher : fakeEventDispatcher ,
325
330
// @ts -ignore
0 commit comments