LocalData/Tests/LocalDataTests/SyncHelperTests.swift
Matt Bruce 66001439e3 Update Configuration, Helpers, Models (+1 more) + tests
Summary:
- Sources: Configuration, Helpers, Models, Services
- Tests: AppGroupTests.swift, FileStorageHelperExpansionTests.swift, FileStorageHelperTests.swift, MigrationTests.swift, RouterConfigurationTests.swift (+5 more)
- Added symbols: func resolveDirectoryURL, func handleReceivedContext, enum KeychainAccessControl, enum KeychainAccessibility, enum SecurityPolicy, enum EncryptionPolicy (+5 more)
- Removed symbols: func resolveDirectoryURL, func handleReceivedContext, enum KeychainAccessControl, enum KeychainAccessibility, enum SecurityPolicy, enum EncryptionPolicy (+1 more)

Stats:
- 18 files changed, 306 insertions(+), 58 deletions(-)
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()
@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)
let localHelper = SyncHelper(configuration: config)
let largeData = Data(repeating: 0, count: 100)
await #expect(throws: StorageError.dataTooLargeForSync) {
try await localHelper.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)
}
}