Skip to content

Commit fffcf50

Browse files
committed
add tests for glucoseTooOld and glucoseInFuture
1 parent ffbdc46 commit fffcf50

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

LoopTests/ViewModels/BolusEntryViewModelTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,26 @@ class BolusEntryViewModelTests: XCTestCase {
348348
XCTAssertEqual(.stalePumpData, bolusEntryViewModel.activeNotice)
349349
}
350350

351+
func testUpdateRecommendedBolusThrowsGlucoseTooOld() async throws {
352+
XCTAssertFalse(bolusEntryViewModel.isBolusRecommended)
353+
delegate.loopState.bolusRecommendationError = LoopError.glucoseTooOld(date: now)
354+
await bolusEntryViewModel.update()
355+
XCTAssertFalse(bolusEntryViewModel.isBolusRecommended)
356+
let recommendedBolus = bolusEntryViewModel.recommendedBolus
357+
XCTAssertNil(recommendedBolus)
358+
XCTAssertEqual(.staleGlucoseData, bolusEntryViewModel.activeNotice)
359+
}
360+
361+
func testUpdateRecommendedBolusThrowsGlucoseInFuture() async throws {
362+
XCTAssertFalse(bolusEntryViewModel.isBolusRecommended)
363+
delegate.loopState.bolusRecommendationError = LoopError.glucoseInFuture(date: now)
364+
await bolusEntryViewModel.update()
365+
XCTAssertFalse(bolusEntryViewModel.isBolusRecommended)
366+
let recommendedBolus = bolusEntryViewModel.recommendedBolus
367+
XCTAssertNil(recommendedBolus)
368+
XCTAssertEqual(.futureGlucoseData, bolusEntryViewModel.activeNotice)
369+
}
370+
351371
func testUpdateRecommendedBolusThrowsOtherError() async throws {
352372
XCTAssertFalse(bolusEntryViewModel.isBolusRecommended)
353373
delegate.loopState.bolusRecommendationError = LoopError.pumpSuspended

0 commit comments

Comments
 (0)