@@ -580,6 +580,10 @@ describe('RoktManager', () => {
580580 attributes : {
581581 mapped_key : 'test_value' , // This key should be mapped
582582 other_attr : 'other_value' // This key should remain unchanged
583+ } ,
584+ devPassedAttributes : {
585+ original_key : 'test_value' ,
586+ other_attr : 'other_value'
583587 }
584588 } ;
585589
@@ -645,7 +649,10 @@ describe('RoktManager', () => {
645649 } as IRoktSelectPlacementsOptions ;
646650
647651 roktManager . selectPlacements ( options ) ;
648- expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( options ) ;
652+ expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( {
653+ attributes : { } ,
654+ devPassedAttributes : { }
655+ } ) ;
649656 } ) ;
650657
651658 it ( 'should call kit.selectPlacements with passed in attributes' , async ( ) => {
@@ -677,7 +684,22 @@ describe('RoktManager', () => {
677684 } ;
678685
679686 await roktManager . selectPlacements ( options ) ;
680- expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( options ) ;
687+ expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( {
688+ attributes : {
689+ age : 25 ,
690+ score : 100.5 ,
691+ isSubscribed : true ,
692+ isActive : false ,
693+ interests : 'sports,music,books'
694+ } ,
695+ devPassedAttributes : {
696+ age : 25 ,
697+ score : 100.5 ,
698+ isSubscribed : true ,
699+ isActive : false ,
700+ interests : 'sports,music,books'
701+ }
702+ } ) ;
681703 } ) ;
682704
683705 it ( 'should queue the selectPlacements method if no launcher or kit is attached' , ( ) => {
@@ -739,7 +761,10 @@ describe('RoktManager', () => {
739761
740762 expect ( roktManager [ 'kit' ] ) . not . toBeNull ( ) ;
741763 expect ( roktManager [ 'messageQueue' ] . size ) . toBe ( 0 ) ;
742- expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( options ) ;
764+ expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( {
765+ attributes : { } ,
766+ devPassedAttributes : { }
767+ } ) ;
743768 expect ( result ) . toEqual ( expectedResult ) ;
744769 } ) ;
745770
@@ -779,9 +804,26 @@ describe('RoktManager', () => {
779804 }
780805 } ;
781806
807+ const expectedOptions = {
808+ attributes : {
809+ age : 25 ,
810+ score : 100.5 ,
811+ isSubscribed : true ,
812+ isActive : false ,
813+ interests : 'sports,music,books'
814+ } ,
815+ devPassedAttributes : {
816+ age : 25 ,
817+ score : 100.5 ,
818+ isSubscribed : true ,
819+ isActive : false ,
820+ interests : 'sports,music,books'
821+ }
822+ } ;
823+
782824 roktManager . selectPlacements ( options ) ;
783- expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( options ) ;
784- expect ( kit . launcher . selectPlacements ) . toHaveBeenCalledWith ( options ) ;
825+ expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( expectedOptions ) ;
826+ expect ( kit . launcher . selectPlacements ) . toHaveBeenCalledWith ( expectedOptions ) ;
785827 } ) ;
786828
787829 it ( 'should pass sandbox flag as an attribute through to kit.selectPlacements' , ( ) => {
@@ -811,7 +853,17 @@ describe('RoktManager', () => {
811853 } ;
812854
813855 roktManager . selectPlacements ( options ) ;
814- expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( options ) ;
856+ expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( {
857+ attributes : {
858+ customAttr : 'value' ,
859+ sandbox : true
860+ } ,
861+ identifier : 'test-identifier' ,
862+ devPassedAttributes : {
863+ customAttr : 'value' ,
864+ sandbox : true
865+ }
866+ } ) ;
815867 } ) ;
816868
817869 it ( 'should NOT override global sandbox in placement attributes when initialized as true' , ( ) => {
@@ -843,7 +895,16 @@ describe('RoktManager', () => {
843895 roktManager . selectPlacements ( options ) ;
844896
845897 expect ( roktManager [ 'sandbox' ] ) . toBeTruthy ( ) ;
846- expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( options ) ;
898+ expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( {
899+ attributes : {
900+ customAttr : 'value' ,
901+ sandbox : false
902+ } ,
903+ devPassedAttributes : {
904+ customAttr : 'value' ,
905+ sandbox : false
906+ }
907+ } ) ;
847908 } ) ;
848909
849910 it ( 'should set sandbox in placement attributes when not initialized globally' , ( ) => {
@@ -874,7 +935,17 @@ describe('RoktManager', () => {
874935 } ;
875936
876937 roktManager . selectPlacements ( options ) ;
877- expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( options ) ;
938+ expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( {
939+ attributes : {
940+ customAttr : 'value' ,
941+ sandbox : true
942+ } ,
943+ identifier : 'test-identifier' ,
944+ devPassedAttributes : {
945+ customAttr : 'value' ,
946+ sandbox : true
947+ }
948+ } ) ;
878949 } ) ;
879950
880951 it ( 'should pass mapped attributes to kit.launcher.selectPlacements' , ( ) => {
@@ -919,6 +990,11 @@ describe('RoktManager', () => {
919990 firstname : 'John' ,
920991 lastname : 'Doe' ,
921992 score : 42 ,
993+ } ,
994+ devPassedAttributes : {
995+ 'f.name' : 'John' ,
996+ 'last_name' : 'Doe' ,
997+ 'score' : 42 ,
922998 }
923999 } ;
9241000
@@ -952,7 +1028,101 @@ describe('RoktManager', () => {
9521028 } ;
9531029
9541030 roktManager . selectPlacements ( options ) ;
955- expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( options ) ;
1031+ expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( {
1032+ attributes : {
1033+ 'f.name' : 'John' ,
1034+ 'last_name' : 'Doe' ,
1035+ 'score' : 42 ,
1036+ 'age' : 25 ,
1037+ } ,
1038+ devPassedAttributes : {
1039+ 'f.name' : 'John' ,
1040+ 'last_name' : 'Doe' ,
1041+ 'score' : 42 ,
1042+ 'age' : 25 ,
1043+ }
1044+ } ) ;
1045+ } ) ;
1046+
1047+ it ( 'should pass devPassedAttributes to kit for event logging' , ( ) => {
1048+ const kit : Partial < IRoktKit > = {
1049+ launcher : {
1050+ selectPlacements : jest . fn ( ) ,
1051+ hashAttributes : jest . fn ( ) ,
1052+ use : jest . fn ( ) ,
1053+ } ,
1054+ hashAttributes : jest . fn ( ) ,
1055+ selectPlacements : jest . fn ( ) ,
1056+ setExtensionData : jest . fn ( ) ,
1057+ use : jest . fn ( ) ,
1058+ } ;
1059+
1060+ roktManager . kit = kit as IRoktKit ;
1061+ roktManager [ 'placementAttributesMapping' ] = [ ] ;
1062+
1063+ const options : IRoktSelectPlacementsOptions = {
1064+ attributes : {
1065+ 'customAttr' : 'value' ,
1066+ }
1067+ } ;
1068+
1069+ roktManager . selectPlacements ( options ) ;
1070+
1071+ expect ( kit . selectPlacements ) . toHaveBeenCalledWith (
1072+ expect . objectContaining ( {
1073+ devPassedAttributes : {
1074+ 'customAttr' : 'value' ,
1075+ }
1076+ } )
1077+ ) ;
1078+ } ) ;
1079+
1080+ it ( 'should include original attributes in devPassedAttributes even after mapping' , ( ) => {
1081+ const kit : Partial < IRoktKit > = {
1082+ launcher : {
1083+ selectPlacements : jest . fn ( ) ,
1084+ hashAttributes : jest . fn ( ) ,
1085+ use : jest . fn ( ) ,
1086+ } ,
1087+ hashAttributes : jest . fn ( ) ,
1088+ selectPlacements : jest . fn ( ) ,
1089+ setExtensionData : jest . fn ( ) ,
1090+ use : jest . fn ( ) ,
1091+ } ;
1092+
1093+ roktManager . kit = kit as IRoktKit ;
1094+ roktManager [ 'placementAttributesMapping' ] = [
1095+ {
1096+ jsmap : null ,
1097+ map : 'f.name' ,
1098+ maptype : 'UserAttributeClass.Name' ,
1099+ value : 'firstname'
1100+ }
1101+ ] ;
1102+
1103+ const options : IRoktSelectPlacementsOptions = {
1104+ attributes : {
1105+ 'f.name' : 'John' ,
1106+ 'userId' : 'user123' ,
1107+ }
1108+ } ;
1109+
1110+ roktManager . selectPlacements ( options ) ;
1111+
1112+ // devPassedAttributes should contain the ORIGINAL unmapped attributes
1113+ expect ( kit . selectPlacements ) . toHaveBeenCalledWith (
1114+ expect . objectContaining ( {
1115+ devPassedAttributes : {
1116+ 'f.name' : 'John' ,
1117+ 'userId' : 'user123' ,
1118+ } ,
1119+ // attributes should be mapped
1120+ attributes : {
1121+ 'firstname' : 'John' ,
1122+ 'userId' : 'user123' ,
1123+ }
1124+ } )
1125+ ) ;
9561126 } ) ;
9571127
9581128 it ( 'should set the mapped attributes on the current user via setUserAttributes' , async ( ) => {
@@ -1031,7 +1201,14 @@ describe('RoktManager', () => {
10311201 } ;
10321202
10331203 roktManager . selectPlacements ( options ) ;
1034- expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( options ) ;
1204+ expect ( kit . selectPlacements ) . toHaveBeenCalledWith ( {
1205+ attributes : {
1206+ 'sandbox' : true
1207+ } ,
1208+ devPassedAttributes : {
1209+ 'sandbox' : true
1210+ }
1211+ } ) ;
10351212 expect ( roktManager [ 'currentUser' ] . setUserAttributes ) . not . toHaveBeenCalledWith ( {
10361213 sandbox : true
10371214 } ) ;
0 commit comments