@@ -629,6 +629,49 @@ public void view_stopStartedAndNext() {
629629 ModuleViewsTests .validateView ("next" , 0.0 , 2 , 3 , false , true , null , TestUtils .keysValues [1 ], TestUtils .keysValues [0 ]);
630630 }
631631
632+ /**
633+ * Validates that when session calls are made, if any user properties are set,
634+ * they are sent before sending that session call
635+ * Validated with all session calls: begin, update, end
636+ *
637+ * @throws InterruptedException if thread is interrupted
638+ */
639+ @ Test
640+ public void userPropsOnSessions () throws InterruptedException {
641+ Countly .instance ().init (TestUtils .getConfigSessions (Config .Feature .UserProfiles ));
642+ Countly .instance ().userProfile ().setProperty ("name" , "John Doe" );
643+ Countly .instance ().userProfile ().setProperty ("custom_key" , "custom_value" );
644+
645+ Countly .session ().begin ();
646+ Map <String , String >[] RQ = TestUtils .getCurrentRQ ();
647+ UserEditorTests .validateUserDetailsRequestInRQ (TestUtils .map ("user_details" , TestUtils .json ("name" , "John Doe" , "custom" , TestUtils .map ("custom_key" , "custom_value" ))), 0 , 2 );
648+ Assert .assertEquals ("1" , RQ [1 ].get ("begin_session" ));
649+
650+ Thread .sleep (2000 ); // wait for session to update
651+ Countly .instance ().userProfile ().save ();
652+ RQ = TestUtils .getCurrentRQ ();
653+ Assert .assertEquals (2 , RQ .length ); // Validate that user properties are flushed
654+
655+ Countly .
instance ().
userProfile ().
setProperty (
"email" ,
"[email protected] " );
656+ Countly .session ().update ();
657+
658+ RQ = TestUtils .getCurrentRQ ();
659+ Assert .
assertEquals (
TestUtils .
json (
"email" ,
"[email protected] " ),
RQ [
2 ].
get (
"user_details" ));
660+ Assert .assertEquals ("2" , RQ [3 ].get ("session_duration" ));
661+
662+ Thread .sleep (2000 ); // wait for session to update
663+ Countly .instance ().userProfile ().save ();
664+ RQ = TestUtils .getCurrentRQ ();
665+ Assert .assertEquals (4 , RQ .length ); // Validate that user properties are flushed with update call
666+
667+ Countly .instance ().userProfile ().setProperty ("done" , "yes" );
668+ Countly .session ().end ();
669+
670+ RQ = TestUtils .getCurrentRQ ();
671+ Assert .assertEquals (TestUtils .json ("custom" , TestUtils .map ("done" , "yes" )), RQ [4 ].get ("user_details" ));
672+ Assert .assertEquals ("1" , RQ [5 ].get ("end_session" ));
673+ }
674+
632675 private void validateNotEquals (int idOffset , BiFunction <SessionImpl , SessionImpl , Consumer <Long >> setter ) {
633676 Countly .instance ().init (TestUtils .getConfigSessions ());
634677 long ts = TimeUtils .timestampMs ();
0 commit comments