@@ -17,7 +17,7 @@ import { assert, expect } from 'chai';
1717import sinon from 'sinon' ;
1818import { sprintf } from '../utils/fns' ;
1919import { NOTIFICATION_TYPES } from '../notification_center/type' ;
20- import Optimizely from './' ;
20+ import Optimizely , { INVALID_ATTRIBUTES , INVALID_IDENTIFIER } from './' ;
2121import OptimizelyUserContext from '../optimizely_user_context' ;
2222import { OptimizelyDecideOption } from '../shared_types' ;
2323import AudienceEvaluator from '../core/audience_evaluator' ;
@@ -4379,14 +4379,16 @@ describe('lib/optimizely', function() {
43794379 assert . deepEqual ( userId , user . getUserId ( ) ) ;
43804380 } ) ;
43814381
4382- it ( 'should return null OptimizelyUserContext when input userId is null' , function ( ) {
4383- var user = optlyInstance . createUserContext ( null ) ;
4384- assert . deepEqual ( null , user ) ;
4382+ it ( 'should throw error when input userId is null' , function ( ) {
4383+ assert . throws ( ( ) => {
4384+ optlyInstance . createUserContext ( null ) ;
4385+ } , Error , INVALID_IDENTIFIER ) ;
43854386 } ) ;
43864387
4387- it ( 'should return null OptimizelyUserContext when input userId is undefined' , function ( ) {
4388- var user = optlyInstance . createUserContext ( undefined ) ;
4389- assert . deepEqual ( null , user ) ;
4388+ it ( 'should throw error when input userId is undefined' , function ( ) {
4389+ assert . throws ( ( ) => {
4390+ optlyInstance . createUserContext ( undefined ) ;
4391+ } , Error , INVALID_IDENTIFIER ) ;
43904392 } ) ;
43914393
43924394 it ( 'should create multiple instances of OptimizelyUserContext' , function ( ) {
@@ -4405,11 +4407,11 @@ describe('lib/optimizely', function() {
44054407 assert . deepEqual ( user2 . getUserId ( ) , userId2 ) ;
44064408 } ) ;
44074409
4408- it ( 'should call the error handler for invalid user ID and return null ' , function ( ) {
4410+ it ( 'should call the error handler for invalid user ID and throw ' , function ( ) {
44094411 const { optlyInstance, errorNotifier, createdLogger } = getOptlyInstance ( {
44104412 datafileObj : testData . getTestDecideProjectConfig ( ) ,
44114413 } ) ;
4412- assert . isNull ( optlyInstance . createUserContext ( 1 ) ) ;
4414+ assert . throws ( ( ) => optlyInstance . createUserContext ( 1 ) , Error , INVALID_IDENTIFIER ) ;
44134415 sinon . assert . calledOnce ( errorNotifier . notify ) ;
44144416 // var errorMessage = errorHandler.handleError.lastCall.args[0].message;
44154417 // assert.strictEqual(errorMessage, sprintf(INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id'));
@@ -4418,11 +4420,11 @@ describe('lib/optimizely', function() {
44184420 // assert.strictEqual(logMessage, sprintf(INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id'));
44194421 } ) ;
44204422
4421- it ( 'should call the error handler for invalid attributes and return null ' , function ( ) {
4423+ it ( 'should call the error handler for invalid attributes and throw ' , function ( ) {
44224424 const { optlyInstance, errorNotifier, createdLogger } = getOptlyInstance ( {
44234425 datafileObj : testData . getTestDecideProjectConfig ( ) ,
44244426 } ) ;
4425- assert . isNull ( optlyInstance . createUserContext ( 'user1' , 'invalid_attributes' ) ) ;
4427+ assert . throws ( ( ) => optlyInstance . createUserContext ( 'user1' , 'invalid_attributes' ) , Error , INVALID_ATTRIBUTES ) ;
44264428 sinon . assert . calledOnce ( errorNotifier . notify ) ;
44274429 // var errorMessage = errorHandler.handleError.lastCall.args[0].message;
44284430 // assert.strictEqual(errorMessage, sprintf(INVALID_ATTRIBUTES, 'ATTRIBUTES_VALIDATOR'));
0 commit comments