@@ -103,6 +103,52 @@ describe('Collect Data API', () => {
103
103
) ;
104
104
} ) ;
105
105
106
+ it ( 'should call the API to collect data with endpoint path' , async ( ) => {
107
+ fetchMock . post ( 'https://gofeatureflag.org/examplepath/v1/data/collector' , 200 ) ;
108
+ const options : GoFeatureFlagWebProviderOptions = {
109
+ endpoint : 'https://gofeatureflag.org/examplepath' ,
110
+ apiTimeout : 1000 ,
111
+ } ;
112
+ const goff = new GoffApiController ( options ) ;
113
+ await goff . collectData (
114
+ [
115
+ {
116
+ key : 'flagKey' ,
117
+ contextKind : 'user' ,
118
+ creationDate : 1733138237486 ,
119
+ default : false ,
120
+ kind : 'feature' ,
121
+ userKey : 'toto' ,
122
+ value : true ,
123
+ variation : 'varA' ,
124
+ } ,
125
+ ] ,
126
+ { provider : 'open-feature-js-sdk' } ,
127
+ ) ;
128
+ expect ( fetchMock . lastUrl ( ) ) . toBe ( 'https://gofeatureflag.org/examplepath/v1/data/collector' ) ;
129
+ expect ( fetchMock . lastOptions ( ) ?. headers ) . toEqual ( {
130
+ 'Content-Type' : 'application/json' ,
131
+ Accept : 'application/json' ,
132
+ } ) ;
133
+ expect ( fetchMock . lastOptions ( ) ?. body ) . toEqual (
134
+ JSON . stringify ( {
135
+ events : [
136
+ {
137
+ key : 'flagKey' ,
138
+ contextKind : 'user' ,
139
+ creationDate : 1733138237486 ,
140
+ default : false ,
141
+ kind : 'feature' ,
142
+ userKey : 'toto' ,
143
+ value : true ,
144
+ variation : 'varA' ,
145
+ } ,
146
+ ] ,
147
+ meta : { provider : 'open-feature-js-sdk' } ,
148
+ } ) ,
149
+ ) ;
150
+ } ) ;
151
+
106
152
it ( 'should not call the API to collect data if no event provided' , async ( ) => {
107
153
fetchMock . post ( 'https://gofeatureflag.org/v1/data/collector' , 200 ) ;
108
154
const options : GoFeatureFlagWebProviderOptions = {
0 commit comments