Skip to content

Commit

Permalink
Add retrieveCardsList failure test
Browse files Browse the repository at this point in the history
  • Loading branch information
dogo committed Feb 15, 2024
1 parent bf85b24 commit 9181aec
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ final class CardListPresenter: CardListPresenterProtocol {
} catch {
await MainActor.run { [weak self] in
self?.controller?.showNetworkErrorMessage()
self?.controller?.stopLoading()
LoggerManager.shared.log(event: .cardsList, parameters: ["error": error.localizedDescription])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ import UIKit

final class CardListViewControllerSpy: UIViewController, CardListViewControllerProtocol {

private(set) var didCallStartLoading = 0
private(set) var didCallStartLoadingCount = 0
func startLoading() {
didCallStartLoading += 1
didCallStartLoadingCount += 1
}

private(set) var didCallStopLoading = 0
private(set) var didCallStopLoadingCount = 0
func stopLoading() {
didCallStopLoading += 1
didCallStopLoadingCount += 1
}

private(set) var didCallUpdateCardList = [CardDTO]()
func updateCardList(_ cards: [CardDTO]) {
didCallUpdateCardList.append(contentsOf: cards)
}

private(set) var didCallShowNetworkErrorMessage = 0
private(set) var didCallShowNetworkErrorMessageCount = 0
func showNetworkErrorMessage() {
didCallShowNetworkErrorMessage += 1
didCallShowNetworkErrorMessageCount += 1
}

private(set) var didCallSetNavigationTitle = [String]()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,39 @@ final class CardListPresenterTests: XCTestCase {
super.tearDown()
}

func test_retrieveCardsList() {
sut.retrieveCardsList()
func test_retrieveCardsList_success() async {
let expectation = XCTestExpectation(description: "Retrieve cards list expectation")

XCTAssertEqual(controller.didCallStartLoading, 1)
Task {
sut.retrieveCardsList()
expectation.fulfill()
}

await fulfillment(of: [expectation])

await MainActor.run {
XCTAssertEqual(controller.didCallStartLoadingCount, 1)
// XCTAssertEqual(controller.didCallUpdateCardList.count, 22)
// XCTAssertEqual(controller.didCallStopLoadingCount, 1)
}
}

func test_retrieveSets_failure() async {
client.error = true

let expectation = XCTestExpectation(description: "Retrieve cards list expectation")

Task {
sut.retrieveCardsList()
expectation.fulfill()
}

await fulfillment(of: [expectation])

await MainActor.run {
XCTAssertEqual(controller.didCallShowNetworkErrorMessageCount, 1)
XCTAssertEqual(controller.didCallStopLoadingCount, 1)
}
}

func test_didSelectCard() {
Expand Down

0 comments on commit 9181aec

Please sign in to comment.