Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 856f3ec

Browse files
more base cases
1 parent 0269181 commit 856f3ec

File tree

1 file changed

+38
-18
lines changed

1 file changed

+38
-18
lines changed

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

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,13 +2467,27 @@ describe('lib/optimizely', function() {
24672467
});
24682468

24692469
describe('#isFeatureEnabled', function() {
2470+
var decisionListener;
24702471

2472+
beforeEach(function(){
2473+
decisionListener.spy();
2474+
});
24712475
it('returns false, and does not dispatch an impression event, for an invalid feature key', function() {
24722476
var result = optlyInstance.isFeatureEnabled('thisIsDefinitelyNotAFeatureKey', 'user1');
24732477
assert.strictEqual(result, false);
24742478
sinon.assert.notCalled(eventDispatcher.dispatchEvent);
24752479
});
2480+
it('returns false, and does not trigger listener, for an invalid feature key', function() {
2481+
optlyInstance.notificationCenter.addNotificationListener({
2482+
enums.NOTIFICATION_TYPES.FEATURE_ROLLOUT,
2483+
decisionListener
2484+
});
24762485

2486+
var result = optlyInstance.isFeatureEnabled('thisIsDefinitelyNotAFeatureKey', 'user1');
2487+
assert.strictEqual(result, false);
2488+
sinon.assert.notCalled(eventDispatcher.dispatchEvent);
2489+
simon.assert.notCalled(decisionListener)
2490+
});
24772491
it('returns false if the instance is invalid', function() {
24782492
optlyInstance = new Optimizely({
24792493
clientEngine: 'node-sdk',
@@ -2492,6 +2506,29 @@ describe('lib/optimizely', function() {
24922506
sinon.assert.calledWith(createdLogger.log, LOG_LEVEL.ERROR, 'OPTIMIZELY: Optimizely object is not valid. Failing isFeatureEnabled.');
24932507
});
24942508

2509+
it('returns false and does not trigger listener if the instance is invalid', function() {
2510+
optlyInstance = new Optimizely({
2511+
clientEngine: 'node-sdk',
2512+
datafile: {
2513+
lasers: 300,
2514+
message: 'this is not a valid datafile'
2515+
},
2516+
eventBuilder: eventBuilder,
2517+
errorHandler: errorHandler,
2518+
eventDispatcher: eventDispatcher,
2519+
jsonSchemaValidator: jsonSchemaValidator,
2520+
logger: createdLogger,
2521+
});
2522+
optlyInstance.notificationCenter.addNotificationListener({
2523+
enums.NOTIFICATION_TYPES.FEATURE_ROLLOUT,
2524+
decisionListener
2525+
});
2526+
var result = optlyInstance.isFeatureEnabled('test_feature_for_experiment', 'user1');
2527+
assert.strictEqual(result, false);
2528+
sinon.assert.calledWith(createdLogger.log, LOG_LEVEL.ERROR, 'OPTIMIZELY: Optimizely object is not valid. Failing isFeatureEnabled.');
2529+
simon.assert.notCalled(decisionListener)
2530+
});
2531+
24952532
describe('when the user bucketed into a variation of an experiment with the feature', function() {
24962533
var attributes = { test_attribute: 'test_value' };
24972534

@@ -2771,12 +2808,6 @@ describe('lib/optimizely', function() {
27712808
});
27722809

27732810
describe('user bucketed into a variation of a rollout of the feature', function() {
2774-
var decisionListener;
2775-
2776-
beforeEach(function(){
2777-
decisionListener.spy();
2778-
});
2779-
27802811
describe('when the variation is toggled ON', function() {
27812812
beforeEach(function() {
27822813
// This experiment is the first audience targeting rule in the rollout of feature 'test_feature'
@@ -2816,17 +2847,6 @@ describe('lib/optimizely', function() {
28162847
});
28172848

28182849
describe('when the variation is toggled OFF', function() {
2819-
beforeEach(function() {
2820-
// This experiment is the second audience targeting rule in the rollout of feature 'test_feature'
2821-
var experiment = optlyInstance.configObj.experimentKeyMap['594037'];
2822-
var variation = experiment.variations[0];
2823-
sandbox.stub(optlyInstance.decisionService, 'getVariationForFeature').returns({
2824-
experiment: experiment,
2825-
variation: variation,
2826-
decisionSource: DECISION_SOURCES.ROLLOUT,
2827-
});
2828-
});
2829-
28302850
it('returns false ', function() {
28312851
var result = optlyInstance.isFeatureEnabled('test_feature', 'user1', {
28322852
test_attribute: 'test_value',
@@ -2870,7 +2890,7 @@ describe('lib/optimizely', function() {
28702890
});
28712891

28722892

2873-
it('returns false and does not dispatch an event and notification listener is not triggered', function() {
2893+
it('returns false and does not dispatch an event, and a notification listener is not triggered', function() {
28742894
optlyInstance.notificationCenter.addNotificationListener({
28752895
enums.NOTIFICATION_TYPES.FEATURE_ROLLOUT,
28762896
decisionListener

0 commit comments

Comments
 (0)