@@ -38,6 +38,13 @@ final class FaceLivenessDetectionViewModelTestCase: XCTestCase {
3838 self . videoChunker = videoChunker
3939 self . viewModel = viewModel
4040 }
41+
42+ override func tearDown( ) {
43+ self . faceDetector = nil
44+ self . livenessService = nil
45+ self . videoChunker = nil
46+ self . viewModel = nil
47+ }
4148
4249 /// Given: A `FaceLivenessDetectionViewModel`
4350 /// When: The viewModel is first initialized
@@ -113,7 +120,7 @@ final class FaceLivenessDetectionViewModelTestCase: XCTestCase {
113120 " setResultHandler(detectionResultHandler:) (FaceLivenessDetectionViewModel) "
114121 ] )
115122 XCTAssertEqual ( livenessService. interactions, [ ] )
116-
123+
117124 let boundingBox = CGRect ( x: 0.26788579725878847 , y: 0.40317180752754211 , width: 0.45549795395626447 , height: 0.34162446856498718 )
118125 let leftEye = CGPoint ( x: 0.61124476128552629 , y: 0.4918237030506134 )
119126 let rightEye = CGPoint ( x: 0.38036393762719456 , y: 0.48050540685653687 )
@@ -131,4 +138,20 @@ final class FaceLivenessDetectionViewModelTestCase: XCTestCase {
131138 " initializeLivenessStream(withSessionID:userAgent:) "
132139 ] )
133140 }
141+
142+ /// Given: A `FaceLivenessDetectionViewModel`
143+ /// When: The viewModel handles a no match event over a duration of 7 seconds
144+ /// Then: The end state is `.encounteredUnrecoverableError(.timedOut)`
145+ func testNoMatchTimeoutCheck( ) async throws {
146+ viewModel. livenessService = self . livenessService
147+ self . viewModel. handleNoMatch ( instruction: . tooFar( nearnessPercentage: 0.2 ) , percentage: 0.2 )
148+
149+ XCTAssertNotEqual ( self . viewModel. livenessState. state, . encounteredUnrecoverableError( . timedOut) )
150+ try await Task . sleep ( seconds: 6 )
151+ self . viewModel. handleNoMatch ( instruction: . tooFar( nearnessPercentage: 0.2 ) , percentage: 0.2 )
152+ XCTAssertNotEqual ( self . viewModel. livenessState. state, . encounteredUnrecoverableError( . timedOut) )
153+ try await Task . sleep ( seconds: 1 )
154+ self . viewModel. handleNoMatch ( instruction: . tooFar( nearnessPercentage: 0.2 ) , percentage: 0.2 )
155+ XCTAssertEqual ( self . viewModel. livenessState. state, . encounteredUnrecoverableError( . timedOut) )
156+ }
134157}
0 commit comments