@@ -173,9 +173,9 @@ final class OSLiveActivitiesExecutorTests: XCTestCase {
173173 mockDispatchQueue. waitForDispatches ( 2 )
174174
175175 /* Then */
176- // Forgotten from the cache, but its notificationId is remembered so it isn't reported again.
177- XCTAssertEqual ( executor. receiveReceipts. items. count, 0 )
178- XCTAssertTrue ( executor. confirmedReceiptIds . contains ( " notification-id " ) )
176+ // The sent receipt is kept as a dedup marker so the same notificationId isn't reported again.
177+ XCTAssertEqual ( executor. receiveReceipts. items. count, 1 )
178+ XCTAssertTrue ( executor. receiveReceipts . items [ " notification-id " ] ? . requestSuccessful ?? false )
179179 XCTAssertEqual ( mockClient. executedRequests. count, 1 )
180180 XCTAssertTrue ( mockClient. executedRequests [ 0 ] == request)
181181 }
@@ -517,21 +517,19 @@ final class OSLiveActivitiesExecutorTests: XCTestCase {
517517 mockDispatchQueue. waitForDispatches ( 3 )
518518
519519 /* Then */
520- // request2 is suppressed as a duplicate of request1; the sent receipt is then forgotten .
521- XCTAssertEqual ( executor. receiveReceipts. items. count, 0 )
520+ // request2 is suppressed as a duplicate of request1, which is kept as a dedup marker .
521+ XCTAssertEqual ( executor. receiveReceipts. items. count, 1 )
522522 XCTAssertEqual ( mockClient. executedRequests. count, 1 )
523523 XCTAssertTrue ( mockClient. executedRequests [ 0 ] == request1)
524524 }
525525
526526 /**
527- A receive-receipt for a notificationId must be sent at most once per device. This covers the
528- cross-cycle case: unlike `testReceiveReceiptsRequestNotExecutedWithSameNotificationId` (both receipts
529- appended in one cycle), here the first fully completes and is forgotten before the second arrives, so
530- the duplicate is caught by the remembered notificationIds rather than by the request cache.
527+ A receive receipt must be sent at most once per device, even across app launches. The second executor
528+ reloads the persisted cache with in-memory state gone, simulating a relaunch where ActivityKit re-emits
529+ the active activity's current content and the same notificationId is reported again.
531530 */
532- func testReceiveReceiptsNotResentForSameNotificationIdAcrossDeliveryCycles ( ) throws {
531+ func testReceiveReceiptsNotResentForSameNotificationIdAfterRelaunch ( ) throws {
533532 /* Setup */
534- let mockDispatchQueue = MockDispatchQueue ( )
535533 let mockClient = MockOneSignalClient ( )
536534 OneSignalCoreImpl . setSharedClient ( mockClient)
537535 OneSignalUserDefaults . initShared ( ) . saveString ( forKey: OSUD_LEGACY_PLAYER_ID, withValue: " my-subscription-id " )
@@ -546,21 +544,21 @@ final class OSLiveActivitiesExecutorTests: XCTestCase {
546544 mockClient. setMockResponseForRequest ( request: String ( describing: request2) , response: [ String: Any] ( ) )
547545
548546 /* When */
549- let executor = OSLiveActivitiesExecutor ( requestDispatch : mockDispatchQueue )
550-
551- // First cycle: receipt is sent, succeeds, is forgotten, and its notificationId is remembered.
552- executor . append ( request1)
553- mockDispatchQueue . waitForDispatches ( 2 )
547+ // First launch: the receipt is sent and succeeds.
548+ let firstLaunch = MockDispatchQueue ( )
549+ let executor1 = OSLiveActivitiesExecutor ( requestDispatch : firstLaunch )
550+ executor1 . append ( request1)
551+ firstLaunch . waitForDispatches ( 2 )
554552 XCTAssertEqual ( mockClient. executedRequests. count, 1 )
555- XCTAssertEqual ( executor. receiveReceipts. items. count, 0 )
556- XCTAssertTrue ( executor. confirmedReceiptIds. contains ( " my-notification-id " ) )
557553
558- // Second cycle, same notificationId (e.g. another content update / relaunch): a duplicate.
559- executor. append ( request2)
560- mockDispatchQueue. waitForDispatches ( 3 )
554+ // Relaunch: a fresh executor reloads the persisted cache; ActivityKit re-emits the same content.
555+ let secondLaunch = MockDispatchQueue ( )
556+ let executor2 = OSLiveActivitiesExecutor ( requestDispatch: secondLaunch)
557+ executor2. append ( request2)
558+ secondLaunch. waitForDispatches ( 1 )
561559
562560 /* Then */
563- XCTAssertEqual ( mockClient. executedRequests. count, 1 , " Duplicate receive- receipt must not be sent for the same notificationId across delivery cycles " )
561+ XCTAssertEqual ( mockClient. executedRequests. count, 1 , " Receive receipt must not be re- sent for the same notificationId after relaunch " )
564562 XCTAssertTrue ( mockClient. executedRequests [ 0 ] == request1)
565563 }
566564}
0 commit comments