@@ -2467,13 +2467,27 @@ describe('lib/optimizely', function() {
2467
2467
} ) ;
2468
2468
2469
2469
describe ( '#isFeatureEnabled' , function ( ) {
2470
+ var decisionListener ;
2470
2471
2472
+ beforeEach ( function ( ) {
2473
+ decisionListener . spy ( ) ;
2474
+ } ) ;
2471
2475
it ( 'returns false, and does not dispatch an impression event, for an invalid feature key' , function ( ) {
2472
2476
var result = optlyInstance . isFeatureEnabled ( 'thisIsDefinitelyNotAFeatureKey' , 'user1' ) ;
2473
2477
assert . strictEqual ( result , false ) ;
2474
2478
sinon . assert . notCalled ( eventDispatcher . dispatchEvent ) ;
2475
2479
} ) ;
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
+ } ) ;
2476
2485
2486
+ var result = optlyInstance . isFeatureEnabled ( 'thisIsDefinitelyNotAFeatureKey' , 'user1' ) ;
2487
+ assert . strictEqual ( result , false ) ;
2488
+ sinon . assert . notCalled ( eventDispatcher . dispatchEvent ) ;
2489
+ simon . assert . notCalled ( decisionListener )
2490
+ } ) ;
2477
2491
it ( 'returns false if the instance is invalid' , function ( ) {
2478
2492
optlyInstance = new Optimizely ( {
2479
2493
clientEngine : 'node-sdk' ,
@@ -2492,6 +2506,29 @@ describe('lib/optimizely', function() {
2492
2506
sinon . assert . calledWith ( createdLogger . log , LOG_LEVEL . ERROR , 'OPTIMIZELY: Optimizely object is not valid. Failing isFeatureEnabled.' ) ;
2493
2507
} ) ;
2494
2508
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
+
2495
2532
describe ( 'when the user bucketed into a variation of an experiment with the feature' , function ( ) {
2496
2533
var attributes = { test_attribute : 'test_value' } ;
2497
2534
@@ -2771,12 +2808,6 @@ describe('lib/optimizely', function() {
2771
2808
} ) ;
2772
2809
2773
2810
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
-
2780
2811
describe ( 'when the variation is toggled ON' , function ( ) {
2781
2812
beforeEach ( function ( ) {
2782
2813
// This experiment is the first audience targeting rule in the rollout of feature 'test_feature'
@@ -2816,17 +2847,6 @@ describe('lib/optimizely', function() {
2816
2847
} ) ;
2817
2848
2818
2849
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
-
2830
2850
it ( 'returns false ' , function ( ) {
2831
2851
var result = optlyInstance . isFeatureEnabled ( 'test_feature' , 'user1' , {
2832
2852
test_attribute : 'test_value' ,
@@ -2870,7 +2890,7 @@ describe('lib/optimizely', function() {
2870
2890
} ) ;
2871
2891
2872
2892
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 ( ) {
2874
2894
optlyInstance . notificationCenter . addNotificationListener ( {
2875
2895
enums. NOTIFICATION_TYPES . FEATURE_ROLLOUT ,
2876
2896
decisionListener
0 commit comments