Skip to content

Commit

Permalink
Merge pull request #786 from DeluxeAlonso/feature/unit-tests
Browse files Browse the repository at this point in the history
Feature/unit tests
  • Loading branch information
DeluxeAlonso committed Sep 10, 2023
2 parents a7dbe2c + 68f923c commit defa6a0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Alonso on 6/09/21.
//

struct AddToWatchlistResult: Decodable {
struct AddToWatchlistResult: Codable {

let statusCode: Int
let statusMessage: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,45 @@ final class AccountClientTests: XCTestCase {
wait(for: [expectation], timeout: 1.0)
}

func testAddToWatchlistSuccess() throws {
// Arrange
let data = try JSONEncoder().encode(AddToWatchlistResult(statusCode: 200, statusMessage: ""))
guard let url = URL(string: "www.google.com") else {
XCTFail("Invalid URL")
return
}
urlSession.dataTaskWithRequestCompletionHandler = (data, HTTPURLResponse(url: url, statusCode: 200, httpVersion: nil, headerFields: nil), nil)
let expectation = XCTestExpectation(description: "Add to watchlist success")
// Act
accountClient.addToWatchlist(1, sessionId: "", accountId: 1, watchlist: true) { result in
switch result {
case .success:
break
case .failure:
XCTFail("Add to watchlist error")
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

func testAddToWatchlistError() throws {
// Arrange
urlSession.dataTaskWithRequestCompletionHandler = (nil, nil, nil)
let expectation = XCTestExpectation(description: "Add to watchlist error")
// Act
accountClient.addToWatchlist(1, sessionId: "", accountId: 1, watchlist: true) { result in
switch result {
case .success:
XCTFail("Add to watchlist success")
case .failure:
break
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

}

0 comments on commit defa6a0

Please sign in to comment.