Skip to content

Commit

Permalink
Add SearchListInteractor
Browse files Browse the repository at this point in the history
  • Loading branch information
dogo committed Mar 18, 2024
1 parent 8fed9a4 commit db8dd91
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// SearchListInteractor.swift
// SWDestinyTrades
//
// Created by Diogo Autilio on 18/03/24.
// Copyright © 2024 Diogo Autilio. All rights reserved.
//

import Foundation

protocol SearchListInteractorProtocol {
func search(query: String) async throws -> [CardDTO]
}

final class SearchListInteractor: SearchListInteractorProtocol {

private let service: SWDestinyServiceProtocol

init(service: SWDestinyServiceProtocol = SWDestinyService()) {
self.service = service
}

func search(query: String) async throws -> [CardDTO] {
return try await service.search(query: query)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// SearchListInteractorTests.swift
// SWDestinyTradesTests
//
// Created by Diogo Autilio on 18/03/24.
// Copyright © 2024 Diogo Autilio. All rights reserved.
//

import Foundation
import XCTest

@testable import SWDestinyTrades

final class SearchListInteractorTests: XCTestCase {

private var sut: SearchListInteractor!
private var service: SWDestinyService!
private var client: HttpClientMock!

override func setUpWithError() throws {
client = HttpClientMock()
service = SWDestinyService(client: client)
sut = SearchListInteractor(service: service)
}

override func tearDownWithError() throws {
client = nil
service = nil
sut = nil
}

func test_search_cards_with_success() async throws {
client.fileName = "card-list"
let cardList = try await sut.search(query: "panda")

XCTAssertEqual(cardList.count, 22)
}

func test_fail_to_search_cards() async throws {
client.error = true

do {
_ = try await sut.search(query: "panda")
XCTFail("Expected to throw while awaiting, but succeeded")
} catch {
XCTAssertNotNil(error, "error must be not-nil")
}
}
}

0 comments on commit db8dd91

Please sign in to comment.