Фикс: исправлено исчезновение части уведомлений при открытии пуша
This commit is contained in:
@@ -5,36 +5,37 @@ import Testing
|
||||
|
||||
struct PushNotificationExtendedTests {
|
||||
|
||||
@Test("Realistic FCM token with device ID round-trip")
|
||||
func fcmTokenWithDeviceIdRoundTrip() throws {
|
||||
@Test("Realistic FCM token round-trip")
|
||||
func fcmTokenRoundTrip() throws {
|
||||
// Real FCM tokens are ~163 chars
|
||||
let fcmToken = "dQw4w9WgXcQ:APA91bHnzPc5Y0z4R8kP3mN6vX2tL7wJ1qA5sD8fG0hK3lZ9xC2vB4nM7oP1iU8yT6rE5wQ3jF4kL2mN0bV7cX9sD1aF3gH5jK7lP9oI2uY4tR6eW8qZ0xC"
|
||||
var packet = PacketPushNotification()
|
||||
packet.notificationsToken = fcmToken
|
||||
packet.action = .subscribe
|
||||
packet.tokenType = .fcm
|
||||
packet.deviceId = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop"
|
||||
packet.deviceId = "ios-fcm-device"
|
||||
|
||||
let decoded = try decode(packet)
|
||||
#expect(decoded.notificationsToken == fcmToken)
|
||||
#expect(decoded.action == .subscribe)
|
||||
#expect(decoded.tokenType == .fcm)
|
||||
#expect(decoded.deviceId == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop")
|
||||
#expect(decoded.deviceId == "ios-fcm-device")
|
||||
}
|
||||
|
||||
@Test("Realistic VoIP hex token round-trip")
|
||||
func voipTokenWithDeviceIdRoundTrip() throws {
|
||||
// PushKit tokens are 32 bytes = 64 hex chars
|
||||
let voipToken = "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2"
|
||||
@Test("Realistic APNs hex token round-trip")
|
||||
func apnsTokenRoundTrip() throws {
|
||||
let apnsToken = "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2"
|
||||
var packet = PacketPushNotification()
|
||||
packet.notificationsToken = voipToken
|
||||
packet.notificationsToken = apnsToken
|
||||
packet.action = .subscribe
|
||||
packet.tokenType = .voipApns
|
||||
packet.deviceId = "device-xyz-123"
|
||||
packet.deviceId = "ios-voip-device"
|
||||
|
||||
let decoded = try decode(packet)
|
||||
#expect(decoded.notificationsToken == voipToken)
|
||||
#expect(decoded.notificationsToken == apnsToken)
|
||||
#expect(decoded.action == .subscribe)
|
||||
#expect(decoded.tokenType == .voipApns)
|
||||
#expect(decoded.deviceId == "ios-voip-device")
|
||||
}
|
||||
|
||||
@Test("Long token (256 chars) round-trip — stress test UInt32 string length")
|
||||
@@ -44,38 +45,43 @@ struct PushNotificationExtendedTests {
|
||||
packet.notificationsToken = longToken
|
||||
packet.action = .subscribe
|
||||
packet.tokenType = .fcm
|
||||
packet.deviceId = "dev"
|
||||
packet.deviceId = "ios-long-device"
|
||||
|
||||
let decoded = try decode(packet)
|
||||
#expect(decoded.notificationsToken == longToken)
|
||||
#expect(decoded.notificationsToken.count == 256)
|
||||
#expect(decoded.tokenType == .fcm)
|
||||
#expect(decoded.deviceId == "ios-long-device")
|
||||
}
|
||||
|
||||
@Test("Unicode device ID with emoji and Cyrillic round-trip")
|
||||
func unicodeDeviceIdRoundTrip() throws {
|
||||
let unicodeId = "Телефон Гайдара 📱"
|
||||
@Test("Unicode token round-trip")
|
||||
func unicodeTokenRoundTrip() throws {
|
||||
let unicodeToken = "Токен-Гайдара-📱"
|
||||
var packet = PacketPushNotification()
|
||||
packet.notificationsToken = "token"
|
||||
packet.notificationsToken = unicodeToken
|
||||
packet.action = .subscribe
|
||||
packet.tokenType = .fcm
|
||||
packet.deviceId = unicodeId
|
||||
packet.deviceId = "ios-unicode-device"
|
||||
|
||||
let decoded = try decode(packet)
|
||||
#expect(decoded.deviceId == unicodeId)
|
||||
#expect(decoded.notificationsToken == unicodeToken)
|
||||
#expect(decoded.tokenType == .fcm)
|
||||
#expect(decoded.deviceId == "ios-unicode-device")
|
||||
}
|
||||
|
||||
@Test("Unsubscribe action round-trip for both token types",
|
||||
arguments: [PushTokenType.fcm, PushTokenType.voipApns])
|
||||
func unsubscribeRoundTrip(tokenType: PushTokenType) throws {
|
||||
@Test("Unsubscribe action round-trip")
|
||||
func unsubscribeRoundTrip() throws {
|
||||
var packet = PacketPushNotification()
|
||||
packet.notificationsToken = "test-token"
|
||||
packet.action = .unsubscribe
|
||||
packet.tokenType = tokenType
|
||||
packet.deviceId = "dev"
|
||||
packet.tokenType = .voipApns
|
||||
packet.deviceId = "ios-unsub-device"
|
||||
|
||||
let decoded = try decode(packet)
|
||||
#expect(decoded.action == .unsubscribe)
|
||||
#expect(decoded.tokenType == tokenType)
|
||||
#expect(decoded.notificationsToken == "test-token")
|
||||
#expect(decoded.tokenType == .voipApns)
|
||||
#expect(decoded.deviceId == "ios-unsub-device")
|
||||
}
|
||||
|
||||
private func decode(_ packet: PacketPushNotification) throws -> PacketPushNotification {
|
||||
@@ -200,11 +206,6 @@ struct CallPushEnumParityTests {
|
||||
#expect(pair.0.rawValue == pair.1)
|
||||
}
|
||||
|
||||
@Test("PushTokenType enum values match server")
|
||||
func pushTokenTypeValues() {
|
||||
#expect(PushTokenType.fcm.rawValue == 0)
|
||||
#expect(PushTokenType.voipApns.rawValue == 1)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Wire Format Byte-Level Tests
|
||||
@@ -216,8 +217,8 @@ struct CallPushWireFormatTests {
|
||||
var packet = PacketPushNotification()
|
||||
packet.notificationsToken = "A"
|
||||
packet.action = .unsubscribe
|
||||
packet.tokenType = .fcm
|
||||
packet.deviceId = "B"
|
||||
packet.tokenType = .voipApns
|
||||
packet.deviceId = "D"
|
||||
|
||||
let data = PacketRegistry.encode(packet)
|
||||
#expect(data.count == 16)
|
||||
@@ -230,12 +231,12 @@ struct CallPushWireFormatTests {
|
||||
#expect(data[6] == 0x00); #expect(data[7] == 0x41)
|
||||
// action = 1 (unsubscribe)
|
||||
#expect(data[8] == 0x01)
|
||||
// tokenType = 0 (fcm)
|
||||
#expect(data[9] == 0x00)
|
||||
// deviceId "B": length=1, 'B'=0x0042
|
||||
// tokenType = 1 (voipApns)
|
||||
#expect(data[9] == 0x01)
|
||||
// deviceId "D": length=1, 'D'=0x0044
|
||||
#expect(data[10] == 0x00); #expect(data[11] == 0x00)
|
||||
#expect(data[12] == 0x00); #expect(data[13] == 0x01)
|
||||
#expect(data[14] == 0x00); #expect(data[15] == 0x42)
|
||||
#expect(data[14] == 0x00); #expect(data[15] == 0x44)
|
||||
}
|
||||
|
||||
@Test("SignalPeer call byte layout: signalType→src→dst→callId→joinToken")
|
||||
|
||||
Reference in New Issue
Block a user