mirror of
https://github.com/block/buzz.git
synced 2026-11-01 06:51:17 +00:00
78 lines
1.9 KiB
Swift
78 lines
1.9 KiB
Swift
import Foundation
|
|
import Testing
|
|
|
|
@testable import BuzzPushKit
|
|
|
|
@Test func `Round-trip opaque navigation target through notification user info`() {
|
|
let target = BuzzPushNavigationTarget(
|
|
eventID: "MESSAGE-ID",
|
|
communityID: "community-id",
|
|
channelID: "CHANNEL/GENERAL"
|
|
)
|
|
|
|
#expect(
|
|
BuzzPushNavigationTarget.decodeIfPresent(
|
|
from: [BuzzPushNavigationTarget.userInfoKey: target.userInfoValue]
|
|
) == target
|
|
)
|
|
#expect(target.eventID == "MESSAGE-ID")
|
|
#expect(target.channelID == "CHANNEL/GENERAL")
|
|
}
|
|
|
|
@Test func `Reject incomplete or malformed navigation target`() {
|
|
#expect(
|
|
BuzzPushNavigationTarget.decodeIfPresent(
|
|
from: [
|
|
BuzzPushNavigationTarget.userInfoKey: [
|
|
"event_id": "message-id",
|
|
"community_id": "community-id",
|
|
]
|
|
]
|
|
) == nil
|
|
)
|
|
|
|
#expect(
|
|
BuzzPushNavigationTarget.decodeIfPresent(
|
|
from: [
|
|
BuzzPushNavigationTarget.userInfoKey: [
|
|
"event_id": "",
|
|
"community_id": "community-id",
|
|
"channel_id": "channel-id",
|
|
]
|
|
]
|
|
) == nil
|
|
)
|
|
|
|
#expect(
|
|
BuzzPushNavigationTarget.decodeIfPresent(
|
|
from: [
|
|
BuzzPushNavigationTarget.userInfoKey: [
|
|
"event_id": "message-id",
|
|
"community_id": "community-id",
|
|
"channel_id": "",
|
|
]
|
|
]
|
|
) == nil
|
|
)
|
|
}
|
|
|
|
@Test func `Buffer preserves cold-start target until consumed`() {
|
|
let first = BuzzPushNavigationTarget(
|
|
eventID: String(repeating: "a", count: 64),
|
|
communityID: "community-id",
|
|
channelID: "123e4567-e89b-42d3-a456-426614174000"
|
|
)
|
|
let second = BuzzPushNavigationTarget(
|
|
eventID: String(repeating: "b", count: 64),
|
|
communityID: "community-id",
|
|
channelID: "123e4567-e89b-42d3-a456-426614174000"
|
|
)
|
|
let buffer = BuzzPushNavigationBuffer()
|
|
|
|
buffer.record(first)
|
|
buffer.remove(ifMatching: second)
|
|
#expect(buffer.peek() == first)
|
|
#expect(buffer.take() == first)
|
|
#expect(buffer.take() == nil)
|
|
}
|