Skip to content

Commit

Permalink
Adds unit tests for watchlist in account client
Browse files Browse the repository at this point in the history
  • Loading branch information
DeluxeAlonso committed Sep 3, 2023
1 parent 6d8d0ac commit 8701e61
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,45 @@ final class AccountClientTests: XCTestCase {
wait(for: [expectation], timeout: 1.0)
}

func testGetWatchlistSuccess() throws {
// Arrange
let data = try JSONEncoder().encode(MovieResult(results: [], currentPage: 1, totalPages: 1))
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: "Get watchlist success")
// Act
accountClient.getWatchlist(page: 1, sortBy: .createdAtAsc, sessionId: "", accountId: 1) { result in
switch result {
case .success:
break
case .failure:
XCTFail("Get watchlist error")
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

func testGetWatchlistError() throws {
// Arrange
urlSession.dataTaskWithRequestCompletionHandler = (nil, nil, nil)
let expectation = XCTestExpectation(description: "Get watchlist error")
// Act
accountClient.getWatchlist(page: 1, sortBy: .createdAtAsc, sessionId: "", accountId: 1) { result in
switch result {
case .success:
XCTFail("Get watchlist success")
case .failure:
break
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

}

0 comments on commit 8701e61

Please sign in to comment.