|
Bogdan Timofte
authored
19 hours ago
|
1
|
import HealthKit
|
|
|
2
|
import XCTest
|
|
|
3
|
@testable import HealthProbe
|
|
|
4
|
|
|
|
5
|
final class HealthKitAPICallResultTests: XCTestCase {
|
|
|
6
|
func testProtectedDataInaccessibleDetectionRecognizesHealthKitDatabaseLockError() {
|
|
|
7
|
let result = HealthKitAPICallResult(
|
|
|
8
|
queryType: "earliest_sample",
|
|
|
9
|
status: .failed,
|
|
|
10
|
elapsedSeconds: 0,
|
|
|
11
|
resultValue: nil,
|
|
|
12
|
errorCode: "\(HKError.Code.errorDatabaseInaccessible.rawValue)",
|
|
|
13
|
errorDomain: HKError.errorDomain,
|
|
|
14
|
errorDescription: "Protected health data is inaccessible because the device is locked.",
|
|
|
15
|
failureKind: "HealthKit error",
|
|
|
16
|
cancellationReason: nil
|
|
|
17
|
)
|
|
|
18
|
|
|
|
19
|
XCTAssertTrue(result.indicatesProtectedDataInaccessible)
|
|
|
20
|
}
|
|
|
21
|
|
|
|
22
|
func testProtectedDataInaccessibleDetectionIgnoresOtherHealthKitFailures() {
|
|
|
23
|
let result = HealthKitAPICallResult(
|
|
|
24
|
queryType: "earliest_sample",
|
|
|
25
|
status: .failed,
|
|
|
26
|
elapsedSeconds: 0,
|
|
|
27
|
resultValue: nil,
|
|
|
28
|
errorCode: "\(HKError.Code.errorAuthorizationDenied.rawValue)",
|
|
|
29
|
errorDomain: HKError.errorDomain,
|
|
|
30
|
errorDescription: "Authorization denied.",
|
|
|
31
|
failureKind: "HealthKit error",
|
|
|
32
|
cancellationReason: nil
|
|
|
33
|
)
|
|
|
34
|
|
|
|
35
|
XCTAssertFalse(result.indicatesProtectedDataInaccessible)
|
|
|
36
|
}
|
|
|
37
|
}
|