-
Notifications
You must be signed in to change notification settings - Fork 83
feat(flag-decisions): Add support for sending flag decisions #599
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
15 commits
Select commit
Hold shift + click to select a range
865b852
Update activate and isFeatureEnabled to send decision events
yavorona 4e6b706
Upgrade event-processor to 0.7.0
yavorona 0eb0ee2
Add createEventProcessor factory function
5b407d5
Add tests for getSendFlagDecisionsValue method
yavorona c4d1d51
Update variationKey type to be string
yavorona 6f755d2
Refactor isFeatureEnabled
yavorona a0f873c
Pass decision object instead of 4 individual values
yavorona d90f509
Update DecisionService setForcedVariation signature and comments
yavorona bfb33ab
Use optional chaining and nullish coalescing operator
yavorona 4df5b3f
Create decision helper functions
yavorona 69c0133
Address comments
yavorona 3a338a4
Clean up
yavorona d1e1f9a
Fix experiment decision object
yavorona 1e896cc
Change variation_key to '' instead of null in metadata
yavorona ad8ace8
Update Changelog
yavorona 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Copyright 2020, Optimizely | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { assert } from 'chai'; | ||
import { rolloutDecisionObj, featureTestDecisionObj } from '../../tests/test_data'; | ||
import * as decision from './'; | ||
|
||
describe('lib/core/decision', function() { | ||
describe('getExperimentKey method', function() { | ||
it('should return empty string when experiment is null', function() { | ||
var experimentKey = decision.getExperimentKey(rolloutDecisionObj); | ||
assert.strictEqual(experimentKey, ''); | ||
}); | ||
|
||
it('should return empty string when experiment is not defined', function() { | ||
var experimentKey = decision.getExperimentKey({}); | ||
assert.strictEqual(experimentKey, ''); | ||
}); | ||
|
||
it('should return experiment key when experiment is defined', function() { | ||
var experimentKey = decision.getExperimentKey(featureTestDecisionObj); | ||
assert.strictEqual(experimentKey, 'testing_my_feature'); | ||
}); | ||
}); | ||
|
||
describe('getVariationKey method', function() { | ||
it('should return empty string when variation is null', function() { | ||
var variationKey = decision.getVariationKey(rolloutDecisionObj); | ||
assert.strictEqual(variationKey, ''); | ||
}); | ||
|
||
it('should return empty string when variation is not defined', function() { | ||
var variationKey = decision.getVariationKey({}); | ||
assert.strictEqual(variationKey, ''); | ||
}); | ||
|
||
it('should return variation key when variation is defined', function() { | ||
var variationKey = decision.getVariationKey(featureTestDecisionObj); | ||
assert.strictEqual(variationKey, 'variation'); | ||
}); | ||
}); | ||
|
||
describe('getFeatureEnabledFromVariation method', function() { | ||
it('should return false when variation is null', function() { | ||
var featureEnabled = decision.getFeatureEnabledFromVariation(rolloutDecisionObj); | ||
assert.strictEqual(featureEnabled, false); | ||
}); | ||
|
||
it('should return false when variation is not defined', function() { | ||
var featureEnabled = decision.getFeatureEnabledFromVariation({}); | ||
assert.strictEqual(featureEnabled, false); | ||
}); | ||
|
||
it('should return featureEnabled boolean when variation is defined', function() { | ||
var featureEnabled = decision.getFeatureEnabledFromVariation(featureTestDecisionObj); | ||
assert.strictEqual(featureEnabled, true); | ||
}); | ||
}); | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright 2020, Optimizely | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { DecisionObj } from '../decision_service'; | ||
|
||
/** | ||
* Get experiment key from the provided decision object | ||
* @param {DecisionObj} decisionObj Object representing decision | ||
* @returns {string} Experiment key or empty string if experiment is null | ||
*/ | ||
export function getExperimentKey(decisionObj: DecisionObj): string { | ||
return decisionObj.experiment?.key ?? ''; | ||
} | ||
|
||
/** | ||
* Get variation key from the provided decision object | ||
* @param {DecisionObj} decisionObj Object representing decision | ||
* @returns {string} Variation key or empty string if variation is null | ||
*/ | ||
export function getVariationKey(decisionObj: DecisionObj): string { | ||
return decisionObj.variation?.key ?? ''; | ||
} | ||
|
||
/** | ||
* Get featureEnabled from variation in the provided decision object | ||
* @param {DecisionObj} decisionObj Object representing decision | ||
* @returns {boolean} featureEnabled boolean or false if variation is null | ||
*/ | ||
export function getFeatureEnabledFromVariation(decisionObj: DecisionObj): boolean { | ||
return decisionObj.variation?.featureEnabled ?? false; | ||
} |
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
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
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.
Let's add some basic unit tests for this module. I think we should have some coverage for when
experiment
orvariation
arenull
orundefined
.