@@ -17,7 +17,7 @@ import { assert, expect } from 'chai';
17
17
import sinon from 'sinon' ;
18
18
import { sprintf } from '../utils/fns' ;
19
19
import { NOTIFICATION_TYPES } from '../notification_center/type' ;
20
- import Optimizely from './' ;
20
+ import Optimizely , { INVALID_ATTRIBUTES , INVALID_IDENTIFIER } from './' ;
21
21
import OptimizelyUserContext from '../optimizely_user_context' ;
22
22
import { OptimizelyDecideOption } from '../shared_types' ;
23
23
import AudienceEvaluator from '../core/audience_evaluator' ;
@@ -4379,14 +4379,16 @@ describe('lib/optimizely', function() {
4379
4379
assert . deepEqual ( userId , user . getUserId ( ) ) ;
4380
4380
} ) ;
4381
4381
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 ) ;
4385
4386
} ) ;
4386
4387
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 ) ;
4390
4392
} ) ;
4391
4393
4392
4394
it ( 'should create multiple instances of OptimizelyUserContext' , function ( ) {
@@ -4405,11 +4407,11 @@ describe('lib/optimizely', function() {
4405
4407
assert . deepEqual ( user2 . getUserId ( ) , userId2 ) ;
4406
4408
} ) ;
4407
4409
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 ( ) {
4409
4411
const { optlyInstance, errorNotifier, createdLogger } = getOptlyInstance ( {
4410
4412
datafileObj : testData . getTestDecideProjectConfig ( ) ,
4411
4413
} ) ;
4412
- assert . isNull ( optlyInstance . createUserContext ( 1 ) ) ;
4414
+ assert . throws ( ( ) => optlyInstance . createUserContext ( 1 ) , Error , INVALID_IDENTIFIER ) ;
4413
4415
sinon . assert . calledOnce ( errorNotifier . notify ) ;
4414
4416
// var errorMessage = errorHandler.handleError.lastCall.args[0].message;
4415
4417
// assert.strictEqual(errorMessage, sprintf(INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id'));
@@ -4418,11 +4420,11 @@ describe('lib/optimizely', function() {
4418
4420
// assert.strictEqual(logMessage, sprintf(INVALID_INPUT_FORMAT, 'OPTIMIZELY', 'user_id'));
4419
4421
} ) ;
4420
4422
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 ( ) {
4422
4424
const { optlyInstance, errorNotifier, createdLogger } = getOptlyInstance ( {
4423
4425
datafileObj : testData . getTestDecideProjectConfig ( ) ,
4424
4426
} ) ;
4425
- assert . isNull ( optlyInstance . createUserContext ( 'user1' , 'invalid_attributes' ) ) ;
4427
+ assert . throws ( ( ) => optlyInstance . createUserContext ( 'user1' , 'invalid_attributes' ) , Error , INVALID_ATTRIBUTES ) ;
4426
4428
sinon . assert . calledOnce ( errorNotifier . notify ) ;
4427
4429
// var errorMessage = errorHandler.handleError.lastCall.args[0].message;
4428
4430
// assert.strictEqual(errorMessage, sprintf(INVALID_ATTRIBUTES, 'ATTRIBUTES_VALIDATOR'));
0 commit comments