RadrootsUserPresenceTesting.swift (2089B)
1 import Foundation 2 import RadrootsKit 3 4 public actor RadrootsFakeUserPresence: RadrootsUserPresence { 5 private var statusValue: RadrootsUserPresenceStatus 6 private var verificationOutcome: Result<Bool, RadrootsUserPresenceError> 7 private var statusRequestCountValue: Int 8 private var verificationRequestsValue: [RadrootsUserPresenceRequest] 9 10 public init( 11 status: RadrootsUserPresenceStatus = RadrootsUserPresenceStatus( 12 support: .biometricsOrDeviceCredential, 13 biometryKind: .faceID, 14 canEvaluateDeviceCredential: true, 15 canEvaluateBiometrics: true 16 ), 17 verificationOutcome: Result<Bool, RadrootsUserPresenceError> = .success(true) 18 ) { 19 self.statusValue = status 20 self.verificationOutcome = verificationOutcome 21 self.statusRequestCountValue = 0 22 self.verificationRequestsValue = [] 23 } 24 25 public func setStatus(_ status: RadrootsUserPresenceStatus) { 26 statusValue = status 27 } 28 29 public func setVerificationOutcome(_ outcome: Result<Bool, RadrootsUserPresenceError>) { 30 verificationOutcome = outcome 31 } 32 33 public func currentStatus() async throws -> RadrootsUserPresenceStatus { 34 statusRequestCountValue += 1 35 return statusValue 36 } 37 38 public func verify(_ request: RadrootsUserPresenceRequest) async throws -> RadrootsUserPresenceResult { 39 verificationRequestsValue.append(request) 40 switch verificationOutcome { 41 case .success(let verified): 42 return RadrootsUserPresenceResult(policy: request.policy, verified: verified) 43 case .failure(let error): 44 throw error 45 } 46 } 47 48 public var statusRequestCount: Int { 49 statusRequestCountValue 50 } 51 52 public var verificationRequestCount: Int { 53 verificationRequestsValue.count 54 } 55 56 public var verificationRequests: [RadrootsUserPresenceRequest] { 57 verificationRequestsValue 58 } 59 60 public var lastVerificationRequest: RadrootsUserPresenceRequest? { 61 verificationRequestsValue.last 62 } 63 }