Skip to content

Commit

Permalink
Merge pull request #773 from DeluxeAlonso/feature/unit-tests
Browse files Browse the repository at this point in the history
Feature/unit tests
  • Loading branch information
DeluxeAlonso committed Aug 29, 2023
2 parents 1a1e0d8 + c8a3ce7 commit 675e065
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
82 changes: 82 additions & 0 deletions NetworkInfrastructure/Services/MovieClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,86 @@ final class MovieClientTests: XCTestCase {
wait(for: [expectation], timeout: 1.0)
}

func testGetSimilarMoviesError() throws {
// Arrange
urlSession.dataTaskWithRequestCompletionHandler = (nil, nil, nil)
let expectation = XCTestExpectation(description: "Get top rated movies error")
// Act
movieClient.getSimilarMovies(page: 1, movieId: 1) { result in
switch result {
case .success:
XCTFail("Get top rated movies success")
case .failure:
break
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

func testGetSimilarMoviesSuccess() 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 similar movies success")
// Act
movieClient.getSimilarMovies(page: 1, movieId: 1) { result in
switch result {
case .success:
break
case .failure:
XCTFail("Get similar movies error")
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

func testGetMoviesByGenreError() throws {
// Arrange
urlSession.dataTaskWithRequestCompletionHandler = (nil, nil, nil)
let expectation = XCTestExpectation(description: "Get movies by genre error")
// Act
movieClient.getMoviesByGenre(page: 1, genreId: 1) { result in
switch result {
case .success:
XCTFail("Get movies by genre success")
case .failure:
break
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

func testGetMoviesByGenreSuccess() 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 movies by genre success")
// Act
movieClient.getMoviesByGenre(page: 1, genreId: 1) { result in
switch result {
case .success:
break
case .failure:
XCTFail("Get movies by genre error")
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Alonso on 25/06/22.
//

@testable import UpcomingMoviesDomain
import UpcomingMoviesDomain

final class ConfigurationRemoteDataSourceProtocolMock: ConfigurationRemoteDataSourceProtocol {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ final class ProfileViewControllerTests: XCTestCase {
// Act
viewModel.didUpdateAuthenticationState.value = .currentlySignedOut
// Assert
_ = XCTWaiter.wait(for: [XCTestExpectation(description: "")], timeout: 0.1)
_ = XCTWaiter.wait(for: [XCTestExpectation(description: "")], timeout: 1)
XCTAssertEqual(delegate.didUpdateAuthenticationStateCallCount, 2)
}

Expand Down

0 comments on commit 675e065

Please sign in to comment.