Files
wristivo/Adapters/WatchBridge/Tests/iPhone/PhoneRelayDependencyTests.swift
T

42 lines
1.8 KiB
Swift

import Foundation
import Testing
import RemoteCore
import WatchBridgePhone
private actor FakePhoneCoordinator: PhoneCommandCoordinating {
private(set) var receivedCommands: [CommandEnvelope] = []
private(set) var receivedPeers: [WatchPeerGeneration] = []
func watchBridgeDidActivate(peer: WatchPeerGeneration) {}
func watchBridgeDidDeactivate(peer: WatchPeerGeneration) {}
func beginWatchSession(_ request: BeginRemoteSessionRequest, peer: WatchPeerGeneration)
-> Result<RemoteSessionGrant, RelayFailure> {
.failure(RelayFailure(code: .unavailable))
}
func endWatchSession(_ request: EndRemoteSessionRequest, peer: WatchPeerGeneration)
-> Result<RemoteSessionEnded, RelayFailure> {
.failure(RelayFailure(code: .sessionInvalidated))
}
func submitWatchCommand(_ envelope: CommandEnvelope, peer: WatchPeerGeneration) -> CommandReceipt {
receivedCommands.append(envelope)
receivedPeers.append(peer)
return CommandReceipt(id: envelope.id, status: .rejected)
}
}
@Test func phoneDependencyUsesInjectedActorAndPreservesItsDecision() async {
let actor = FakePhoneCoordinator()
let dependency = PhoneRelayDependency(coordinator: actor)
#expect(dependency.coordinator === actor)
let peer = WatchPeerGeneration()
let now = Date(timeIntervalSince1970: 1_700_000_000)
let command = CommandEnvelope(
sessionID: UUID(), televisionID: UUID(), sequence: 1,
issuedAt: now, expiresAt: now.addingTimeInterval(0.5), command: .right
)
let receipt = await dependency.coordinator.submitWatchCommand(command, peer: peer)
#expect(receipt == CommandReceipt(id: command.id, status: .rejected))
#expect(await actor.receivedCommands == [command])
#expect(await actor.receivedPeers == [peer])
}