Implement WatchConnectivity relay bridge
This commit is contained in:
@@ -24,3 +24,49 @@ import WatchBridgeCommon
|
||||
try RelayContainer(kind: .error, value: String(repeating: "x", count: RelayWire.maximumPayloadBytes))
|
||||
}
|
||||
}
|
||||
|
||||
@Test func incomingContainerRequiresExactTypedShape() throws {
|
||||
let payload = try RelayJSON.encode(BeginRemoteSessionRequest())
|
||||
let valid: [String: Any] = [
|
||||
"schemaVersion": 1,
|
||||
"kind": "beginSession",
|
||||
"payload": payload
|
||||
]
|
||||
#expect(try RelayContainer(dictionary: valid).kind == .beginSession)
|
||||
#expect(throws: RelayContainerError.extraKeys) {
|
||||
var extra = valid
|
||||
extra["token"] = "never accepted"
|
||||
_ = try RelayContainer(dictionary: extra)
|
||||
}
|
||||
#expect(throws: RelayContainerError.invalidSchemaType) {
|
||||
var booleanVersion = valid
|
||||
booleanVersion["schemaVersion"] = true
|
||||
_ = try RelayContainer(dictionary: booleanVersion)
|
||||
}
|
||||
#expect(throws: RelayContainerError.invalidSchemaType) {
|
||||
var floatingVersion = valid
|
||||
floatingVersion["schemaVersion"] = 1.0
|
||||
_ = try RelayContainer(dictionary: floatingVersion)
|
||||
}
|
||||
#expect(throws: RelayContainerError.invalidPayload) {
|
||||
var wrongPayload = valid
|
||||
wrongPayload["payload"] = "not bytes"
|
||||
_ = try RelayContainer(dictionary: wrongPayload)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func applicationContextContainsOnlyLatestStateAllowlist() throws {
|
||||
let tv = UUID()
|
||||
let context = try RelayApplicationContext(selectedTelevisionID: tv,
|
||||
displayName: "Living room").dictionary()
|
||||
#expect(context["selectedTelevisionID"] as? String == tv.uuidString)
|
||||
#expect(context["displayName"] as? String == "Living room")
|
||||
#expect(!context.keys.contains("token"))
|
||||
#expect(!context.keys.contains("command"))
|
||||
#expect(try RelayApplicationContext(dictionary: context).selectedTelevisionID == tv)
|
||||
var executable = context
|
||||
executable["command"] = "queued"
|
||||
#expect(throws: RelayContainerError.extraKeys) {
|
||||
_ = try RelayApplicationContext(dictionary: executable)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user