Фикс: исправлено исчезновение части уведомлений при открытии пуша
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
import Testing
|
||||
@testable import Rosetta
|
||||
|
||||
/// Verifies PacketPushNotification wire format matches server
|
||||
/// (im.rosetta.packet.Packet16PushNotification).
|
||||
///
|
||||
/// Server wire format:
|
||||
/// Verifies PacketPushNotification wire format matches Server/Android:
|
||||
/// writeInt16(packetId=0x10)
|
||||
/// writeString(notificationToken)
|
||||
/// writeInt8(action) — 0=subscribe, 1=unsubscribe
|
||||
/// writeInt8(tokenType) — 0=FCM, 1=VoIPApns
|
||||
/// writeInt8(action)
|
||||
/// writeInt8(tokenType)
|
||||
/// writeString(deviceId)
|
||||
struct PushNotificationPacketTests {
|
||||
|
||||
@@ -24,49 +21,49 @@ struct PushNotificationPacketTests {
|
||||
#expect(PushNotificationAction.unsubscribe.rawValue == 1)
|
||||
}
|
||||
|
||||
@Test("PushTokenType.fcm == 0 (server: FCM)")
|
||||
@Test("PushTokenType.fcm == 0")
|
||||
func fcmTokenTypeValue() {
|
||||
#expect(PushTokenType.fcm.rawValue == 0)
|
||||
}
|
||||
|
||||
@Test("PushTokenType.voipApns == 1 (server: VoIPApns)")
|
||||
@Test("PushTokenType.voipApns == 1")
|
||||
func voipTokenTypeValue() {
|
||||
#expect(PushTokenType.voipApns.rawValue == 1)
|
||||
}
|
||||
|
||||
// MARK: - Round Trip (encode → decode)
|
||||
|
||||
@Test("FCM subscribe round-trip preserves all fields")
|
||||
func fcmSubscribeRoundTrip() throws {
|
||||
@Test("Subscribe round-trip preserves all fields")
|
||||
func subscribeRoundTrip() throws {
|
||||
var packet = PacketPushNotification()
|
||||
packet.notificationsToken = "test-fcm-token-abc123"
|
||||
packet.action = .subscribe
|
||||
packet.tokenType = .fcm
|
||||
packet.deviceId = "device-id-xyz"
|
||||
packet.deviceId = "ios-device-1"
|
||||
|
||||
let decoded = try decodePushNotification(packet)
|
||||
#expect(decoded.notificationsToken == "test-fcm-token-abc123")
|
||||
#expect(decoded.action == .subscribe)
|
||||
#expect(decoded.tokenType == .fcm)
|
||||
#expect(decoded.deviceId == "device-id-xyz")
|
||||
#expect(decoded.deviceId == "ios-device-1")
|
||||
}
|
||||
|
||||
@Test("VoIP unsubscribe round-trip preserves all fields")
|
||||
func voipUnsubscribeRoundTrip() throws {
|
||||
@Test("Unsubscribe round-trip preserves all fields")
|
||||
func unsubscribeRoundTrip() throws {
|
||||
var packet = PacketPushNotification()
|
||||
packet.notificationsToken = "voip-hex-token-deadbeef"
|
||||
packet.notificationsToken = "test-token-deadbeef"
|
||||
packet.action = .unsubscribe
|
||||
packet.tokenType = .voipApns
|
||||
packet.deviceId = "another-device-id"
|
||||
packet.deviceId = "ios-device-2"
|
||||
|
||||
let decoded = try decodePushNotification(packet)
|
||||
#expect(decoded.notificationsToken == "voip-hex-token-deadbeef")
|
||||
#expect(decoded.notificationsToken == "test-token-deadbeef")
|
||||
#expect(decoded.action == .unsubscribe)
|
||||
#expect(decoded.tokenType == .voipApns)
|
||||
#expect(decoded.deviceId == "another-device-id")
|
||||
#expect(decoded.deviceId == "ios-device-2")
|
||||
}
|
||||
|
||||
@Test("Empty token and deviceId round-trip")
|
||||
@Test("Empty token round-trip")
|
||||
func emptyFieldsRoundTrip() throws {
|
||||
var packet = PacketPushNotification()
|
||||
packet.notificationsToken = ""
|
||||
@@ -76,6 +73,7 @@ struct PushNotificationPacketTests {
|
||||
|
||||
let decoded = try decodePushNotification(packet)
|
||||
#expect(decoded.notificationsToken == "")
|
||||
#expect(decoded.tokenType == .fcm)
|
||||
#expect(decoded.deviceId == "")
|
||||
}
|
||||
|
||||
@@ -100,7 +98,7 @@ struct PushNotificationPacketTests {
|
||||
var packet = PacketPushNotification()
|
||||
packet.notificationsToken = "T" // 1 UTF-16 code unit
|
||||
packet.action = .subscribe // 0
|
||||
packet.tokenType = .voipApns // 1
|
||||
packet.tokenType = .fcm // 0
|
||||
packet.deviceId = "D" // 1 UTF-16 code unit
|
||||
|
||||
let data = PacketRegistry.encode(packet)
|
||||
@@ -110,9 +108,9 @@ struct PushNotificationPacketTests {
|
||||
// [2-5] string length = 1 (UInt32 big-endian) for "T"
|
||||
// [6-7] 'T' = 0x0054 (UInt16 big-endian)
|
||||
// [8] action = 0 (subscribe)
|
||||
// [9] tokenType = 1 (voipApns)
|
||||
// [9] tokenType = 0 (fcm)
|
||||
// [10-13] string length = 1 for "D"
|
||||
// [14-15] 'D' = 0x0044 (UInt16 big-endian)
|
||||
// [14-15] 'D' = 0x0044
|
||||
|
||||
#expect(data.count == 16)
|
||||
|
||||
@@ -133,8 +131,8 @@ struct PushNotificationPacketTests {
|
||||
// action = 0 (subscribe)
|
||||
#expect(data[8] == 0x00)
|
||||
|
||||
// tokenType = 1 (voipApns)
|
||||
#expect(data[9] == 0x01)
|
||||
// tokenType = 0 (fcm)
|
||||
#expect(data[9] == 0x00)
|
||||
|
||||
// deviceId string length = 1
|
||||
#expect(data[10] == 0x00)
|
||||
|
||||
Reference in New Issue
Block a user