-
Notifications
You must be signed in to change notification settings - Fork 1
convert to dynamic config; return boolean, numeric and string responses (FF-860) #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c63dde5
add support for dynamic config types (FF-860)
leoromanovsky a50ecce
Merge branch 'main' into lr/dynamic-config
leoromanovsky 7823a08
handle test case 5 and 6; add github test data repo
leoromanovsky 1a54b12
remove deleting .git directory; not sure why make test-data is failin…
leoromanovsky c529589
trying to get the makefile to work
leoromanovsky 11fe907
aaron feedback: private constructor; toString function
leoromanovsky 7484f3c
v1.4.0
leoromanovsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import mock from 'xhr-mock'; | |
|
||
import { | ||
IAssignmentTestCase, | ||
ValueTestType, | ||
readAssignmentTestData, | ||
readMockRacResponse, | ||
} from '../../test/testHelpers'; | ||
|
@@ -15,6 +16,7 @@ import { IAssignmentLogger } from '../assignment-logger'; | |
import { IConfigurationStore } from '../configuration-store'; | ||
import { MAX_EVENT_QUEUE_SIZE } from '../constants'; | ||
import { OperatorType } from '../dto/rule-dto'; | ||
import { EppoValue } from '../eppo_value'; | ||
import ExperimentConfigurationRequestor from '../experiment-configuration-requestor'; | ||
import HttpClient from '../http-client'; | ||
|
||
|
@@ -85,6 +87,7 @@ describe('EppoClient E2E test', () => { | |
enabled: true, | ||
subjectShards: 100, | ||
overrides: {}, | ||
typedOverrides: {}, | ||
rules: [ | ||
{ | ||
allocationKey: 'allocation1', | ||
|
@@ -98,6 +101,7 @@ describe('EppoClient E2E test', () => { | |
{ | ||
name: 'control', | ||
value: 'control', | ||
typedValue: 'control', | ||
shardRange: { | ||
start: 0, | ||
end: 34, | ||
|
@@ -106,6 +110,7 @@ describe('EppoClient E2E test', () => { | |
{ | ||
name: 'variant-1', | ||
value: 'variant-1', | ||
typedValue: 'variant-1', | ||
shardRange: { | ||
start: 34, | ||
end: 67, | ||
|
@@ -114,6 +119,7 @@ describe('EppoClient E2E test', () => { | |
{ | ||
name: 'variant-2', | ||
value: 'variant-2', | ||
typedValue: 'variant-2', | ||
shardRange: { | ||
start: 67, | ||
end: 100, | ||
|
@@ -172,17 +178,34 @@ describe('EppoClient E2E test', () => { | |
'test variation assignment splits', | ||
async ({ | ||
experiment, | ||
valueType = ValueTestType.StringType, | ||
subjects, | ||
subjectsWithAttributes, | ||
expectedAssignments, | ||
}: IAssignmentTestCase) => { | ||
`---- Test Case for ${experiment} Experiment ----`; | ||
const assignments = subjectsWithAttributes | ||
? getAssignmentsWithSubjectAttributes(subjectsWithAttributes, experiment) | ||
: getAssignments(subjects, experiment); | ||
|
||
// temporarily cast to string under dynamic configuration support is added | ||
expect(assignments).toEqual(expectedAssignments.map((e) => (e ? e.toString() : null))); | ||
const assignments = subjectsWithAttributes | ||
? getAssignmentsWithSubjectAttributes(subjectsWithAttributes, experiment, valueType) | ||
: getAssignments(subjects, experiment, valueType); | ||
|
||
switch (valueType) { | ||
case ValueTestType.BoolType: { | ||
const boolAssignments = assignments.map((a) => a?.boolValue ?? null); | ||
expect(boolAssignments).toEqual(expectedAssignments); | ||
break; | ||
} | ||
case ValueTestType.NumericType: { | ||
const numericAssignments = assignments.map((a) => a?.numericValue ?? null); | ||
expect(numericAssignments).toEqual(expectedAssignments); | ||
break; | ||
} | ||
case ValueTestType.StringType: { | ||
const stringAssignments = assignments.map((a) => a?.stringValue ?? null); | ||
expect(stringAssignments).toEqual(expectedAssignments); | ||
break; | ||
} | ||
} | ||
}, | ||
); | ||
}); | ||
|
@@ -198,7 +221,7 @@ describe('EppoClient E2E test', () => { | |
experimentName, | ||
JSON.stringify({ | ||
...mockExperimentConfig, | ||
overrides: { | ||
typedOverrides: { | ||
'1b50f33aef8f681a13f623963da967ed': 'control', | ||
}, | ||
}), | ||
|
@@ -212,7 +235,7 @@ describe('EppoClient E2E test', () => { | |
const entry = { | ||
...mockExperimentConfig, | ||
enabled: false, | ||
overrides: { | ||
typedOverrides: { | ||
'1b50f33aef8f681a13f623963da967ed': 'control', | ||
}, | ||
}; | ||
|
@@ -281,9 +304,29 @@ describe('EppoClient E2E test', () => { | |
expect(assignment).toEqual('control'); | ||
}); | ||
|
||
function getAssignments(subjects: string[], experiment: string): string[] { | ||
function getAssignments( | ||
subjects: string[], | ||
experiment: string, | ||
valueTestType: ValueTestType = ValueTestType.StringType, | ||
): (EppoValue | null)[] { | ||
return subjects.map((subjectKey) => { | ||
return globalClient.getAssignment(subjectKey, experiment); | ||
switch (valueTestType) { | ||
case ValueTestType.BoolType: { | ||
const ba = globalClient.getBoolAssignment(subjectKey, experiment); | ||
if (ba === null) return null; | ||
return EppoValue.Bool(ba); | ||
Comment on lines
+316
to
+317
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor but with short-circuiting and I think we could simplify this to > v = null
null
> v && Bool(v)
null
> v = true
true
> v && Boolean(v)
true |
||
} | ||
case ValueTestType.NumericType: { | ||
const na = globalClient.getNumericAssignment(subjectKey, experiment); | ||
if (na === null) return null; | ||
return EppoValue.Numeric(na); | ||
} | ||
case ValueTestType.StringType: { | ||
const sa = globalClient.getStringAssignment(subjectKey, experiment); | ||
if (sa === null) return null; | ||
return EppoValue.String(sa); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
|
@@ -294,9 +337,38 @@ describe('EppoClient E2E test', () => { | |
subjectAttributes: Record<string, any>; | ||
}[], | ||
experiment: string, | ||
): string[] { | ||
valueTestType: ValueTestType = ValueTestType.StringType, | ||
): (EppoValue | null)[] { | ||
return subjectsWithAttributes.map((subject) => { | ||
return globalClient.getAssignment(subject.subjectKey, experiment, subject.subjectAttributes); | ||
switch (valueTestType) { | ||
case ValueTestType.BoolType: { | ||
const ba = globalClient.getBoolAssignment( | ||
subject.subjectKey, | ||
experiment, | ||
subject.subjectAttributes, | ||
); | ||
if (ba === null) return null; | ||
return EppoValue.Bool(ba); | ||
} | ||
case ValueTestType.NumericType: { | ||
const na = globalClient.getNumericAssignment( | ||
subject.subjectKey, | ||
experiment, | ||
subject.subjectAttributes, | ||
); | ||
if (na === null) return null; | ||
return EppoValue.Numeric(na); | ||
} | ||
case ValueTestType.StringType: { | ||
const sa = globalClient.getStringAssignment( | ||
subject.subjectKey, | ||
experiment, | ||
subject.subjectAttributes, | ||
); | ||
if (sa === null) return null; | ||
return EppoValue.String(sa); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
|
@@ -324,12 +396,16 @@ describe('EppoClient E2E test', () => { | |
{}, | ||
{ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
onPreAssignment(experimentKey: string, subject: string): string { | ||
return 'my-overridden-variation'; | ||
onPreAssignment(experimentKey: string, subject: string): EppoValue | null { | ||
return EppoValue.String('my-overridden-variation'); | ||
}, | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
onPostAssignment(experimentKey: string, subject: string, variation: string): void { | ||
onPostAssignment( | ||
experimentKey: string, | ||
subject: string, | ||
variation: EppoValue | null, | ||
): void { | ||
// no-op | ||
}, | ||
}, | ||
|
@@ -345,12 +421,16 @@ describe('EppoClient E2E test', () => { | |
{}, | ||
{ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
onPreAssignment(experimentKey: string, subject: string): string | null { | ||
onPreAssignment(experimentKey: string, subject: string): EppoValue | null { | ||
return null; | ||
}, | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
onPostAssignment(experimentKey: string, subject: string, variation: string): void { | ||
onPostAssignment( | ||
experimentKey: string, | ||
subject: string, | ||
variation: EppoValue | null, | ||
): void { | ||
// no-op | ||
}, | ||
}, | ||
|
@@ -369,7 +449,9 @@ describe('EppoClient E2E test', () => { | |
expect(td.explain(mockHooks.onPostAssignment).callCount).toEqual(1); | ||
expect(td.explain(mockHooks.onPostAssignment).calls[0].args[0]).toEqual(experimentName); | ||
expect(td.explain(mockHooks.onPostAssignment).calls[0].args[1]).toEqual(subject); | ||
expect(td.explain(mockHooks.onPostAssignment).calls[0].args[2]).toEqual(variation); | ||
expect(td.explain(mockHooks.onPostAssignment).calls[0].args[2]).toEqual( | ||
EppoValue.String(variation ?? ''), | ||
); | ||
}); | ||
}); | ||
}); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥