@@ -1124,4 +1124,170 @@ - (void)testAttributedIndirectSession_sendsUniqueOutcomeForNewNIAMs_andNotCached
11241124 }];
11251125 [RestClientAsserts assertNumberOfMeasureSourcesRequests: 2 ];
11261126}
1127+
1128+
1129+ - (void )testUnattributedSessionToDirectSessionWhileInactive {
1130+ // 1. Open app
1131+ [UnitTestCommonMethods initOneSignalAndThreadWait ];
1132+
1133+ [[OneSignal outcomeEventsCache ] saveOutcomesV2ServiceEnabled: YES ];
1134+
1135+ // 2. Make sure IN_APP_MESSAGE influence is UNATTRIBUTED and Notifications is UNATTRIBUTED
1136+ NSArray <OSInfluence *> *sessionInfluences = [OneSignal.sessionManager getInfluences ];
1137+ for (OSInfluence *influence in sessionInfluences) {
1138+ switch (influence.influenceChannel ) {
1139+ case IN_APP_MESSAGE:
1140+ XCTAssertEqual (influence.influenceType , UNATTRIBUTED);
1141+ XCTAssertEqual (influence.ids , nil );
1142+ break ;
1143+ case NOTIFICATION:
1144+ XCTAssertEqual (influence.influenceType , UNATTRIBUTED);
1145+ XCTAssertEqual (influence.ids , nil );
1146+ break ;
1147+ }
1148+ }
1149+
1150+ // Make app inactive. This actually involves backgrounding foregroudning backgrounding and then inactive.
1151+ [UnitTestCommonMethods pullDownNotificationCenter ];
1152+
1153+ // 3. Receive 1 notification and open it
1154+ [UnitTestCommonMethods receiveNotification: @" test_notification_1" wasOpened: YES ];
1155+
1156+ // 4. Open app
1157+ [UnitTestCommonMethods initOneSignalAndThreadWait ];
1158+
1159+ // 5. Make sure IN_APP_MESSAGE influence is UNATTRIBUTED and Notifications is direct
1160+ sessionInfluences = [OneSignal.sessionManager getInfluences ];
1161+ for (OSInfluence *influence in sessionInfluences) {
1162+ switch (influence.influenceChannel ) {
1163+ case IN_APP_MESSAGE:
1164+ XCTAssertEqual (influence.influenceType , UNATTRIBUTED);
1165+ XCTAssertEqual (influence.ids , nil );
1166+ break ;
1167+ case NOTIFICATION:
1168+ XCTAssertEqual (influence.influenceType , DIRECT);
1169+ XCTAssertEqual (influence.ids .count , 1 );
1170+ [CommonAsserts assertArrayEqualsWithExpected: influence.ids actual: @[@" test_notification_1" ]];
1171+ break ;
1172+ }
1173+ }
1174+ }
1175+
1176+ - (void )testDirectSessionToDirectSessionWhileInactive {
1177+ // 1. Open app
1178+ [UnitTestCommonMethods initOneSignalAndThreadWait ];
1179+ [[OneSignal outcomeEventsCache ] saveOutcomesV2ServiceEnabled: YES ];
1180+
1181+ [UnitTestCommonMethods pullDownNotificationCenter ];
1182+
1183+ // 2. Make sure IN_APP_MESSAGE influence is UNATTRIBUTED and Notifications is UNATTRIBUTED
1184+ NSArray <OSInfluence *> *sessionInfluences = [OneSignal.sessionManager getInfluences ];
1185+
1186+ // 3. Receive notification 1 and open it
1187+ [UnitTestCommonMethods receiveNotification: @" test_notification_1" wasOpened: YES ];
1188+
1189+ // 4. Open app
1190+ [UnitTestCommonMethods initOneSignalAndThreadWait ];
1191+
1192+ // 5. Make sure IN_APP_MESSAGE influence is UNATTRIBUTED and Notifications is direct
1193+ sessionInfluences = [OneSignal.sessionManager getInfluences ];
1194+ for (OSInfluence *influence in sessionInfluences) {
1195+ switch (influence.influenceChannel ) {
1196+ case IN_APP_MESSAGE:
1197+ XCTAssertEqual (influence.influenceType , UNATTRIBUTED);
1198+ XCTAssertEqual (influence.ids , nil );
1199+ break ;
1200+ case NOTIFICATION:
1201+ XCTAssertEqual (influence.influenceType , DIRECT);
1202+ XCTAssertEqual (influence.ids .count , 1 );
1203+ [CommonAsserts assertArrayEqualsWithExpected: influence.ids actual: @[@" test_notification_1" ]];
1204+ break ;
1205+ }
1206+ }
1207+
1208+ // Make app inactive. This actually involves backgrounding foregroudning backgrounding and then inactive.
1209+ [UnitTestCommonMethods pullDownNotificationCenter ];
1210+
1211+ // 6. Receive notification 2 and open it
1212+ [UnitTestCommonMethods receiveNotification: @" test_notification_2" wasOpened: YES ];
1213+
1214+ // 7. Open app
1215+ [UnitTestCommonMethods initOneSignalAndThreadWait ];
1216+
1217+ // 8. Make sure IN_APP_MESSAGE influence is UNATTRIBUTED and Notifications is direct
1218+ sessionInfluences = [OneSignal.sessionManager getInfluences ];
1219+ for (OSInfluence *influence in sessionInfluences) {
1220+ switch (influence.influenceChannel ) {
1221+ case IN_APP_MESSAGE:
1222+ XCTAssertEqual (influence.influenceType , UNATTRIBUTED);
1223+ XCTAssertEqual (influence.ids , nil );
1224+ break ;
1225+ case NOTIFICATION:
1226+ XCTAssertEqual (influence.influenceType , DIRECT);
1227+ XCTAssertEqual (influence.ids .count , 1 );
1228+ [CommonAsserts assertArrayEqualsWithExpected: influence.ids actual: @[@" test_notification_2" ]];
1229+ break ;
1230+ }
1231+ }
1232+ }
1233+
1234+ - (void )testIndirectSessionToDirectSessionWhileInactive {
1235+ // 1. Open app
1236+ [UnitTestCommonMethods initOneSignalAndThreadWait ];
1237+ [[OneSignal outcomeEventsCache ] saveOutcomesV2ServiceEnabled: YES ];
1238+
1239+ // Background app
1240+ [UnitTestCommonMethods backgroundApp ];
1241+
1242+ // 2. Make sure IN_APP_MESSAGE influence is UNATTRIBUTED and Notifications is UNATTRIBUTED
1243+ NSArray <OSInfluence *> *sessionInfluences = [OneSignal.sessionManager getInfluences ];
1244+
1245+ // 3. Receive notification 1 and open it
1246+ [UnitTestCommonMethods receiveNotification: @" test_notification_1" wasOpened: NO ];
1247+
1248+ // 4. Open app
1249+ [UnitTestCommonMethods initOneSignalAndThreadWait ];
1250+
1251+ // 5. Make sure IN_APP_MESSAGE influence is UNATTRIBUTED and Notifications is INDIRECT
1252+ sessionInfluences = [OneSignal.sessionManager getInfluences ];
1253+ for (OSInfluence *influence in sessionInfluences) {
1254+ switch (influence.influenceChannel ) {
1255+ case IN_APP_MESSAGE:
1256+ XCTAssertEqual (influence.influenceType , UNATTRIBUTED);
1257+ XCTAssertEqual (influence.ids , nil );
1258+ break ;
1259+ case NOTIFICATION:
1260+ XCTAssertEqual (influence.influenceType , INDIRECT);
1261+ XCTAssertEqual (influence.ids .count , 1 );
1262+ [CommonAsserts assertArrayEqualsWithExpected: influence.ids actual: @[@" test_notification_1" ]];
1263+ break ;
1264+ }
1265+ }
1266+
1267+ // Make app inactive. This actually involves backgrounding foregroudning backgrounding and then inactive.
1268+ [UnitTestCommonMethods pullDownNotificationCenter ];
1269+
1270+ // 6. Receive notification 2 and open it
1271+ [UnitTestCommonMethods receiveNotification: @" test_notification_2" wasOpened: YES ];
1272+
1273+ // 7. Open app
1274+ [UnitTestCommonMethods initOneSignalAndThreadWait ];
1275+
1276+ // 8. Make sure IN_APP_MESSAGE influence is UNATTRIBUTED and Notifications is direct
1277+ sessionInfluences = [OneSignal.sessionManager getInfluences ];
1278+ for (OSInfluence *influence in sessionInfluences) {
1279+ switch (influence.influenceChannel ) {
1280+ case IN_APP_MESSAGE:
1281+ XCTAssertEqual (influence.influenceType , UNATTRIBUTED);
1282+ XCTAssertEqual (influence.ids , nil );
1283+ break ;
1284+ case NOTIFICATION:
1285+ XCTAssertEqual (influence.influenceType , DIRECT);
1286+ XCTAssertEqual (influence.ids .count , 1 );
1287+ [CommonAsserts assertArrayEqualsWithExpected: influence.ids actual: @[@" test_notification_2" ]];
1288+ break ;
1289+ }
1290+ }
1291+ }
1292+
11271293@end
0 commit comments