@@ -30,6 +30,7 @@ import { BrowserOdpManager } from './plugins/odp_manager/index.browser';
3030import { OdpConfig } from './core/odp/odp_config' ;
3131import { BrowserOdpEventManager } from './plugins/odp/event_manager/index.browser' ;
3232import { BrowserOdpEventApiManager } from './plugins/odp/event_api_manager/index.browser' ;
33+ import { OdpEvent } from './core/odp/odp_event' ;
3334
3435var LocalStoragePendingEventsDispatcher = eventProcessor . LocalStoragePendingEventsDispatcher ;
3536
@@ -771,7 +772,7 @@ describe('javascript-sdk (Browser)', function() {
771772 sinon . assert . called ( fakeEventManager . start ) ;
772773 } ) ;
773774
774- it ( 'should send an odp event with sendOdpEvent' , async ( ) => {
775+ it ( 'should send an odp event when calling sendOdpEvent with valid parameters ' , async ( ) => {
775776 const fakeEventManager = {
776777 updateSettings : sinon . spy ( ) ,
777778 start : sinon . spy ( ) ,
@@ -803,6 +804,80 @@ describe('javascript-sdk (Browser)', function() {
803804 sinon . assert . called ( fakeEventManager . sendEvent ) ;
804805 } ) ;
805806
807+ it ( 'should throw an error and not send an odp event when calling sendOdpEvent with an invalid action input' , async ( ) => {
808+ const fakeEventManager = {
809+ updateSettings : sinon . spy ( ) ,
810+ start : sinon . spy ( ) ,
811+ stop : sinon . spy ( ) ,
812+ registerVuid : sinon . spy ( ) ,
813+ identifyUser : sinon . spy ( ) ,
814+ sendEvent : sinon . spy ( ) ,
815+ flush : sinon . spy ( ) ,
816+ } ;
817+
818+ const client = optimizelyFactory . createInstance ( {
819+ datafile : testData . getOdpIntegratedConfigWithSegments ( ) ,
820+ errorHandler : fakeErrorHandler ,
821+ eventDispatcher : fakeEventDispatcher ,
822+ eventBatchSize : null ,
823+ logger,
824+ odpOptions : {
825+ eventManager : fakeEventManager ,
826+ } ,
827+ } ) ;
828+
829+ const readyData = await client . onReady ( ) ;
830+ assert . equal ( readyData . success , true ) ;
831+ assert . isUndefined ( readyData . reason ) ;
832+
833+ client . sendOdpEvent ( '' ) ;
834+ sinon . assert . called ( logger . error ) ;
835+
836+ client . sendOdpEvent ( null ) ;
837+ sinon . assert . calledTwice ( logger . error ) ;
838+
839+ client . sendOdpEvent ( undefined ) ;
840+ sinon . assert . calledThrice ( logger . error ) ;
841+
842+ sinon . assert . notCalled ( fakeEventManager . sendEvent ) ;
843+ } ) ;
844+
845+ it ( 'should use fullstack as a fallback value for the odp event when calling sendOdpEvent with an empty type input' , async ( ) => {
846+ const fakeEventManager = {
847+ updateSettings : sinon . spy ( ) ,
848+ start : sinon . spy ( ) ,
849+ stop : sinon . spy ( ) ,
850+ registerVuid : sinon . spy ( ) ,
851+ identifyUser : sinon . spy ( ) ,
852+ sendEvent : sinon . spy ( ) ,
853+ flush : sinon . spy ( ) ,
854+ } ;
855+
856+ const client = optimizelyFactory . createInstance ( {
857+ datafile : testData . getOdpIntegratedConfigWithSegments ( ) ,
858+ errorHandler : fakeErrorHandler ,
859+ eventDispatcher : fakeEventDispatcher ,
860+ eventBatchSize : null ,
861+ logger,
862+ odpOptions : {
863+ eventManager : fakeEventManager ,
864+ } ,
865+ } ) ;
866+
867+ const readyData = await client . onReady ( ) ;
868+ assert . equal ( readyData . success , true ) ;
869+ assert . isUndefined ( readyData . reason ) ;
870+
871+ client . sendOdpEvent ( 'dummy-action' , '' ) ;
872+
873+ sinon . assert . calledWith ( fakeEventManager . sendEvent , {
874+ action : 'dummy-action' ,
875+ type : 'fullstack' ,
876+ identifiers : new Map ( ) ,
877+ data : new Map ( ) ,
878+ } ) ;
879+ } ) ;
880+
806881 it ( 'should log an error when attempting to send an odp event when odp is disabled' , async ( ) => {
807882 const client = optimizelyFactory . createInstance ( {
808883 datafile : testData . getTestProjectConfigWithFeatures ( ) ,
0 commit comments