@@ -58,24 +58,25 @@ class LocalNotificationCacheTests: XCTestCase {
58
58
)
59
59
}
60
60
61
- func makeNotificaction( id: String , title: String ) -> V3Notification {
61
+ func makeNotificaction( id: String , title: String , updatedAt : Date ) -> V3Notification {
62
62
return V3Notification (
63
63
id: id,
64
64
lastReadAt: nil ,
65
65
reason: . assign,
66
66
repository: makeRepo ( ) ,
67
67
subject: V3NotificationSubject ( title: title, type: . issue, url: nil ) ,
68
68
unread: true ,
69
- updatedAt: Date ( )
69
+ updatedAt: updatedAt
70
70
)
71
71
}
72
72
73
73
func test_whenUpdating_thatReadFirstTime_thenSecondCallEmpty( ) {
74
74
clear ( for: #function)
75
75
76
76
let cache = LocalNotificationsCache ( path: path ( for: #function) )
77
+ let date = Date ( )
77
78
let n1 = [
78
- makeNotificaction ( id: " 123 " , title: " foo " )
79
+ makeNotificaction ( id: " 123 " , title: " foo " , updatedAt : date )
79
80
]
80
81
var executions = 0
81
82
@@ -85,17 +86,17 @@ class LocalNotificationCacheTests: XCTestCase {
85
86
}
86
87
87
88
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 )
90
91
]
91
92
cache. update ( notifications: n2) { results in
92
93
executions += 1
93
94
XCTAssertEqual ( results. count, 1 )
94
95
}
95
96
96
97
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 )
99
100
]
100
101
101
102
cache. update ( notifications: n3) { results in
@@ -105,5 +106,30 @@ class LocalNotificationCacheTests: XCTestCase {
105
106
106
107
XCTAssertEqual ( executions, 3 )
107
108
}
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
+ }
108
134
109
135
}
0 commit comments