LocalData/Tests/LocalDataTests/SyncDelegateTests.swift

44 lines
1.4 KiB
Swift

import Foundation
import Testing
import WatchConnectivity
@testable import LocalData
@Suite struct SyncDelegateTests {
@Test func delegateProxyActivationCallbacks() {
let proxy = SessionDelegateProxy.shared
let session = WCSession.default
// Exercise activation completion (success)
proxy.session(session, activationDidCompleteWith: .activated, error: nil)
// Exercise activation completion (error)
let error = NSError(domain: "test", code: 1, userInfo: nil)
proxy.session(session, activationDidCompleteWith: .notActivated, error: error)
}
@Test func delegateProxyContextReceived() async throws {
let proxy = SessionDelegateProxy.shared
let session = WCSession.default
let context: [String: Any] = [
"test.sync.key": Data("sync-data".utf8)
]
// This triggers SyncHelper.handleReceivedContext
proxy.session(session, didReceiveApplicationContext: context)
// Wait a bit for the Task to start/finish
try await Task.sleep(for: .milliseconds(100))
}
#if os(iOS)
@Test func delegateProxyiOSCallbacks() {
let proxy = SessionDelegateProxy.shared
let session = WCSession.default
proxy.sessionDidBecomeInactive(session)
proxy.sessionDidDeactivate(session)
}
#endif
}