Skip to content

Commit

Permalink
test: refresh 실패 테스트 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
sujeong000 committed Dec 1, 2021
1 parent 3dbe821 commit 344ffcb
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions BBus/AlarmSettingViewModelTests/AlarmSettingViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class AlarmSettingViewModelTests: XCTestCase {
let expectedSecondArriveInfo = self.secondArriveInfo
let expectedResult = AlarmSettingBusArriveInfos(arriveInfos: [expectedFirstArriveInfo, expectedSecondArriveInfo], changedByTimer: false)

alarmSettingVieWModel.refresh()
alarmSettingVieWModel.$busArriveInfos
.receive(on: DispatchQueue.global())
.filter { $0.count != 0 }
Expand Down Expand Up @@ -122,4 +123,34 @@ class AlarmSettingViewModelTests: XCTestCase {

waitForExpectations(timeout: 10)
}

func test_refresh_arriveInfo가_에러를_리턴하여_실패() {
let MOCCKAlarmSettingUseCase = MOCKAlarmSettingAPIUseCase(mode: .failure, arrInfoByRouteDTO: self.arrInfoByRouteDTO)
let alarmSettingVieWModel = AlarmSettingViewModel(apiUseCase: MOCCKAlarmSettingUseCase,
calculateUseCase: AlarmSettingCalculateUseCase(),
stationId: 1,
busRouteId: 1,
stationOrd: 1,
arsId: "11111",
routeType: RouteType.mainLine,
busName: "11")
let expectation = expectation(description: "AlarmSettingViewModel에 busArriveInfos가 저장되는지 확인")

alarmSettingVieWModel.refresh()
alarmSettingVieWModel.$networkError
.receive(on: DispatchQueue.global())
.compactMap { $0 }
.sink { error in
guard let error = error as? TestError else { XCTFail(); return; }
switch error {
case .fail:
expectation.fulfill()
default:
XCTFail()
}
}
.store(in: &self.cancellables)

waitForExpectations(timeout: 10)
}
}

0 comments on commit 344ffcb

Please sign in to comment.