@@ -77,9 +77,13 @@ - (void)testIndirectNotificationToIndirectInfluenceMigration {
7777 NSMutableArray *indirectNotifications = [NSMutableArray new ];
7878 [indirectNotifications addObject: indirectNotification];
7979
80+ [NSKeyedArchiver setClassName: @" OSIndirectNotification" forClass: [OSIndirectNotification class ]];
8081 [dataRepository saveNotifications: indirectNotifications];
81- NSArray *lastNotificationReceived = [dataRepository lastNotificationsReceivedData ];
82+ [NSKeyedUnarchiver setClass: [OSIndirectNotification class ] forClassName: @" OSIndirectNotification" ];
83+ NSArray <OSIndirectNotification *> *lastNotificationReceived = [dataRepository lastNotificationsReceivedData ];
84+ OSIndirectNotification *lastIndirectNotificationReceived = [lastNotificationReceived objectAtIndex: 0 ];
8285 NSInteger sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey: OSUD_CACHED_SDK_VERSION defaultValue: 0 ];
86+ XCTAssertTrue ([lastIndirectNotificationReceived.notificationId isEqualToString: notificationId]);
8387 XCTAssertEqual (1 , [lastNotificationReceived count ]);
8488 XCTAssertEqual (0 , sdkVersion);
8589
@@ -125,6 +129,42 @@ - (void)testIndirectInfluenceToIndirectInfluenceMigration {
125129 XCTAssertEqual ([[OneSignal sdk_version_raw ] intValue ], sdkVersionAfterMigration);
126130}
127131
132+ - (void )testIndirectNotificationToIndirectInfluenceMigration_NotificationServiceExtensionHandler {
133+ NSString *notificationId = @" 1234-5678-1234-5678-1234" ;
134+ double timestamp = 10 ;
135+ OSIndirectNotification *indirectNotification = [[OSIndirectNotification alloc ] initWithParamsNotificationId: notificationId timestamp: timestamp];
136+ NSMutableArray *indirectNotifications = [NSMutableArray new ];
137+ [indirectNotifications addObject: indirectNotification];
138+
139+ [NSKeyedArchiver setClassName: @" OSIndirectNotification" forClass: [OSIndirectNotification class ]];
140+ [dataRepository saveNotifications: indirectNotifications];
141+ [NSKeyedUnarchiver setClass: [OSIndirectNotification class ] forClassName: @" OSIndirectNotification" ];
142+ NSArray <OSIndirectNotification *> *lastNotificationReceived = [dataRepository lastNotificationsReceivedData ];
143+ OSIndirectNotification *lastIndirectNotificationReceived = [lastNotificationReceived objectAtIndex: 0 ];
144+ NSInteger sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey: OSUD_CACHED_SDK_VERSION defaultValue: 0 ];
145+ XCTAssertTrue ([lastIndirectNotificationReceived.notificationId isEqualToString: notificationId]);
146+ XCTAssertEqual (1 , [lastNotificationReceived count ]);
147+ XCTAssertEqual (0 , sdkVersion);
148+
149+ // Receive notification
150+ [UnitTestCommonMethods receiveNotification: @" test_notification_1" wasOpened: NO ];
151+
152+ NSArray <OSIndirectInfluence *> *lastNotificationReceivedAfterMigration = [dataRepository lastNotificationsReceivedData ];
153+ XCTAssertEqual (2 , [lastNotificationReceivedAfterMigration count ]);
154+
155+ OSIndirectInfluence *indirectInfluenceMigrated = [lastNotificationReceivedAfterMigration objectAtIndex: 0 ];
156+ XCTAssertTrue ([indirectInfluenceMigrated.influenceId isEqualToString: notificationId]);
157+ XCTAssertTrue ([indirectInfluenceMigrated.channelIdTag isEqualToString: @" notification_id" ]);
158+ XCTAssertEqual (timestamp, indirectInfluenceMigrated.timestamp );
159+
160+ OSIndirectInfluence *indirectInfluenceReceived = [lastNotificationReceivedAfterMigration objectAtIndex: 1 ];
161+ XCTAssertTrue ([indirectInfluenceReceived.influenceId isEqualToString: @" test_notification_1" ]);
162+ XCTAssertTrue ([indirectInfluenceReceived.channelIdTag isEqualToString: @" notification_id" ]);
163+
164+ NSInteger sdkVersionAfterMigration = [OneSignalUserDefaults.initShared getSavedIntegerForKey: OSUD_CACHED_SDK_VERSION defaultValue: 0 ];
165+ XCTAssertEqual ([[OneSignal sdk_version_raw ] intValue ], sdkVersionAfterMigration);
166+ }
167+
128168- (void )testNoAttributedUniqueOutcomeDataAvailableToMigrate {
129169 NSArray *uniqueOutcomes = [outcomesCache getAttributedUniqueOutcomeEventSent ];
130170 NSInteger sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey: OSUD_CACHED_SDK_VERSION defaultValue: 0 ];
0 commit comments