File tree Expand file tree Collapse file tree 5 files changed +49
-13
lines changed Expand file tree Collapse file tree 5 files changed +49
-13
lines changed Original file line number Diff line number Diff line change @@ -299,6 +299,14 @@ export class OFREPWebProvider implements Provider {
299
299
} ;
300
300
}
301
301
302
+ if ( resolved . value === undefined || resolved . value === null ) {
303
+ return {
304
+ value : defaultValue ,
305
+ flagMetadata : resolved . flagMetadata ,
306
+ reason : resolved . reason || StandardResolutionReasons . DEFAULT ,
307
+ } ;
308
+ }
309
+
302
310
if ( typeof resolved . value !== type ) {
303
311
return {
304
312
value : defaultValue ,
Original file line number Diff line number Diff line change @@ -60,6 +60,14 @@ describe('OFREPProvider should', () => {
60
60
) ;
61
61
} ) ;
62
62
63
+ it . each ( [ true , false ] ) ( 'returns default if value is null' , async ( defaultValue ) => {
64
+ await expect ( provider . resolveBooleanEvaluation ( 'my-null-value-flag' , defaultValue , { } ) ) . resolves . toStrictEqual ( {
65
+ value : defaultValue ,
66
+ reason : 'DEFAULT' ,
67
+ flagMetadata : expect . objectContaining ( TEST_FLAG_METADATA ) ,
68
+ } ) ;
69
+ } ) ;
70
+
63
71
it ( 'throw OFREPApiUnauthorizedError on HTTP 401' , async ( ) => {
64
72
await expect ( provider . resolveBooleanEvaluation ( 'my-flag' , false , { expectedAuthHeader : 'secret' } ) ) . rejects . toThrow (
65
73
OFREPApiUnauthorizedError ,
Original file line number Diff line number Diff line change @@ -94,7 +94,11 @@ export class OFREPProvider implements Provider {
94
94
return handleEvaluationError ( result , defaultValue ) ;
95
95
}
96
96
97
- if ( typeof result . value . value !== typeof defaultValue ) {
97
+ if (
98
+ result . value . value !== undefined &&
99
+ result . value . value !== null &&
100
+ typeof result . value . value !== typeof defaultValue
101
+ ) {
98
102
return {
99
103
value : defaultValue ,
100
104
reason : StandardResolutionReasons . ERROR ,
@@ -104,6 +108,6 @@ export class OFREPProvider implements Provider {
104
108
} ;
105
109
}
106
110
107
- return toResolutionDetails ( result . value ) ;
111
+ return toResolutionDetails ( result . value , defaultValue ) ;
108
112
}
109
113
}
Original file line number Diff line number Diff line change @@ -191,13 +191,22 @@ export function handleEvaluationError<T>(
191
191
192
192
export function toResolutionDetails < T extends EvaluationFlagValue > (
193
193
result : EvaluationSuccessResponse ,
194
+ defaultValue : T ,
194
195
) : ResolutionDetails < T > {
195
- return {
196
- value : result . value as T ,
197
- variant : result . variant ,
198
- reason : result . reason ,
199
- flagMetadata : result . metadata && toFlagMetadata ( result . metadata ) ,
200
- } ;
196
+ if ( result . value === undefined || result . value === null ) {
197
+ return {
198
+ value : defaultValue ,
199
+ reason : result . reason || StandardResolutionReasons . DEFAULT ,
200
+ flagMetadata : result . metadata && toFlagMetadata ( result . metadata ) ,
201
+ } ;
202
+ } else {
203
+ return {
204
+ value : result . value as T ,
205
+ variant : result . variant ,
206
+ reason : result . reason ,
207
+ flagMetadata : result . metadata && toFlagMetadata ( result . metadata ) ,
208
+ } ;
209
+ }
201
210
}
202
211
203
212
export function toFlagMetadata ( metadata : object ) : FlagMetadata {
Original file line number Diff line number Diff line change @@ -121,14 +121,21 @@ export const handlers = [
121
121
}
122
122
123
123
const scopeValue = new URL ( info . request . url ) . searchParams . get ( 'scope' ) ;
124
+ const key = info . params . key ;
125
+ const reason = key . includes ( 'null-value' )
126
+ ? StandardResolutionReasons . DEFAULT
127
+ : requestBody . context ?. targetingKey
128
+ ? StandardResolutionReasons . TARGETING_MATCH
129
+ : StandardResolutionReasons . STATIC ;
130
+
131
+ const value = key . includes ( 'null-value' ) ? null : true ;
132
+ const variant = key . includes ( 'null-value' ) ? undefined : scopeValue ? 'scoped' : 'default' ;
124
133
125
134
return HttpResponse . json < EvaluationResponse > ( {
126
135
key : info . params . key ,
127
- reason : requestBody . context ?. targetingKey
128
- ? StandardResolutionReasons . TARGETING_MATCH
129
- : StandardResolutionReasons . STATIC ,
130
- variant : scopeValue ? 'scoped' : 'default' ,
131
- value : true ,
136
+ reason,
137
+ variant,
138
+ value,
132
139
metadata : TEST_FLAG_METADATA ,
133
140
} ) ;
134
141
} ,
You can’t perform that action at this time.
0 commit comments