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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,24 @@ import Foundation
|
|||||||
import Testing
|
import Testing
|
||||||
|
|
||||||
@Suite struct DeepLinkParserTests {
|
@Suite struct DeepLinkParserTests {
|
||||||
|
@Test func parseRejectsUnknownHost() {
|
||||||
|
let url = URL(string: "clawdis://nope?message=hi")!
|
||||||
|
#expect(DeepLinkParser.parse(url) == nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func parseHostIsCaseInsensitive() {
|
||||||
|
let url = URL(string: "clawdis://AGENT?message=Hello")!
|
||||||
|
#expect(DeepLinkParser.parse(url) == .agent(.init(
|
||||||
|
message: "Hello",
|
||||||
|
sessionKey: nil,
|
||||||
|
thinking: nil,
|
||||||
|
deliver: false,
|
||||||
|
to: nil,
|
||||||
|
channel: nil,
|
||||||
|
timeoutSeconds: nil,
|
||||||
|
key: nil)))
|
||||||
|
}
|
||||||
|
|
||||||
@Test func parseRejectsNonClawdisScheme() {
|
@Test func parseRejectsNonClawdisScheme() {
|
||||||
let url = URL(string: "https://example.com/agent?message=hi")!
|
let url = URL(string: "https://example.com/agent?message=hi")!
|
||||||
#expect(DeepLinkParser.parse(url) == nil)
|
#expect(DeepLinkParser.parse(url) == nil)
|
||||||
@@ -28,6 +46,21 @@ import Testing
|
|||||||
key: nil)))
|
key: nil)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test func parseAgentLinkParsesTargetRoutingFields() {
|
||||||
|
let url = URL(string: "clawdis://agent?message=Hello%20World&deliver=1&to=%2B15551234567&channel=whatsapp&key=secret")!
|
||||||
|
#expect(
|
||||||
|
DeepLinkParser.parse(url) == .agent(
|
||||||
|
.init(
|
||||||
|
message: "Hello World",
|
||||||
|
sessionKey: nil,
|
||||||
|
thinking: nil,
|
||||||
|
deliver: true,
|
||||||
|
to: "+15551234567",
|
||||||
|
channel: "whatsapp",
|
||||||
|
timeoutSeconds: nil,
|
||||||
|
key: "secret")))
|
||||||
|
}
|
||||||
|
|
||||||
@Test func parseRejectsNegativeTimeoutSeconds() {
|
@Test func parseRejectsNegativeTimeoutSeconds() {
|
||||||
let url = URL(string: "clawdis://agent?message=Hello&timeoutSeconds=-1")!
|
let url = URL(string: "clawdis://agent?message=Hello&timeoutSeconds=-1")!
|
||||||
#expect(DeepLinkParser.parse(url) == .agent(.init(
|
#expect(DeepLinkParser.parse(url) == .agent(.init(
|
||||||
|
|||||||
22
apps/ios/Tests/KeychainStoreTests.swift
Normal file
22
apps/ios/Tests/KeychainStoreTests.swift
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import Foundation
|
||||||
|
import Testing
|
||||||
|
@testable import Clawdis
|
||||||
|
|
||||||
|
@Suite struct KeychainStoreTests {
|
||||||
|
@Test func saveLoadUpdateDeleteRoundTrip() {
|
||||||
|
let service = "com.steipete.clawdis.tests.\(UUID().uuidString)"
|
||||||
|
let account = "value"
|
||||||
|
|
||||||
|
#expect(KeychainStore.delete(service: service, account: account))
|
||||||
|
#expect(KeychainStore.loadString(service: service, account: account) == nil)
|
||||||
|
|
||||||
|
#expect(KeychainStore.saveString("first", service: service, account: account))
|
||||||
|
#expect(KeychainStore.loadString(service: service, account: account) == "first")
|
||||||
|
|
||||||
|
#expect(KeychainStore.saveString("second", service: service, account: account))
|
||||||
|
#expect(KeychainStore.loadString(service: service, account: account) == "second")
|
||||||
|
|
||||||
|
#expect(KeychainStore.delete(service: service, account: account))
|
||||||
|
#expect(KeychainStore.loadString(service: service, account: account) == nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user