test(ios): add bridge session + keychain suites
This commit is contained in:
48
apps/ios/Tests/BridgeSessionTests.swift
Normal file
48
apps/ios/Tests/BridgeSessionTests.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable import Clawdis
|
||||
|
||||
@Suite struct BridgeSessionTests {
|
||||
@Test func initialStateIsIdle() async {
|
||||
let session = BridgeSession()
|
||||
#expect(await session.state == .idle)
|
||||
}
|
||||
|
||||
@Test func requestFailsWhenNotConnected() async {
|
||||
let session = BridgeSession()
|
||||
|
||||
do {
|
||||
_ = try await session.request(method: "health", paramsJSON: nil, timeoutSeconds: 1)
|
||||
Issue.record("Expected request to throw when not connected")
|
||||
} catch let error as NSError {
|
||||
#expect(error.domain == "Bridge")
|
||||
#expect(error.code == 11)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func sendEventFailsWhenNotConnected() async {
|
||||
let session = BridgeSession()
|
||||
|
||||
do {
|
||||
try await session.sendEvent(event: "tick", payloadJSON: nil)
|
||||
Issue.record("Expected sendEvent to throw when not connected")
|
||||
} catch let error as NSError {
|
||||
#expect(error.domain == "Bridge")
|
||||
#expect(error.code == 10)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func disconnectFinishesServerEventStreams() async throws {
|
||||
let session = BridgeSession()
|
||||
let stream = await session.subscribeServerEvents(bufferingNewest: 1)
|
||||
|
||||
let consumer = Task { @Sendable in
|
||||
for await _ in stream {}
|
||||
}
|
||||
|
||||
await session.disconnect()
|
||||
|
||||
_ = await consumer.result
|
||||
#expect(await session.state == .idle)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user