LocalData/Tests/LocalDataTests/SyncHelperTests.swift
Matt Bruce e27e2e38bb Tests AnyCodableTests.swift, AnyStorageKeyTests.swift, AuditTests.swift (+8 more)
Summary:
- Tests: AnyCodableTests.swift, AnyStorageKeyTests.swift, AuditTests.swift, EncryptionLogicTests.swift, FileStorageHelperTests.swift (+6 more)
- Added symbols: struct NonCodable, struct StringKey, typealias Value, struct AuditCatalog, struct TestKey, struct RawProvider (+11 more)

Stats:
- 11 files changed, 698 insertions(+)
2026-01-18 14:53:29 -06:00

58 lines
1.9 KiB
Swift

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)
}
}