Skip to content

Commit 8ce1a78

Browse files
fix: tests related to orientation
1 parent 78460aa commit 8ce1a78

File tree

6 files changed

+48
-39
lines changed

6 files changed

+48
-39
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public void testOnStop_reallyStopping_emptyEventQueue() {
401401
assertEquals(0, mCountly.getActivityCount());
402402
assertTrue(mCountly.getPrevSessionDurationStartTime() > 0);
403403
verify(requestQueueProvider).endSession(0);
404-
verify(requestQueueProvider, times(0)).recordEvents(anyString());
404+
verify(requestQueueProvider, times(1)).recordEvents(anyString()); // not 0 anymore, it will send orientation event
405405
}
406406

407407
/**
@@ -534,7 +534,7 @@ public void testOnTimer_activeSession_emptyEventQueue() {
534534
mCountly.onTimer();
535535

536536
verify(requestQueueProvider).updateSession(0);
537-
verify(requestQueueProvider, times(0)).recordEvents(anyString());
537+
verify(requestQueueProvider, times(1)).recordEvents(anyString()); // not 0 anymore, it will send orientation event
538538
}
539539

540540
@Test

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import androidx.test.ext.junit.runners.AndroidJUnit4;
44
import java.util.Collections;
5+
import org.json.JSONException;
56
import org.junit.After;
67
import org.junit.Before;
78
import org.junit.Test;
@@ -284,7 +285,7 @@ public void legacyFallbackType_null() {
284285
* -- at this point 9 requests are generated (firs begin, 1 merge, 1 user profile, 1 end session for without merge, 1 begin session for the new user, 1 user profile, 1 user profile, 1 user profile, 1 merge)
285286
*/
286287
@Test
287-
public void sessionDurationScenario_1() throws InterruptedException {
288+
public void sessionDurationScenario_1() throws InterruptedException, JSONException {
288289
CountlyConfig config = TestUtils.createBaseConfig();
289290
config.setRequiresConsent(false);
290291
config.lifecycleObserver = () -> true;
@@ -304,11 +305,12 @@ public void sessionDurationScenario_1() throws InterruptedException {
304305
Thread.sleep(2000);
305306

306307
countly.deviceId().changeWithoutMerge("ff"); // this will generate a request with "end_session", "session_duration" fields and reset duration + begin_session
307-
assertEquals(5, TestUtils.getCurrentRQ().length);
308+
assertEquals(6, TestUtils.getCurrentRQ().length); // not 5 anymore, it will send orientation event as well
308309

309310
TestUtils.validateRequest("ff_merge", TestUtils.map("old_device_id", "1234"), 1);
310-
TestUtils.validateRequest("ff_merge", TestUtils.map("user_details", "{\"custom\":{\"prop2\":123,\"prop1\":\"string\",\"prop3\":false}}"), 2);
311-
ModuleSessionsTests.validateSessionEndRequest(3, 3, "ff_merge");
311+
ModuleEventsTests.validateEventInRQ("ff_merge", "[CLY]_orientation", 1, 0.0d, 0.0d, 2, 0, 1, -1);
312+
TestUtils.validateRequest("ff_merge", TestUtils.map("user_details", "{\"custom\":{\"prop2\":123,\"prop1\":\"string\",\"prop3\":false}}"), 3);
313+
ModuleSessionsTests.validateSessionEndRequest(4, 3, "ff_merge");
312314

313315
Thread.sleep(1000);
314316

@@ -336,13 +338,13 @@ public void sessionDurationScenario_1() throws InterruptedException {
336338

337339
countly.deviceId().changeWithMerge("ff_merge"); // this will generate a request with "session_duration" field and reset duration
338340

339-
assertEquals(9, TestUtils.getCurrentRQ().length);
341+
assertEquals(11, TestUtils.getCurrentRQ().length);
340342

341-
TestUtils.validateRequest("ff", TestUtils.map("user_details", "{\"custom\":{\"prop4\":[\"sd\"]}}"), 5);
342-
TestUtils.validateRequest("ff", TestUtils.map("user_details", "{\"custom\":{}}"), 6);
343-
TestUtils.validateRequest("ff", TestUtils.map("user_details", "{\"custom\":{\"prop2\":456,\"prop1\":\"string_a\",\"prop3\":true}}"), 7);
343+
TestUtils.validateRequest("ff", TestUtils.map("user_details", "{\"custom\":{\"prop4\":[\"sd\"]}}"), 7);
344+
TestUtils.validateRequest("ff", TestUtils.map("user_details", "{\"custom\":{}}"), 8);
345+
TestUtils.validateRequest("ff", TestUtils.map("user_details", "{\"custom\":{\"prop2\":456,\"prop1\":\"string_a\",\"prop3\":true}}"), 9);
344346

345-
TestUtils.validateRequest("ff_merge", TestUtils.map("old_device_id", "ff"), 8);
347+
TestUtils.validateRequest("ff_merge", TestUtils.map("old_device_id", "ff"), 10);
346348

347349
countly.halt();
348350
store.clear();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void manualSessionBeginUpdateEnd() throws InterruptedException {
4444

4545
Thread.sleep(2000);
4646
mCountly.sessions().endSession();
47-
validateSessionEndRequest(2, 2, TestUtils.commonDeviceId);
47+
validateSessionEndRequest(3, 2, TestUtils.commonDeviceId); // not idx 2 anymore, it will send orientation event RQ
4848
}
4949

5050
@Test
@@ -97,7 +97,7 @@ public void automaticSessionBeginEndWithManualDisabled() throws InterruptedExcep
9797

9898
mCountly.onStopInternal();
9999

100-
validateSessionEndRequest(1, 1, TestUtils.commonDeviceId);
100+
validateSessionEndRequest(2, 1, TestUtils.commonDeviceId); // not idx 1 anymore, it will send orientation event RQ
101101
}
102102

103103
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void eventIDScenario_automaticViews() {
7272
verifyRecordEventToEventQueueNotCalled(eqp);
7373

7474
mCountly.onStartInternal(act);
75-
verifyRecordEventToEventQueueIDs(eqp, ModuleViews.VIEW_EVENT_KEY, idV[0], null, "", null, 0, 1);
75+
verifyRecordEventToEventQueueIDs(eqp, ModuleViews.VIEW_EVENT_KEY, idV[0], null, "", null, 1, 2); // not 1 anymore plus orientation
7676

7777
clearInvocations(eqp);
7878

@@ -83,7 +83,7 @@ public void eventIDScenario_automaticViews() {
8383

8484
//custom event 1
8585
mCountly.events().recordEvent(eKeys[0]);
86-
verifyRecordEventToEventQueueIDs(eqp, eKeys[0], idE[0], idV[1], null, "", 0, 1);
86+
verifyRecordEventToEventQueueIDs(eqp, eKeys[0], idE[1], idV[1], null, "", 0, 1);
8787
clearInvocations(eqp);
8888

8989
mCountly.onStopInternal();

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@ public void SE_201_CNR_M() throws InterruptedException {
9797

9898
flowManualSessions(countly);
9999

100-
Assert.assertEquals(4, TestUtils.getCurrentRQ().length);
100+
Assert.assertEquals(5, TestUtils.getCurrentRQ().length);
101101
validateSessionBeginRequest(0, TestUtils.commonDeviceId);
102-
validateSessionUpdateRequest(1, 2, TestUtils.commonDeviceId);
102+
// orientation request 1
103103
validateSessionUpdateRequest(2, 2, TestUtils.commonDeviceId);
104-
validateSessionEndRequest(3, 2, TestUtils.commonDeviceId);
104+
validateSessionUpdateRequest(3, 2, TestUtils.commonDeviceId);
105+
validateSessionEndRequest(4, 2, TestUtils.commonDeviceId);
105106
}
106107

107108
/**
@@ -122,7 +123,7 @@ public void SE_202_CR_CNG_M() throws InterruptedException {
122123

123124
flowManualSessions(countly);
124125

125-
Assert.assertEquals(2, TestUtils.getCurrentRQ().length);
126+
Assert.assertEquals(2, TestUtils.getCurrentRQ().length); // not 2 anymore plus orientation
126127
validateSessionConsentRequest(0, false, TestUtils.commonDeviceId);
127128
validateRequest(TestUtils.map("location", ""), 1);
128129
}
@@ -211,22 +212,26 @@ public void SE_204_CNR_A_id_change() throws InterruptedException {
211212

212213
flowAutomaticSessions(countly);
213214

214-
Assert.assertEquals(12, TestUtils.getCurrentRQ().length);
215+
Assert.assertEquals(16, TestUtils.getCurrentRQ().length);
215216
validateSessionBeginRequest(0, TestUtils.commonDeviceId);
216217
TestUtils.validateRequest("newID", TestUtils.map("old_device_id", TestUtils.commonDeviceId), 1);
217-
validateSessionEndRequest(2, 2, "newID");
218+
// orientation request
219+
validateSessionEndRequest(3, 2, "newID");
218220

219-
validateSessionBeginRequest(3, "newID_2");
220-
TestUtils.validateRequest("newID", TestUtils.map("old_device_id", "newID_2"), 4);
221-
validateSessionEndRequest(5, 2, "newID");
222-
223-
validateSessionBeginRequest(6, "newID_2");
224-
validateSessionEndRequest(7, 1, "newID_2");
221+
validateSessionBeginRequest(4, "newID_2");
222+
TestUtils.validateRequest("newID", TestUtils.map("old_device_id", "newID_2"), 5);
223+
// orientation request
224+
validateSessionEndRequest(7, 2, "newID");
225225

226226
validateSessionBeginRequest(8, "newID_2");
227-
TestUtils.validateRequest("newID", TestUtils.map("old_device_id", "newID_2"), 9);
228-
validateSessionEndRequest(10, null, "newID");
229-
validateSessionBeginRequest(11, "newID");
227+
// orientation request
228+
validateSessionEndRequest(10, 1, "newID_2");
229+
230+
validateSessionBeginRequest(11, "newID_2");
231+
TestUtils.validateRequest("newID", TestUtils.map("old_device_id", "newID_2"), 12);
232+
// orientation request
233+
validateSessionEndRequest(14, null, "newID");
234+
validateSessionBeginRequest(15, "newID");
230235
}
231236

232237
/**

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ public void eventSaveScenario_manualSessions() throws JSONException {
4848
countly.userProfile().setProperty("theme", "dark_mode");
4949

5050
countly.events().recordEvent("test_event1");
51-
TestUtils.assertRQSize(2); // begin session request + user property request with dark_mode
51+
TestUtils.assertRQSize(3); // begin session request + user property request with dark_mode + orientation event
5252
countly.events().recordEvent("test_event2");
5353
countly.events().recordEvent("test_event3");
5454

5555
countly.userProfile().setProperty("theme", "light_mode");
56-
TestUtils.assertRQSize(2); // no request is generated on the way
56+
TestUtils.assertRQSize(3); // no request is generated on the way, not 2 anymore because of orientation event
5757

5858
countly.sessions().endSession();
5959
// begin_session + first user property request + 3 events + user property request with light_mode + end_session
60-
ModuleUserProfileTests.validateUserProfileRequest(1, 5, TestUtils.map(), TestUtils.map("theme", "dark_mode"));
61-
ModuleUserProfileTests.validateUserProfileRequest(3, 5, TestUtils.map(), TestUtils.map("theme", "light_mode"));
60+
ModuleUserProfileTests.validateUserProfileRequest(1, 6, TestUtils.map(), TestUtils.map("theme", "dark_mode"));
61+
ModuleUserProfileTests.validateUserProfileRequest(3, 6, TestUtils.map(), TestUtils.map("theme", "light_mode"));
6262
}
6363

6464
/**
@@ -325,8 +325,9 @@ public void UP_207_CNR_M() throws JSONException {
325325
TestUtils.assertRQSize(8);
326326
ModuleSessionsTests.validateSessionBeginRequest(0, TestUtils.commonDeviceId);
327327

328-
ModuleEventsTests.validateEventInRQ("A", 1, 0, 2);
329-
ModuleEventsTests.validateEventInRQ("B", 1, 1, 2);
328+
ModuleEventsTests.validateEventInRQ("[CLY]_orientation", 1, 0, 3);
329+
ModuleEventsTests.validateEventInRQ("A", 1, 1, 3); // not 2 anymore because of orientation, 0 is orientation
330+
ModuleEventsTests.validateEventInRQ("B", 1, 2, 3);
330331

331332
ModuleUserProfileTests.validateUserProfileRequest(2, 8, TestUtils.map(), TestUtils.map("a12345", "4"));
332333

@@ -378,8 +379,9 @@ public void UP_208_CR_CG_M() throws JSONException {
378379
ModuleConsentTests.validateAllConsentRequest(TestUtils.commonDeviceId, 0);
379380
ModuleSessionsTests.validateSessionBeginRequest(1, TestUtils.commonDeviceId);
380381

381-
ModuleEventsTests.validateEventInRQ("A", 2, 0, 2);
382-
ModuleEventsTests.validateEventInRQ("B", 2, 1, 2);
382+
ModuleEventsTests.validateEventInRQ("[CLY]_orientation", 2, 0, 3);
383+
ModuleEventsTests.validateEventInRQ("A", 2, 1, 3); // not 2 anymore because of orientation
384+
ModuleEventsTests.validateEventInRQ("B", 2, 2, 3); // not 2 anymore because of orientation
383385

384386
ModuleUserProfileTests.validateUserProfileRequest(3, 9, TestUtils.map(), TestUtils.map("a12345", "4"));
385387

@@ -435,7 +437,7 @@ public void UP_210_CNR_M_duration() throws InterruptedException, JSONException {
435437
sendUserData(countly);
436438
Thread.sleep(6000);
437439

438-
validateUserDataRequest(0, 1, "My Property", TestUtils.commonDeviceId);
440+
validateUserDataRequest(1, 2, "My Property", TestUtils.commonDeviceId); // plus orientation
439441
}
440442

441443
private void sendUserProperties(Countly countly) {

0 commit comments

Comments
 (0)