Skip to content

Commit 6c1c248

Browse files
feat: automatic sessions test
1 parent 25a6353 commit 6c1c248

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

sdk/src/androidTest/java/ly/count/android/sdk/scUP_UserProfileTests.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,52 @@ public void eventSaveScenario_sessionCallsTriggersSave_M() throws JSONException,
163163
ModuleSessionsTests.validateSessionEndRequest(5, 2, TestUtils.commonDeviceId);
164164
}
165165

166+
/**
167+
* Related user properties should be saved with automatic session calls,
168+
* call order, user property before session, user property after begin session, session, user property after update session
169+
* generated request order user_properties + begin_session + user_properties + update_session + user properties + end_session
170+
*/
171+
@Test
172+
public void eventSaveScenario_sessionCallsTriggersSave_A() throws JSONException, InterruptedException {
173+
CountlyConfig config = TestUtils.createBaseConfig(TestUtils.getContext()).setTrackOrientationChanges(false);
174+
TestLifecycleObserver testLifecycleObserver = new TestLifecycleObserver();
175+
config.lifecycleObserver = testLifecycleObserver;
176+
config.setUpdateSessionTimerDelay(3);
177+
Countly countly = new Countly().init(config);
178+
179+
TestUtils.assertRQSize(0);
180+
countly.userProfile().setProperty("before_session", true);
181+
182+
testLifecycleObserver.bringToForeground();
183+
countly.onStart(null);
184+
185+
TestUtils.assertRQSize(2);
186+
ModuleUserProfileTests.validateUserProfileRequest(0, 2, TestUtils.map(), TestUtils.map("before_session", true));
187+
ModuleSessionsTests.validateSessionBeginRequest(1, TestUtils.commonDeviceId);
188+
189+
countly.userProfile().setProperty("after_begin_session", true);
190+
TestUtils.assertRQSize(2);
191+
192+
Thread.sleep(3000);
193+
194+
TestUtils.assertRQSize(4);
195+
196+
ModuleUserProfileTests.validateUserProfileRequest(2, 4, TestUtils.map(), TestUtils.map("after_begin_session", true));
197+
ModuleSessionsTests.validateSessionUpdateRequest(3, 3, TestUtils.commonDeviceId);
198+
199+
countly.userProfile().setProperty("after_update_session", true);
200+
TestUtils.assertRQSize(4);
201+
202+
Thread.sleep(2000);
203+
204+
testLifecycleObserver.goToBackground();
205+
countly.onStop();
206+
207+
TestUtils.assertRQSize(6);
208+
ModuleUserProfileTests.validateUserProfileRequest(4, 6, TestUtils.map(), TestUtils.map("after_update_session", true));
209+
ModuleSessionsTests.validateSessionEndRequest(5, 2, TestUtils.commonDeviceId);
210+
}
211+
166212
/**
167213
* 1. 200_CNR_A
168214
* Init SDK

0 commit comments

Comments
 (0)