-
Notifications
You must be signed in to change notification settings - Fork 83
[FSSDK-11529] Impression event logic adjustment for holdouts #1076
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
junaed-optimizely
merged 19 commits into
master
from
junaed/fssdk-11529-update-impression-event
Aug 1, 2025
Merged
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6412e89
decision service holdout implementation
junaed-optimizely 3a90a81
[FSSDK-11528] audience condition improvement
junaed-optimizely f6c4cda
[FSSDK-11528] decision service tests added
junaed-optimizely 9a77240
[FSSDK-11528] decision service tests improvement
junaed-optimizely b8eac89
[FSSDK-11528] test improvement + decision service logic adjustment
junaed-optimizely 4c88648
[FSSDK-11528] feature toggle readibility improvement
junaed-optimizely aa3381e
[FSSDK-11528] type def update
junaed-optimizely 0d034b2
[FSSDK-11528] test improvement
junaed-optimizely 78eaa41
[FSSDK-11528] remove only
junaed-optimizely de3baaa
[FSSDK-11529] condition adjustment
junaed-optimizely 8e33597
Revert "[FSSDK-11529] condition adjustment"
junaed-optimizely 0618802
Reapply "[FSSDK-11529] condition adjustment"
junaed-optimizely 83b7017
[FSSDK-11529] test addition + layer logic adjustment
junaed-optimizely fc8181f
Merge branch 'master' into junaed/fssdk-11529-update-impression-event
junaed-optimizely 894af95
[FSSDK-11529] test data update
junaed-optimizely 4fc5339
[FSSDK-11529] test name update
junaed-optimizely eb3df08
[FSSDK-11529] review improvements
junaed-optimizely 504bb8c
[FSSDK-11529] fsc fix
junaed-optimizely 6bf661a
[FSSDK-11529] project config issue fix
junaed-optimizely 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -29,6 +29,34 @@ import { DECISION_SOURCES } from '../utils/enums'; | |||||
import OptimizelyUserContext from '../optimizely_user_context'; | ||||||
import { newErrorDecision } from '../optimizely_decision'; | ||||||
import { ImpressionEvent } from '../event_processor/event_builder/user_event'; | ||||||
import { OptimizelyDecideOption } from '../shared_types'; | ||||||
|
||||||
|
||||||
const holdoutData = [ | ||||||
{ | ||||||
id: 'holdout_test_id', | ||||||
key: 'holdout_test_key', | ||||||
status: 'Running', | ||||||
includeFlags: [], | ||||||
excludeFlags: [], | ||||||
audienceIds: [], | ||||||
audienceConditions: [], | ||||||
variations: [ | ||||||
{ | ||||||
id: 'holdout_variation_id', | ||||||
key: 'holdout_variation_key', | ||||||
variables: [], | ||||||
featureEnabled: false, | ||||||
}, | ||||||
], | ||||||
trafficAllocation: [ | ||||||
{ | ||||||
entityId: 'holdout_variation_id', | ||||||
endOfRange: 10000, | ||||||
}, | ||||||
], | ||||||
}, | ||||||
]; | ||||||
|
||||||
describe('Optimizely', () => { | ||||||
const eventDispatcher = { | ||||||
junaed-optimizely marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
@@ -212,5 +240,179 @@ describe('Optimizely', () => { | |||||
const event = processSpy.mock.calls[0][0] as ImpressionEvent; | ||||||
expect(event.cmabUuid).toBe('uuid-cmab'); | ||||||
}); | ||||||
|
||||||
it('should dispatch impression event for holdout decision', async () => { | ||||||
const datafile = getDecisionTestDatafile(); | ||||||
|
||||||
datafile.holdouts = holdoutData; | ||||||
const projectConfig = createProjectConfig(datafile); | ||||||
|
||||||
const projectConfigManager = getMockProjectConfigManager({ | ||||||
initConfig: projectConfig, | ||||||
}); | ||||||
|
||||||
const mockEventDispatcher = { | ||||||
dispatchEvent: vi.fn(() => Promise.resolve({ statusCode: 200 })), | ||||||
}; | ||||||
const eventProcessor = getForwardingEventProcessor(mockEventDispatcher); | ||||||
const processSpy = vi.spyOn(eventProcessor, 'process'); | ||||||
|
||||||
const optimizely = new Optimizely({ | ||||||
clientEngine: 'node-sdk', | ||||||
projectConfigManager, | ||||||
eventProcessor, | ||||||
jsonSchemaValidator, | ||||||
logger, | ||||||
odpManager, | ||||||
disposable: true, | ||||||
cmabService: {} as any | ||||||
}); | ||||||
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||||||
// @ts-ignore | ||||||
const decisionService = optimizely.decisionService; | ||||||
vi.spyOn(decisionService, 'resolveVariationsForFeatureList').mockImplementation(() => { | ||||||
return Value.of('async', [{ | ||||||
error: false, | ||||||
result: { | ||||||
variation: projectConfig.holdouts[0].variations[0], | ||||||
experiment: projectConfig.holdouts[0], | ||||||
decisionSource: DECISION_SOURCES.HOLDOUT, | ||||||
}, | ||||||
reasons: [], | ||||||
}]); | ||||||
}); | ||||||
|
||||||
const user = new OptimizelyUserContext({ | ||||||
optimizely, | ||||||
userId: 'test_user', | ||||||
attributes: {}, | ||||||
}); | ||||||
|
||||||
const decision = await optimizely.decideAsync(user, 'flag_1', []); | ||||||
|
||||||
expect(decision.ruleKey).toBe('holdout_test_key'); | ||||||
expect(decision.flagKey).toBe('flag_1'); | ||||||
expect(decision.variationKey).toBe('holdout_variation_key'); | ||||||
expect(decision.enabled).toBe(false); | ||||||
|
||||||
expect(eventProcessor.process).toHaveBeenCalledOnce(); | ||||||
|
||||||
const event = processSpy.mock.calls[0][0] as ImpressionEvent; | ||||||
|
||||||
expect(event.type).toBe('impression'); | ||||||
expect(event.ruleKey).toBe('holdout_test_key'); | ||||||
expect(event.ruleType).toBe('holdout'); | ||||||
expect(event.enabled).toBe(false); | ||||||
}); | ||||||
|
||||||
it('should not dispatch impression event for holdout when DISABLE_DECISION_EVENT is used', async () => { | ||||||
const datafile = getDecisionTestDatafile(); | ||||||
|
||||||
datafile.holdouts = holdoutData; | ||||||
|
||||||
const projectConfig = createProjectConfig(datafile); | ||||||
|
||||||
const projectConfigManager = getMockProjectConfigManager({ | ||||||
initConfig: projectConfig, | ||||||
}); | ||||||
|
||||||
const mockEventDispatcher = { | ||||||
dispatchEvent: vi.fn(() => Promise.resolve({ statusCode: 200 })), | ||||||
}; | ||||||
const eventProcessor = getForwardingEventProcessor(mockEventDispatcher); | ||||||
vi.spyOn(eventProcessor, 'process'); | ||||||
|
||||||
const optimizely = new Optimizely({ | ||||||
clientEngine: 'node-sdk', | ||||||
projectConfigManager, | ||||||
eventProcessor, | ||||||
jsonSchemaValidator, | ||||||
logger, | ||||||
odpManager, | ||||||
disposable: true, | ||||||
cmabService: {} as any | ||||||
}); | ||||||
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||||||
// @ts-ignore | ||||||
const decisionService = optimizely.decisionService; | ||||||
vi.spyOn(decisionService, 'resolveVariationsForFeatureList').mockImplementation(() => { | ||||||
return Value.of('async', [{ | ||||||
error: false, | ||||||
result: { | ||||||
variation: projectConfig.holdouts![0].variations[0], | ||||||
experiment: projectConfig.holdouts![0], | ||||||
decisionSource: DECISION_SOURCES.HOLDOUT, | ||||||
}, | ||||||
reasons: [], | ||||||
}]); | ||||||
}); | ||||||
|
||||||
const user = new OptimizelyUserContext({ | ||||||
optimizely, | ||||||
userId: 'test_user', | ||||||
attributes: {}, | ||||||
}); | ||||||
|
||||||
const decision = await optimizely.decideAsync(user, 'flag_1', [OptimizelyDecideOption.DISABLE_DECISION_EVENT]); | ||||||
|
||||||
expect(decision.ruleKey).toBe('holdout_test_key'); | ||||||
expect(decision.enabled).toBe(false); | ||||||
expect(eventProcessor.process).not.toHaveBeenCalled(); | ||||||
}); | ||||||
}); | ||||||
describe('isFeatureEnabled', () => { | ||||||
it('should dispatch impression event for holdout decision for isFeatureEnabled', async () => { | ||||||
const datafile = getDecisionTestDatafile(); | ||||||
datafile.holdouts = holdoutData; | ||||||
|
||||||
const projectConfig = createProjectConfig(datafile); | ||||||
const projectConfigManager = getMockProjectConfigManager({ | ||||||
initConfig: projectConfig, | ||||||
}); | ||||||
const mockEventDispatcher = { | ||||||
dispatchEvent: vi.fn(() => Promise.resolve({ statusCode: 200 })), | ||||||
}; | ||||||
const eventProcessor = getForwardingEventProcessor(mockEventDispatcher); | ||||||
vi.spyOn(eventProcessor, 'process'); | ||||||
|
||||||
const optimizely = new Optimizely({ | ||||||
clientEngine: 'node-sdk', | ||||||
projectConfigManager, | ||||||
eventProcessor, | ||||||
jsonSchemaValidator, | ||||||
logger, | ||||||
odpManager, | ||||||
disposable: true, | ||||||
cmabService: {} as any | ||||||
}); | ||||||
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||||||
// @ts-ignore | ||||||
const decisionService = optimizely.decisionService; | ||||||
vi.spyOn(decisionService, 'getVariationForFeature').mockReturnValue({ | ||||||
error: false, | ||||||
result: { | ||||||
variation: projectConfig.holdouts![0].variations[0], | ||||||
experiment: projectConfig.holdouts![0], | ||||||
decisionSource: DECISION_SOURCES.HOLDOUT, | ||||||
}, | ||||||
reasons: [], | ||||||
}); | ||||||
const result = optimizely.isFeatureEnabled('flag_1', 'test_user', {}); | ||||||
|
||||||
expect(result).toBe(false); | ||||||
|
||||||
expect(eventProcessor.process).toHaveBeenCalledOnce(); | ||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||||||
// @ts-ignore | ||||||
const event = eventProcessor.process.mock.calls[0][0] as ImpressionEvent; | ||||||
|
||||||
expect(event.type).toBe('impression'); | ||||||
expect(event.ruleKey).toBe('holdout_test_key'); | ||||||
expect(event.ruleType).toBe('holdout'); | ||||||
expect(event.enabled).toBe(false); | ||||||
}); | ||||||
}) | ||||||
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. Missing semicolon after the closing brace. This is inconsistent with the rest of the codebase style.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
}); |
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
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.
Uh oh!
There was an error while loading. Please reload this page.