Skip to content

Commit

Permalink
fix(flipt): return the correct default value when provided in Flipt (#…
Browse files Browse the repository at this point in the history
…1052)

Signed-off-by: Roman Dmytrenko <[email protected]>
  • Loading branch information
erka authored Sep 4, 2024
1 parent 0b6179b commit 28bffa5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions libs/providers/flipt/src/lib/flipt-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,27 @@ describe('FliptProvider', () => {
expect(value).toHaveProperty('value', { hello: 'world' });
});

it('should return right value for default value', async () => {
fetchMock.post(
variantEndpoint,
{
match: false,
segmentKeys: [],
reason: 'DEFAULT_EVALUATION_REASON',
variantKey: '10',
variantAttachment: `{"hello": "world"}`,
requestId: '0f39483c-d52b-42b4-adbb-40b98bc7058d',
requestDurationMillis: 0.409,
timestamp: '2024-01-15T18:51:50.629551Z',
flagKey: 'flag_json',
},
{ overwriteRoutes: true },
);

const value = await provider.resolveObjectEvaluation('flag_json', {}, { fizz: 'buzz' });
expect(value).toHaveProperty('value', { hello: 'world' });
});

it('should throw TypeMismatchError on non-number value', async () => {
fetchMock.post(
variantEndpoint,
Expand Down
2 changes: 1 addition & 1 deletion libs/providers/flipt/src/lib/flipt-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class FliptProvider implements Provider {
};
}

if (!variantEvaluation.match) {
if (!variantEvaluation.match && variantEvaluation.reason != 'DEFAULT_EVALUATION_REASON') {
return {
value: defaultValue,
reason: StandardResolutionReasons.DEFAULT,
Expand Down

0 comments on commit 28bffa5

Please sign in to comment.