@@ -133,14 +133,16 @@ describe('GoFeatureFlagProvider', () => {
133
133
) ;
134
134
} ) ;
135
135
} ) ;
136
- it ( 'should throw an error if invalid api key is propvided ' , async ( ) => {
136
+ it ( 'should throw an error if invalid api key is provided ' , async ( ) => {
137
137
const flagName = 'unauthorized' ;
138
138
const targetingKey = 'user-key' ;
139
139
const dns = `${ endpoint } v1/feature/${ flagName } /eval` ;
140
+ const apiKey = 'invalid-api-key' ;
140
141
141
142
axiosMock . onPost ( dns ) . reply ( 401 , { } as GoFeatureFlagProxyResponse < string > ) ;
142
143
143
- await goff
144
+ const authenticatedGoff = new GoFeatureFlagProvider ( { endpoint, apiKey } ) ;
145
+ await authenticatedGoff
144
146
. resolveStringEvaluation ( flagName , 'sdk-default' , { targetingKey } )
145
147
. catch ( ( err ) => {
146
148
expect ( err ) . toBeInstanceOf ( Unauthorized ) ;
@@ -149,6 +151,33 @@ describe('GoFeatureFlagProvider', () => {
149
151
) ;
150
152
} ) ;
151
153
} ) ;
154
+
155
+ it ( 'should be valid with an API key provided' , async ( ) => {
156
+ const flagName = 'random-flag' ;
157
+ const targetingKey = 'user-key' ;
158
+ const dns = `${ endpoint } v1/feature/${ flagName } /eval` ;
159
+ const apiKey = 'valid-api-key' ;
160
+
161
+ axiosMock . onPost ( dns ) . reply ( 200 , {
162
+ value : true ,
163
+ variationType : 'trueVariation' ,
164
+ reason : StandardResolutionReasons . TARGETING_MATCH ,
165
+ failed : false ,
166
+ trackEvents : true ,
167
+ version : '1.0.0' ,
168
+ } as GoFeatureFlagProxyResponse < boolean > ) ;
169
+
170
+ const authenticatedGoff = new GoFeatureFlagProvider ( { endpoint, apiKey } ) ;
171
+ await authenticatedGoff
172
+ . resolveBooleanEvaluation ( flagName , false , { targetingKey } )
173
+ . then ( ( res ) => {
174
+ expect ( res ) . toEqual ( {
175
+ reason : StandardResolutionReasons . TARGETING_MATCH ,
176
+ value : true ,
177
+ variant : 'trueVariation' ,
178
+ } as ResolutionDetails < boolean > ) ;
179
+ } ) ;
180
+ } ) ;
152
181
} ) ;
153
182
154
183
describe ( 'resolveBooleanEvaluation' , ( ) => {
0 commit comments