@@ -293,8 +293,34 @@ class NotificationStoreTests: XCTestCase {
293293 wait ( for: [ expectation] , timeout: Constants . expectationTimeout)
294294 }
295295
296+ /// Verifies that `NotificationAction.updateReadStatus` effectively invalidates the note's hash on error.
297+ ///
298+ func testMarkAsReadInvalidatesTheNotificationHashOnError( ) {
299+ let expectation = self . expectation ( description: " Update read status success response " )
300+ let noteStore = NotificationStore ( dispatcher: dispatcher, storageManager: storageManager, network: network)
301+ let originalNote = sampleNotification ( )
296302
297- // MARK: - NotificationAction.updateReadStatus
303+ network. simulateResponse ( requestUrlSuffix: " notifications/read " , filename: " generic_error " )
304+ let action = NotificationAction . updateReadStatus ( noteId: originalNote. noteId, read: true ) { [ weak self] ( error) in
305+ XCTAssertNotNil ( error)
306+
307+ let storageNote = self ? . viewStorage. loadNotification ( noteID: originalNote. noteId)
308+ XCTAssertEqual ( storageNote? . toReadOnly ( ) . hash, Int64 . min)
309+
310+ expectation. fulfill ( )
311+ }
312+
313+ XCTAssertEqual ( viewStorage. countObjects ( ofType: Storage . Note. self) , 0 )
314+ noteStore. updateLocalNotes ( with: [ originalNote] ) { [ weak self] in
315+ XCTAssertEqual ( self ? . viewStorage. countObjects ( ofType: Storage . Note. self) , 1 )
316+ noteStore. onAction ( action)
317+ }
318+
319+ wait ( for: [ expectation] , timeout: Constants . expectationTimeout)
320+ }
321+
322+
323+ // MARK: - NotificationAction.updateMultipleReadStatus
298324
299325 /// Verifies that NotificationAction.updateMultipleReadStatus handles a success response from the backend properly
300326 ///
@@ -322,7 +348,6 @@ class NotificationStoreTests: XCTestCase {
322348
323349 wait ( for: [ expectation] , timeout: Constants . expectationTimeout)
324350 }
325-
326351}
327352
328353
0 commit comments