Skip to content

Commit

Permalink
fix: allow the full flag to be resolved (#56)
Browse files Browse the repository at this point in the history
* fix: allow the full flag to be resolved
  • Loading branch information
mfranberg authored Feb 1, 2024
1 parent bf00676 commit fa4c7a8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/client-http/src/client/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export namespace Configuration {
let value: any = flag.value;
let schema: FlagSchema = flag.schema;

if (path === '') {
return { value, schema };
}

for (const part of path.split('.')) {
if (typeof schema !== 'object') {
throw new Error(`Parse Error. Cannot find path: ${path}. In flag: ${JSON.stringify(flag)}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,28 @@ describe('ConfidenceServerProvider', () => {
});
});

it('should resolve a full flag object', async () => {
expect(await instanceUnderTest.resolveObjectEvaluation('testFlag', {}, {}, dummyConsole)).toEqual({
variant: 'control',
flagMetadata: {
resolveToken: 'before-each',
},
reason: 'TARGETING_MATCH',
value: {
bool: true,
str: 'control',
int: 3,
dub: 3.5,
obj: {
str: 'obj string',
bool: true,
int: 3,
dub: 3.5,
},
},
});
});

it('should resolve a full object with partial default', async () => {
expect(
await instanceUnderTest.resolveObjectEvaluation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,30 @@ describe('ConfidenceProvider', () => {
});
});

it('should resolve the full flag object', async () => {
await instanceUnderTest.initialize(dummyContext);

expect(instanceUnderTest.resolveObjectEvaluation('testFlag', {}, dummyEvaluationContext, dummyConsole)).toEqual({
variant: 'control',
flagMetadata: {
resolveToken: 'before-each',
},
reason: 'TARGETING_MATCH',
value: {
bool: true,
str: 'control',
int: 3,
dub: 3.5,
obj: {
str: 'obj string',
bool: true,
int: 3,
dub: 3.5,
},
},
});
});

it('should resolve a full object with type mismatch default', async () => {
await instanceUnderTest.initialize(dummyContext);

Expand Down

0 comments on commit fa4c7a8

Please sign in to comment.