Skip to content

Commit 411fcd4

Browse files
committed
checkVersion converted to async, and fix merge issues
1 parent 6179688 commit 411fcd4

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

LoopTests/Managers/LoopDataManagerDosingTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class LoopDataManagerDosingTests: LoopDataManagerTests {
290290
let observer = NotificationCenter.default.addObserver(forName: .LoopDataUpdated, object: nil, queue: nil) { _ in
291291
exp.fulfill()
292292
}
293-
automaticDosingStatus.isClosedLoop = false
293+
automaticDosingStatus.automaticDosingEnabled = false
294294
wait(for: [exp], timeout: 1.0)
295295
let expectedAutomaticDoseRecommendation = AutomaticDoseRecommendation(basalAdjustment: .cancel)
296296
XCTAssertEqual(delegate.recommendation, expectedAutomaticDoseRecommendation)
@@ -345,7 +345,7 @@ class LoopDataManagerDosingTests: LoopDataManagerTests {
345345

346346
func testLoopRecommendsTempBasalWithoutEnactingIfOpenLoop() {
347347
setUp(for: .highAndStable)
348-
automaticDosingStatus.isClosedLoop = false
348+
automaticDosingStatus.automaticDosingEnabled = false
349349
waitOnDataQueue()
350350
let delegate = MockDelegate()
351351
loopDataManager.delegate = delegate
@@ -417,7 +417,7 @@ class LoopDataManagerDosingTests: LoopDataManagerTests {
417417
let currentDate = Date()
418418

419419
dosingDecisionStore = MockDosingDecisionStore()
420-
automaticDosingStatus = AutomaticDosingStatus(isClosedLoop: false, isClosedLoopAllowed: true)
420+
automaticDosingStatus = AutomaticDosingStatus(automaticDosingEnabled: false, isAutomaticDosingAllowed: true)
421421
let existingTempBasal = DoseEntry(
422422
type: .tempBasal,
423423
startDate: currentDate.addingTimeInterval(-.minutes(2)),

LoopTests/Managers/SupportManagerTests.swift

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ class SupportManagerTests: XCTestCase {
2323
nil
2424
}
2525
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+
}
2833
}
2934
weak var delegate: SupportUIDelegate?
3035
}
@@ -62,37 +67,35 @@ class SupportManagerTests: XCTestCase {
6267
supportManager.addSupport(mockSupport)
6368
}
6469

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)
7873
mockSupport.mockResult = .success(.required)
79-
XCTAssertEqual(.required, getVersion())
74+
75+
let result2 = await supportManager.checkVersion()
76+
XCTAssertEqual(.required, result2)
8077
}
8178

82-
func testVersionCheckOneServiceError() throws {
79+
func testVersionCheckOneServiceError() async throws {
8380
// Error doesn't really do anything but log
8481
mockSupport.mockResult = .failure(MockError.nothing)
85-
XCTAssertEqual(VersionUpdate.noUpdateNeeded, getVersion())
82+
let result = await supportManager.checkVersion()
83+
XCTAssertEqual(VersionUpdate.noUpdateNeeded, result)
8684
}
8785

88-
func testVersionCheckMultipleServices() throws {
86+
func testVersionCheckMultipleServices() async throws {
8987
let anotherSupport = AnotherMockSupport()
9088
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()
9293
anotherSupport.mockResult = .success(.required)
93-
XCTAssertEqual(.required, getVersion())
94+
XCTAssertEqual(.required, result2)
95+
96+
let result3 = await supportManager.checkVersion()
9497
mockSupport.mockResult = .success(.recommended)
95-
XCTAssertEqual(.required, getVersion())
98+
XCTAssertEqual(.required, result3)
9699
}
97100

98101
}

0 commit comments

Comments
 (0)