Skip to content

Commit fc3784c

Browse files
committed
feat: usebooleanconfig-takes-precedence-over-returnvaluefordisabledflags
Signed-off-by: wadii <[email protected]>
1 parent fd92a28 commit fc3784c

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

libs/providers/flagsmith/src/lib/flagsmith-provider.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,16 @@ describe('FlagsmithOpenFeatureProvider', () => {
331331
expect(result.reason).toBe(StandardResolutionReasons.DISABLED);
332332
});
333333

334-
it('should throw flag is not enabled with disabled boolean flag and returnValueForDisabledFlags (default)is false', async () => {
334+
it('should return flag.enabled with disabled boolean flag and returnValueForDisabledFlags (default) is false', async () => {
335335
mockFlags.getFlag.mockReturnValue(mockFlagData.booleanDisabled);
336-
await expect(
337-
defaultProvider.resolveBooleanEvaluation('test-flag', false, evaluationContext, loggerMock),
338-
).rejects.toThrow(FlagsmithProviderError);
336+
const result = await defaultProvider.resolveBooleanEvaluation(
337+
'test-flag',
338+
false,
339+
evaluationContext,
340+
loggerMock,
341+
);
342+
expect(result.value).toBe(false);
343+
expect(result.reason).toBe(StandardResolutionReasons.DISABLED);
339344
});
340345

341346
it('should return default value with error details when flag value type does not match requested type', async () => {

libs/providers/flagsmith/src/lib/flagsmith-provider.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,21 @@ export default class FlagsmithOpenFeatureProvider implements Provider {
114114
throw new FlagsmithProviderError('An error occurred retrieving flags from Flagsmith client.', ErrorCode.GENERAL);
115115
}
116116

117-
// Do we want to raise an error if the flag is not found?
118117
if (!this.useFlagsmithDefaults && (!flag || flag?.isDefault)) {
119118
throw new FlagNotFoundError(`Flag '${flagKey}' was not found.`);
120119
}
121120

122-
if (!(this.returnValueForDisabledFlags || flag.enabled)) {
123-
throw new FlagsmithProviderError(`Flag '${flagKey}' is not enabled.`, ErrorCode.GENERAL);
124-
}
125-
126121
if (!this.useBooleanConfigValue && flagType === 'boolean') {
127122
return {
128123
value: flag.enabled,
129124
reason: flag.enabled ? StandardResolutionReasons.TARGETING_MATCH : StandardResolutionReasons.DISABLED,
130125
};
131126
}
132127

128+
if (!(this.returnValueForDisabledFlags || flag.enabled)) {
129+
throw new FlagsmithProviderError(`Flag '${flagKey}' is not enabled.`, ErrorCode.GENERAL);
130+
}
131+
133132
const typedValue = typeFactory(flag.value, flagType);
134133
if (typedValue === undefined || typeof typedValue !== flagType) {
135134
return {

0 commit comments

Comments
 (0)