Skip to content

Commit 7e11082

Browse files
mfahadahmedmikeproeng37
authored andcommitted
getEnabledFeatures returns sorted feature-keys. (#80)
1 parent 6488859 commit 7e11082

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/optimizely-sdk-core/lib/optimizely/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ Optimizely.prototype.getEnabledFeatures = function(userId, attributes) {
516516
}
517517
}.bind(this));
518518

519-
return enabledFeatures;
519+
return enabledFeatures.sort();
520520
};
521521

522522
/**

packages/optimizely-sdk-core/lib/optimizely/index.tests.js

+29
Original file line numberDiff line numberDiff line change
@@ -2837,6 +2837,35 @@ describe('lib/optimizely', function() {
28372837
attributes
28382838
);
28392839
});
2840+
2841+
it('returns sorted feature-key list', function() {
2842+
var sortedFeatures = [
2843+
'feature_with_group',
2844+
'shared_feature',
2845+
'test_feature',
2846+
'test_feature_2',
2847+
'test_feature_for_experiment',
2848+
'unused_flag'
2849+
];
2850+
2851+
sandbox.restore();
2852+
sandbox.stub(optlyInstance, 'isFeatureEnabled', function(featureKey) {
2853+
return sortedFeatures.indexOf(featureKey) !== -1;
2854+
});
2855+
var attributes = { test_attribute: 'test_value' };
2856+
var result = optlyInstance.getEnabledFeatures('user1', attributes);
2857+
assert.deepEqual(sortedFeatures, result);
2858+
sinon.assert.callCount(optlyInstance.isFeatureEnabled, 6);
2859+
2860+
sinon.assert.callOrder(
2861+
optlyInstance.isFeatureEnabled.withArgs('test_feature', 'user1', attributes),
2862+
optlyInstance.isFeatureEnabled.withArgs('test_feature_2', 'user1', attributes),
2863+
optlyInstance.isFeatureEnabled.withArgs('test_feature_for_experiment', 'user1', attributes),
2864+
optlyInstance.isFeatureEnabled.withArgs('feature_with_group', 'user1', attributes),
2865+
optlyInstance.isFeatureEnabled.withArgs('shared_feature', 'user1', attributes),
2866+
optlyInstance.isFeatureEnabled.withArgs('unused_flag', 'user1', attributes)
2867+
);
2868+
});
28402869
});
28412870

28422871
describe('feature variable APIs', function() {

0 commit comments

Comments
 (0)