27 lines
1.1 KiB
Swift
27 lines
1.1 KiB
Swift
import Foundation
|
|
import Testing
|
|
import RemoteCore
|
|
import WatchBridgeCommon
|
|
|
|
@Test func payloadUsesUnixMillisecondsInBothDirections() throws {
|
|
let issued = Date(timeIntervalSince1970: 1_700_000_000.125)
|
|
let envelope = CommandEnvelope(
|
|
sessionID: UUID(), televisionID: UUID(), sequence: 1,
|
|
issuedAt: issued, expiresAt: issued.addingTimeInterval(0.5), command: .right
|
|
)
|
|
let container = try RelayContainer(kind: .command, value: envelope)
|
|
let data = container.payload
|
|
#expect(container.schemaVersion == RelayWire.schemaVersion)
|
|
#expect(container.kind == .command)
|
|
let object = try #require(JSONSerialization.jsonObject(with: data) as? [String: Any])
|
|
#expect((object["issuedAt"] as? Double) == 1_700_000_000_125)
|
|
#expect((object["expiresAt"] as? Double) == 1_700_000_000_625)
|
|
#expect(try RelayJSON.decode(CommandEnvelope.self, from: data) == envelope)
|
|
}
|
|
|
|
@Test func outgoingContainerRejectsOversizedPayload() {
|
|
#expect(throws: RelayContractError.payloadTooLarge) {
|
|
try RelayContainer(kind: .error, value: String(repeating: "x", count: RelayWire.maximumPayloadBytes))
|
|
}
|
|
}
|