@@ -23,8 +23,13 @@ class SupportManagerTests: XCTestCase {
23
23
nil
24
24
}
25
25
var mockResult : Result < VersionUpdate ? , Error > = . success( . default)
26
- func checkVersion( bundleIdentifier: String , currentVersion: String , completion: @escaping ( Result < VersionUpdate ? , Error > ) -> Void ) {
27
- completion ( mockResult)
26
+ func checkVersion( bundleIdentifier: String , currentVersion: String ) async -> VersionUpdate ? {
27
+ switch mockResult {
28
+ case . success( let update) :
29
+ return update
30
+ case . failure:
31
+ return nil
32
+ }
28
33
}
29
34
weak var delegate : SupportUIDelegate ?
30
35
}
@@ -62,37 +67,35 @@ class SupportManagerTests: XCTestCase {
62
67
supportManager. addSupport ( mockSupport)
63
68
}
64
69
65
- func getVersion( fn: String = #function) -> VersionUpdate ? {
66
- let e = expectation ( description: fn)
67
- var result : VersionUpdate ?
68
- supportManager. checkVersion {
69
- result = $0
70
- e. fulfill ( )
71
- }
72
- wait ( for: [ e] , timeout: 1.0 )
73
- return result
74
- }
75
-
76
- func testVersionCheckOneService( ) throws {
77
- XCTAssertEqual ( VersionUpdate . noUpdateNeeded, getVersion ( ) )
70
+ func testVersionCheckOneService( ) async throws {
71
+ let result = await supportManager. checkVersion ( )
72
+ XCTAssertEqual ( VersionUpdate . noUpdateNeeded, result)
78
73
mockSupport. mockResult = . success( . required)
79
- XCTAssertEqual ( . required, getVersion ( ) )
74
+
75
+ let result2 = await supportManager. checkVersion ( )
76
+ XCTAssertEqual ( . required, result2)
80
77
}
81
78
82
- func testVersionCheckOneServiceError( ) throws {
79
+ func testVersionCheckOneServiceError( ) async throws {
83
80
// Error doesn't really do anything but log
84
81
mockSupport. mockResult = . failure( MockError . nothing)
85
- XCTAssertEqual ( VersionUpdate . noUpdateNeeded, getVersion ( ) )
82
+ let result = await supportManager. checkVersion ( )
83
+ XCTAssertEqual ( VersionUpdate . noUpdateNeeded, result)
86
84
}
87
85
88
- func testVersionCheckMultipleServices( ) throws {
86
+ func testVersionCheckMultipleServices( ) async throws {
89
87
let anotherSupport = AnotherMockSupport ( )
90
88
supportManager. addSupport ( anotherSupport)
91
- XCTAssertEqual ( VersionUpdate . noUpdateNeeded, getVersion ( ) )
89
+ let result = await supportManager. checkVersion ( )
90
+ XCTAssertEqual ( VersionUpdate . noUpdateNeeded, result)
91
+
92
+ let result2 = await supportManager. checkVersion ( )
92
93
anotherSupport. mockResult = . success( . required)
93
- XCTAssertEqual ( . required, getVersion ( ) )
94
+ XCTAssertEqual ( . required, result2)
95
+
96
+ let result3 = await supportManager. checkVersion ( )
94
97
mockSupport. mockResult = . success( . recommended)
95
- XCTAssertEqual ( . required, getVersion ( ) )
98
+ XCTAssertEqual ( . required, result3 )
96
99
}
97
100
98
101
}
0 commit comments