import Foundation import Testing @testable import gitbay @Test func payloadDecodesTheAccountAndPath() throws { let userInfo: [AnyHashable: Any] = [ "aps": ["alert": ["title": "krz/gitbay", "body": "cmc opened issue #12"], "badge": 3], "instance": "https://gitbay.org", "user": "cmc", "path": "krz/gitbay/issues/12", ] let payload = try #require(PushPayload(userInfo: userInfo)) #expect(payload.instance == URL(string: "https://gitbay.org")) #expect(payload.user == "cmc") #expect(payload.path == "krz/gitbay/issues/12") #expect(payload.badge == 3) } @Test func payloadTreatsAMissingBadgeAsZero() throws { let userInfo: [AnyHashable: Any] = [ "aps": ["alert": ["title": "t", "body": "b"]], "instance": "https://gitbay.org", "user": "cmc", "path": "a/b/issues/1", ] let payload = try #require(PushPayload(userInfo: userInfo)) #expect(payload.badge == 0) } // A payload from a server that predates the account fields, or one // mangled in transit, is dropped rather than guessed at. @Test func payloadRejectsAnIncompleteNotification() { #expect(PushPayload(userInfo: ["aps": ["alert": "x"], "path": "a/b/issues/1"]) == nil) #expect(PushPayload(userInfo: ["instance": "https://gitbay.org", "user": "cmc"]) == nil) #expect(PushPayload(userInfo: ["instance": "not a url at all", "user": "cmc", "path": "a/b/issues/1"]) == nil) }