@@ -58,24 +58,25 @@ class LocalNotificationCacheTests: XCTestCase {
5858 )
5959 }
6060
61- func makeNotificaction( id: String , title: String ) -> V3Notification {
61+ func makeNotificaction( id: String , title: String , updatedAt : Date ) -> V3Notification {
6262 return V3Notification (
6363 id: id,
6464 lastReadAt: nil ,
6565 reason: . assign,
6666 repository: makeRepo ( ) ,
6767 subject: V3NotificationSubject ( title: title, type: . issue, url: nil ) ,
6868 unread: true ,
69- updatedAt: Date ( )
69+ updatedAt: updatedAt
7070 )
7171 }
7272
7373 func test_whenUpdating_thatReadFirstTime_thenSecondCallEmpty( ) {
7474 clear ( for: #function)
7575
7676 let cache = LocalNotificationsCache ( path: path ( for: #function) )
77+ let date = Date ( )
7778 let n1 = [
78- makeNotificaction ( id: " 123 " , title: " foo " )
79+ makeNotificaction ( id: " 123 " , title: " foo " , updatedAt : date )
7980 ]
8081 var executions = 0
8182
@@ -85,17 +86,17 @@ class LocalNotificationCacheTests: XCTestCase {
8586 }
8687
8788 let n2 = [
88- makeNotificaction ( id: " 123 " , title: " foo " ) ,
89- makeNotificaction ( id: " 456 " , title: " bar " )
89+ makeNotificaction ( id: " 123 " , title: " foo " , updatedAt : date ) ,
90+ makeNotificaction ( id: " 456 " , title: " bar " , updatedAt : date )
9091 ]
9192 cache. update ( notifications: n2) { results in
9293 executions += 1
9394 XCTAssertEqual ( results. count, 1 )
9495 }
9596
9697 let n3 = [
97- makeNotificaction ( id: " 123 " , title: " foo " ) ,
98- makeNotificaction ( id: " 456 " , title: " bar " )
98+ makeNotificaction ( id: " 123 " , title: " foo " , updatedAt : date ) ,
99+ makeNotificaction ( id: " 456 " , title: " bar " , updatedAt : date )
99100 ]
100101
101102 cache. update ( notifications: n3) { results in
@@ -105,5 +106,30 @@ class LocalNotificationCacheTests: XCTestCase {
105106
106107 XCTAssertEqual ( executions, 3 )
107108 }
109+
110+ func test_whenUpdatingWithSameNotificationWithUpdatedTime_thatNotificationReceived( ) {
111+ clear ( for: #function)
112+
113+ let cache = LocalNotificationsCache ( path: path ( for: #function) )
114+ let n1 = [
115+ makeNotificaction ( id: " 123 " , title: " foo " , updatedAt: Date ( ) )
116+ ]
117+
118+ cache. update ( notifications: n1) { results in
119+ XCTAssertEqual ( results. count, 1 )
120+ }
121+
122+ cache. update ( notifications: n1) { results in
123+ XCTAssertEqual ( results. count, 0 )
124+ }
125+
126+ let n2 = [
127+ makeNotificaction ( id: " 123 " , title: " foo " , updatedAt: Date ( timeIntervalSinceNow: 10 ) )
128+ ]
129+
130+ cache. update ( notifications: n2) { results in
131+ XCTAssertEqual ( results. count, 1 )
132+ }
133+ }
108134
109135}
0 commit comments