@@ -25,17 +25,16 @@ import { FirebaseAnalyticsInternalName } from '@firebase/analytics-interop-types
25
25
26
26
describe ( 'Experiment' , ( ) => {
27
27
const storage = { } as Storage ;
28
- const analytics = { } as Provider < FirebaseAnalyticsInternalName > ;
29
- const experiment = new Experiment ( storage , analytics ) ;
30
-
31
- describe ( 'Experiment' , ( ) => {
32
- const storage = { } as Storage ;
33
- const experiment = new Experiment ( storage ) ;
28
+ const analyticsProvider = { } as Provider < FirebaseAnalyticsInternalName > ;
29
+ const experiment = new Experiment ( storage , analyticsProvider ) ;
34
30
35
31
describe ( 'updateActiveExperiments' , ( ) => {
36
32
beforeEach ( ( ) => {
37
33
storage . getActiveExperiments = sinon . stub ( ) ;
38
34
storage . setActiveExperiments = sinon . stub ( ) ;
35
+ analyticsProvider . get = sinon . stub ( ) . returns ( Promise . resolve ( {
36
+ setUserProperties : sinon . stub ( )
37
+ } ) ) ;
39
38
} ) ;
40
39
41
40
it ( 'adds mew experiments to storage' , async ( ) => {
@@ -66,12 +65,14 @@ describe('Experiment', () => {
66
65
storage . getActiveExperiments = sinon
67
66
. stub ( )
68
67
. returns ( new Set ( [ '_exp_1' , '_exp_2' ] ) ) ;
68
+ const analytics = await analyticsProvider . get ( ) ;
69
69
70
70
await experiment . updateActiveExperiments ( latestExperiments ) ;
71
71
72
72
expect ( storage . setActiveExperiments ) . to . have . been . calledWith (
73
73
expectedStoredExperiments
74
74
) ;
75
+ expect ( analytics . setUserProperties ) . to . have . been . calledWith ( { properties : { '_exp_1' : '1' } } ) ;
75
76
} ) ;
76
77
77
78
it ( 'removes missing experiment in fetch response from storage' , async ( ) => {
@@ -88,12 +89,14 @@ describe('Experiment', () => {
88
89
storage . getActiveExperiments = sinon
89
90
. stub ( )
90
91
. returns ( new Set ( [ '_exp_1' , '_exp_2' ] ) ) ;
92
+ const analytics = await analyticsProvider . get ( ) ;
91
93
92
94
await experiment . updateActiveExperiments ( latestExperiments ) ;
93
95
94
96
expect ( storage . setActiveExperiments ) . to . have . been . calledWith (
95
97
expectedStoredExperiments
96
98
) ;
99
+ expect ( analytics . setUserProperties ) . to . have . been . calledWith ( { properties : { '_exp_1' : null } } ) ;
97
100
} ) ;
98
101
} ) ;
99
102
} ) ;
0 commit comments