Skip to content

Commit e8d0419

Browse files
Added complete coverage for VAPID Configurations
1 parent e010062 commit e8d0419

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

Tests/WebPushTests/VAPIDConfigurationTests.swift

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,54 @@ struct VAPIDConfigurationTests {
260260
"""
261261
)
262262
}
263+
264+
@Test func decodesIncompleteConfiguration() throws {
265+
#expect(
266+
try JSONDecoder().decode(VAPID.Configuration.self, from: Data(
267+
"""
268+
{
269+
"contactInformation" : "mailto:test@example.com",
270+
"expirationDuration" : 79200,
271+
"primaryKey" : "FniTgSrf0l+BdfeC6LiblKXBbY4LQm0S+4STNCoJI+0=",
272+
"validityDuration" : 72000
273+
}
274+
""".utf8
275+
)) ==
276+
VAPID.Configuration(
277+
key: key1,
278+
contactInformation: .email("test@example.com")
279+
)
280+
)
281+
}
282+
283+
@Test func decodesWholeConfiguration() throws {
284+
#expect(
285+
try JSONDecoder().decode(VAPID.Configuration.self, from: Data(
286+
"""
287+
{
288+
"contactInformation" : "mailto:test@example.com",
289+
"deprecatedKeys" : [
290+
"bcZgo/p2WFqXaKFzmYaDKO/gARjWvGi3oXyHM2QNlfE="
291+
],
292+
"expirationDuration" : 3600,
293+
"keys" : [
294+
"wyQaGWNwvXKzVmPIhkqVQvQ+FKx1SNqHJ+re8n2ORrk="
295+
],
296+
"primaryKey" : "FniTgSrf0l+BdfeC6LiblKXBbY4LQm0S+4STNCoJI+0=",
297+
"validityDuration" : 36000
298+
}
299+
""".utf8
300+
)) ==
301+
VAPID.Configuration(
302+
primaryKey: key1,
303+
keys: [key2],
304+
deprecatedKeys: [key1, key2, key3],
305+
contactInformation: .email("test@example.com"),
306+
expirationDuration: .hours(1),
307+
validityDuration: .hours(10)
308+
)
309+
)
310+
}
263311
}
264312

265313
@Suite
@@ -303,6 +351,11 @@ struct VAPIDConfigurationTests {
303351
#expect(VAPID.Configuration.Duration.seconds(175) > VAPID.Configuration.Duration.minutes(2))
304352
}
305353

354+
@Test func addingToDates() {
355+
let now = Date()
356+
#expect(now.adding(.seconds(5)) == now.addingTimeInterval(5))
357+
}
358+
306359
@Test func coding() throws {
307360
#expect(String(decoding: try JSONEncoder().encode(VAPID.Configuration.Duration(60)), as: UTF8.self) == "60")
308361

0 commit comments

Comments
 (0)