mirror of
https://github.com/block/buzz.git
synced 2026-11-25 10:42:26 +00:00
Co-authored-by: npub1tquskdu6yc4h8l7xxtceculxw600grekeq0xg2ukqfrwl7vrzg3quz3gmp <58390b379a262b73ffc632f19c73e6769ef40f36c81e642b960246eff9831222@buzz.block.builderlab.xyz> Signed-off-by: npub1tquskdu6yc4h8l7xxtceculxw600grekeq0xg2ukqfrwl7vrzg3quz3gmp <58390b379a262b73ffc632f19c73e6769ef40f36c81e642b960246eff9831222@buzz.block.builderlab.xyz>
81 lines
2.5 KiB
Swift
81 lines
2.5 KiB
Swift
import XCTest
|
|
|
|
@testable import BuzzPushKit
|
|
|
|
final class PushNotificationIdentityTests: XCTestCase {
|
|
private let identity = PushNotificationIdentity(eventID: "EVENT", origin: "origin")
|
|
|
|
func testSequentialDuplicateRemovalStopsStackGrowthButDuplicateWakeCanStillAlertBeforeOlderCopyIsRemoved() throws {
|
|
let requestIdentifiers = try PushDuplicateAbsorption.requestIdentifiersToRemove(
|
|
matching: identity,
|
|
from: [
|
|
PushDeliveredNotificationRecord(
|
|
requestIdentifier: "older-request",
|
|
userInfo: [PushNotificationIdentity.userInfoKey: identity.userInfoValue]
|
|
)
|
|
]
|
|
)
|
|
|
|
XCTAssertEqual(requestIdentifiers, ["older-request"])
|
|
}
|
|
|
|
func testConcurrentNSEInvocationsCanEachMissTheOthersDeliveredNotificationAndBothLeaveACopy() throws {
|
|
let firstObserved = try PushDuplicateAbsorption.requestIdentifiersToRemove(
|
|
matching: identity,
|
|
from: []
|
|
)
|
|
let secondObserved = try PushDuplicateAbsorption.requestIdentifiersToRemove(
|
|
matching: identity,
|
|
from: []
|
|
)
|
|
|
|
XCTAssertTrue(firstObserved.isEmpty)
|
|
XCTAssertTrue(secondObserved.isEmpty)
|
|
}
|
|
|
|
func testMissingOrMalformedCurrentIdentityFailsLoudly() {
|
|
XCTAssertThrowsError(try PushNotificationIdentity.require(from: [:])) { error in
|
|
XCTAssertEqual(error as? PushNotificationIdentityError, .missingIdentity)
|
|
}
|
|
XCTAssertThrowsError(
|
|
try PushNotificationIdentity.require(
|
|
from: [PushNotificationIdentity.userInfoKey: ["event_id": "event"]]
|
|
)
|
|
) { error in
|
|
XCTAssertEqual(error as? PushNotificationIdentityError, .malformedIdentity)
|
|
}
|
|
}
|
|
|
|
func testUnrelatedDeliveredNotificationWithoutBuzzIdentityIsIgnored() throws {
|
|
let requestIdentifiers = try PushDuplicateAbsorption.requestIdentifiersToRemove(
|
|
matching: identity,
|
|
from: [
|
|
PushDeliveredNotificationRecord(
|
|
requestIdentifier: "unrelated",
|
|
userInfo: ["other": "value"]
|
|
)
|
|
]
|
|
)
|
|
|
|
XCTAssertTrue(requestIdentifiers.isEmpty)
|
|
}
|
|
|
|
func testMalformedDeliveredBuzzIdentityFailsLoudly() {
|
|
XCTAssertThrowsError(
|
|
try PushDuplicateAbsorption.requestIdentifiersToRemove(
|
|
matching: identity,
|
|
from: [
|
|
PushDeliveredNotificationRecord(
|
|
requestIdentifier: "malformed",
|
|
userInfo: [
|
|
PushNotificationIdentity.userInfoKey: ["event_id": "event"]
|
|
]
|
|
)
|
|
]
|
|
)
|
|
) { error in
|
|
XCTAssertEqual(error as? PushNotificationIdentityError, .malformedIdentity)
|
|
}
|
|
}
|
|
}
|