@@ -7,9 +7,12 @@ import Combine
77final class FaceLivenessDetectionViewModelTestCase : XCTestCase {
88 var videoChunker : VideoChunker !
99 var viewModel : FaceLivenessDetectionViewModel !
10+ var faceDetector : MockFaceDetector !
11+ var livenessService : MockLivenessService !
1012
1113 override func setUp( ) {
12- let faceDetector = MockFaceDetector ( )
14+ faceDetector = MockFaceDetector ( )
15+ livenessService = MockLivenessService ( )
1316 let videoChunker = VideoChunker (
1417 assetWriter: LivenessAVAssetWriter ( ) ,
1518 assetWriterDelegate: VideoChunker . AssetWriterDelegate ( ) ,
@@ -40,18 +43,32 @@ final class FaceLivenessDetectionViewModelTestCase: XCTestCase {
4043 /// When: The viewModel is first initialized
4144 /// Then: The state is `.intitial`
4245 func testInitialState( ) {
43- viewModel. livenessService = MockLivenessService ( )
46+ // This first call comes from the FaceLivenessDetectionViewModel's initializer
47+ XCTAssertEqual ( faceDetector. interactions, [
48+ " setResultHandler(detectionResultHandler:) (FaceLivenessDetectionViewModel) "
49+ ] )
50+ XCTAssertEqual ( livenessService. interactions, [ ] )
51+
52+ viewModel. livenessService = self . livenessService
4453 XCTAssertEqual ( viewModel. livenessState. state, . initial)
54+ XCTAssertEqual ( faceDetector. interactions, [
55+ " setResultHandler(detectionResultHandler:) (FaceLivenessDetectionViewModel) "
56+ ] )
57+ XCTAssertEqual ( livenessService. interactions, [ ] )
4558 }
4659
4760 /// Given: A `FaceLivenessDetectionViewModel`
4861 /// When: The viewModel is processes the happy path events
4962 /// Then: The end state of this flow is `.faceMatched`
5063 func testHappyPathToMatchedFace( ) async throws {
51- viewModel. livenessService = MockLivenessService ( )
64+ viewModel. livenessService = self . livenessService
5265
5366 viewModel. livenessState. checkIsFacePrepared ( )
5467 XCTAssertEqual ( viewModel. livenessState. state, . pendingFacePreparedConfirmation( . pendingCheck) )
68+ XCTAssertEqual ( faceDetector. interactions, [
69+ " setResultHandler(detectionResultHandler:) (FaceLivenessDetectionViewModel) "
70+ ] )
71+ XCTAssertEqual ( livenessService. interactions, [ ] )
5572
5673 viewModel. initializeLivenessStream ( )
5774 viewModel. process ( newResult: . noFace)
@@ -76,5 +93,11 @@ final class FaceLivenessDetectionViewModelTestCase: XCTestCase {
7693
7794 viewModel. livenessState. faceMatched ( )
7895 XCTAssertEqual ( viewModel. livenessState. state, . faceMatched)
96+ XCTAssertEqual ( faceDetector. interactions, [
97+ " setResultHandler(detectionResultHandler:) (FaceLivenessDetectionViewModel) "
98+ ] )
99+ XCTAssertEqual ( livenessService. interactions, [
100+ " initializeLivenessStream(withSessionID:userAgent:) "
101+ ] )
79102 }
80103}
0 commit comments