@@ -7,9 +7,12 @@ import Combine
7
7
final class FaceLivenessDetectionViewModelTestCase : XCTestCase {
8
8
var videoChunker : VideoChunker !
9
9
var viewModel : FaceLivenessDetectionViewModel !
10
+ var faceDetector : MockFaceDetector !
11
+ var livenessService : MockLivenessService !
10
12
11
13
override func setUp( ) {
12
- let faceDetector = MockFaceDetector ( )
14
+ faceDetector = MockFaceDetector ( )
15
+ livenessService = MockLivenessService ( )
13
16
let videoChunker = VideoChunker (
14
17
assetWriter: LivenessAVAssetWriter ( ) ,
15
18
assetWriterDelegate: VideoChunker . AssetWriterDelegate ( ) ,
@@ -40,18 +43,32 @@ final class FaceLivenessDetectionViewModelTestCase: XCTestCase {
40
43
/// When: The viewModel is first initialized
41
44
/// Then: The state is `.intitial`
42
45
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
44
53
XCTAssertEqual ( viewModel. livenessState. state, . initial)
54
+ XCTAssertEqual ( faceDetector. interactions, [
55
+ " setResultHandler(detectionResultHandler:) (FaceLivenessDetectionViewModel) "
56
+ ] )
57
+ XCTAssertEqual ( livenessService. interactions, [ ] )
45
58
}
46
59
47
60
/// Given: A `FaceLivenessDetectionViewModel`
48
61
/// When: The viewModel is processes the happy path events
49
62
/// Then: The end state of this flow is `.faceMatched`
50
63
func testHappyPathToMatchedFace( ) async throws {
51
- viewModel. livenessService = MockLivenessService ( )
64
+ viewModel. livenessService = self . livenessService
52
65
53
66
viewModel. livenessState. checkIsFacePrepared ( )
54
67
XCTAssertEqual ( viewModel. livenessState. state, . pendingFacePreparedConfirmation( . pendingCheck) )
68
+ XCTAssertEqual ( faceDetector. interactions, [
69
+ " setResultHandler(detectionResultHandler:) (FaceLivenessDetectionViewModel) "
70
+ ] )
71
+ XCTAssertEqual ( livenessService. interactions, [ ] )
55
72
56
73
viewModel. initializeLivenessStream ( )
57
74
viewModel. process ( newResult: . noFace)
@@ -76,5 +93,11 @@ final class FaceLivenessDetectionViewModelTestCase: XCTestCase {
76
93
77
94
viewModel. livenessState. faceMatched ( )
78
95
XCTAssertEqual ( viewModel. livenessState. state, . faceMatched)
96
+ XCTAssertEqual ( faceDetector. interactions, [
97
+ " setResultHandler(detectionResultHandler:) (FaceLivenessDetectionViewModel) "
98
+ ] )
99
+ XCTAssertEqual ( livenessService. interactions, [
100
+ " initializeLivenessStream(withSessionID:userAgent:) "
101
+ ] )
79
102
}
80
103
}
0 commit comments