-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
SWDestinyTrades/Classes/Search/Interactor/SearchListInteractor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
SWDestinyTradesTests/Screens/Search/Interactor/SearchListInteractorTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} |