-
Notifications
You must be signed in to change notification settings - Fork 0
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
FF-2525 Add Assignment Details to logger #106
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ import FetchHttpClient from '../http-client'; | |
import { Flag, ObfuscatedFlag, VariationType } from '../interfaces'; | ||
import { OperatorType } from '../rules'; | ||
|
||
import EppoClient, { AssignmentDetails } from './eppo-client'; | ||
import EppoClient, { IAssignmentDetails } from './eppo-client'; | ||
|
||
async function init(configurationStore: IConfigurationStore<Flag | ObfuscatedFlag>) { | ||
const apiEndpoints = new ApiEndpoints({ | ||
|
@@ -57,7 +57,7 @@ describe('EppoClient get*AssignmentDetails', () => { | |
subjectAttributes, | ||
0, | ||
); | ||
const expected: AssignmentDetails<number> = { | ||
const expected: IAssignmentDetails<number> = { | ||
value: 3, | ||
variationKey: 'three', | ||
variationValue: 3, | ||
|
@@ -92,7 +92,7 @@ describe('EppoClient get*AssignmentDetails', () => { | |
expect(result).toMatchObject(expected); | ||
}); | ||
|
||
it('should set the details for a matched split', () => { | ||
it.only('should set the details for a matched split', () => { | ||
const client = new EppoClient(storage); | ||
client.setIsGracefulFailureMode(false); | ||
const subjectAttributes = { email: '[email protected]', country: 'Brazil' }; | ||
|
@@ -102,7 +102,7 @@ describe('EppoClient get*AssignmentDetails', () => { | |
subjectAttributes, | ||
0, | ||
); | ||
const expected: AssignmentDetails<number> = { | ||
const expected: IAssignmentDetails<number> = { | ||
value: 2, | ||
variationKey: 'two', | ||
variationValue: 2, | ||
|
@@ -115,13 +115,13 @@ describe('EppoClient get*AssignmentDetails', () => { | |
matchedAllocation: { | ||
key: '50/50 split', | ||
allocationEvaluationCode: AllocationEvaluationCode.MATCH, | ||
orderPosition: 1, | ||
orderPosition: 2, | ||
}, | ||
unmatchedAllocations: [ | ||
{ | ||
key: 'targeted allocation', | ||
allocationEvaluationCode: AllocationEvaluationCode.FAILING_RULE, | ||
orderPosition: 0, | ||
orderPosition: 1, | ||
}, | ||
], | ||
unevaluatedAllocations: [], | ||
|
@@ -139,7 +139,7 @@ describe('EppoClient get*AssignmentDetails', () => { | |
subjectAttributes, | ||
'', | ||
); | ||
const expected: AssignmentDetails<string> = { | ||
const expected: IAssignmentDetails<string> = { | ||
value: 'control', | ||
flagEvaluationCode: 'MATCH', | ||
flagEvaluationDescription: | ||
|
@@ -201,7 +201,7 @@ describe('EppoClient get*AssignmentDetails', () => { | |
matchedAllocation: null, | ||
unmatchedAllocations: [], | ||
unevaluatedAllocations: [], | ||
} as AssignmentDetails<number>); | ||
} as IAssignmentDetails<number>); | ||
}); | ||
|
||
describe('UFC General Test Cases', () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,9 @@ import { | |
MOCK_UFC_RESPONSE_FILE, | ||
OBFUSCATED_MOCK_UFC_RESPONSE_FILE, | ||
SubjectTestCase, | ||
getTestAssignmentDetails, | ||
getTestAssignments, | ||
readAssignmentTestData, | ||
readMockUFCResponse, | ||
validateTestAssignmentDetails, | ||
validateTestAssignments, | ||
} from '../../test/testHelpers'; | ||
import ApiEndpoints from '../api-endpoints'; | ||
|
@@ -19,16 +17,10 @@ import { IConfigurationStore } from '../configuration-store/configuration-store' | |
import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.store'; | ||
import { MAX_EVENT_QUEUE_SIZE, POLL_INTERVAL_MS, POLL_JITTER_PCT } from '../constants'; | ||
import FlagConfigurationRequestor from '../flag-configuration-requestor'; | ||
import { AllocationEvaluationCode } from '../flag-evaluation-details-builder'; | ||
import FetchHttpClient from '../http-client'; | ||
import { Flag, ObfuscatedFlag, VariationType } from '../interfaces'; | ||
import { OperatorType } from '../rules'; | ||
|
||
import EppoClient, { | ||
AssignmentDetails, | ||
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. Guessing these were unused imports 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. Yup! |
||
FlagConfigurationRequestParameters, | ||
checkTypeMatch, | ||
} from './eppo-client'; | ||
import EppoClient, { FlagConfigurationRequestParameters, checkTypeMatch } from './eppo-client'; | ||
|
||
export async function init(configurationStore: IConfigurationStore<Flag | ObfuscatedFlag>) { | ||
const apiEndpoints = new ApiEndpoints({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ import { EppoValue } from '../eppo_value'; | |
import { Evaluator, FlagEvaluation, noneResult } from '../evaluator'; | ||
import FlagConfigurationRequestor from '../flag-configuration-requestor'; | ||
import { | ||
FlagEvaluationDetails, | ||
IFlagEvaluationDetails, | ||
FlagEvaluationDetailsBuilder, | ||
} from '../flag-evaluation-details-builder'; | ||
import FetchHttpClient from '../http-client'; | ||
|
@@ -31,7 +31,7 @@ import { validateNotBlank } from '../validation'; | |
import { LIB_VERSION } from '../version'; | ||
|
||
export interface IAssignmentDetails<T extends Variation['value'] | object> | ||
extends FlagEvaluationDetails { | ||
extends IFlagEvaluationDetails { | ||
value: T; | ||
} | ||
|
||
|
@@ -400,7 +400,7 @@ export default class EppoClient { | |
subjectAttributes: Record<string, AttributeType>, | ||
defaultValue: EppoValue, | ||
expectedVariationType: VariationType, | ||
): { eppoValue: EppoValue; flagEvaluationDetails: FlagEvaluationDetails } { | ||
): { eppoValue: EppoValue; flagEvaluationDetails: IFlagEvaluationDetails } { | ||
try { | ||
const result = this.getAssignmentDetail( | ||
flagKey, | ||
|
@@ -622,6 +622,7 @@ export default class EppoClient { | |
sdkLanguage: 'javascript', | ||
sdkLibVersion: LIB_VERSION, | ||
}, | ||
details: result.flagEvaluationDetails, | ||
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. 🕵️♂️ Spotted the actual change! 😛 |
||
}; | ||
|
||
if (variation && allocationKey) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ export interface AllocationEvaluation { | |
orderPosition: number; | ||
} | ||
|
||
export interface FlagEvaluationDetails { | ||
export interface IFlagEvaluationDetails { | ||
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. Nice! Yes this is our naming convention for interfaces |
||
variationKey: string | null; | ||
variationValue: Variation['value'] | null; | ||
flagEvaluationCode: FlagEvaluationCode; | ||
|
@@ -40,12 +40,12 @@ export interface FlagEvaluationDetails { | |
} | ||
|
||
export class FlagEvaluationDetailsBuilder { | ||
private variationKey: FlagEvaluationDetails['variationKey']; | ||
private variationValue: FlagEvaluationDetails['variationValue']; | ||
private matchedRule: FlagEvaluationDetails['matchedRule']; | ||
private matchedAllocation: FlagEvaluationDetails['matchedAllocation']; | ||
private unmatchedAllocations: FlagEvaluationDetails['unmatchedAllocations']; | ||
private unevaluatedAllocations: FlagEvaluationDetails['unevaluatedAllocations']; | ||
private variationKey: IFlagEvaluationDetails['variationKey']; | ||
private variationValue: IFlagEvaluationDetails['variationValue']; | ||
private matchedRule: IFlagEvaluationDetails['matchedRule']; | ||
private matchedAllocation: IFlagEvaluationDetails['matchedAllocation']; | ||
private unmatchedAllocations: IFlagEvaluationDetails['unmatchedAllocations']; | ||
private unevaluatedAllocations: IFlagEvaluationDetails['unevaluatedAllocations']; | ||
|
||
constructor( | ||
private readonly allocations: Allocation[], | ||
|
@@ -122,12 +122,12 @@ export class FlagEvaluationDetailsBuilder { | |
buildForNoneResult = ( | ||
flagEvaluationCode: FlagEvaluationCode, | ||
flagEvaluationDescription: string, | ||
): FlagEvaluationDetails => this.setNone().build(flagEvaluationCode, flagEvaluationDescription); | ||
): IFlagEvaluationDetails => this.setNone().build(flagEvaluationCode, flagEvaluationDescription); | ||
|
||
build = ( | ||
flagEvaluationCode: FlagEvaluationCode, | ||
flagEvaluationDescription: string, | ||
): FlagEvaluationDetails => ({ | ||
): IFlagEvaluationDetails => ({ | ||
flagEvaluationCode, | ||
flagEvaluationDescription, | ||
variationKey: this.variationKey, | ||
|
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.
The purpose of this test was not obvious to me until I ran it myself. It will fail if any required attribute in
IAssignmentEvent
is missing but will pass if attributes not specified inIAssignmentEvent
are included in theevent
object (the latter behavior is described by the test "it" statement)Just a suggestion (feel free to take it or leave it): if it's not too much trouble, you could add a test that checks for a thrown exception if
details
(a required attribute in theevent
object) is missing