import Foundation import Testing @testable import LocalData @Suite struct SyncHelperTests { private let helper = SyncHelper.shared @Test func syncPolicyNeverDoesNothing() async throws { // This should return early without doing anything try await helper.syncIfNeeded( data: Data("test".utf8), keyName: "test.key", availability: .all, syncPolicy: .never ) } @Test func syncPolicyAutomaticSmallThrowsIfTooLarge() async throws { let config = SyncConfiguration(maxAutoSyncSize: 10) await helper.updateConfiguration(config) let largeData = Data(repeating: 0, count: 100) await #expect(throws: StorageError.dataTooLargeForSync) { try await helper.syncIfNeeded( data: largeData, keyName: "too.large", availability: .all, syncPolicy: .automaticSmall ) } } @Test func syncPolicyAutomaticSmallPassesIfSmall() async throws { let config = SyncConfiguration(maxAutoSyncSize: 1000) await helper.updateConfiguration(config) let smallData = Data(repeating: 0, count: 10) // This should not throw StorageError.dataTooLargeForSync // It might return early due to WCSession not being supported/active in tests, // which is fine for covering the policy check logic. try await helper.syncIfNeeded( data: smallData, keyName: "small.key", availability: .all, syncPolicy: .automaticSmall ) } @Test func syncAvailabilityChecksPlatform() async { let available = await helper.isSyncAvailable() // In a simulator environment without a paired watch, this is likely false // But we are exercising the code path. #expect(available == available) } }