Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/unit tests #759

Merged
merged 4 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import XCTest
@testable import UpcomingMovies
import UpcomingMoviesDomain
@testable import NetworkInfrastructure

final class MovieCreditsViewModelTests: XCTestCase {

Expand Down Expand Up @@ -70,13 +69,14 @@ final class MovieCreditsViewModelTests: XCTestCase {

func testGetMovieCreditsError() {
// Arrange
let errorToTest = TestError()
let expectation = XCTestExpectation(description: "Should get error state")
// Act
viewModelToTest.viewState.bind { state in
XCTAssertEqual(state, .error(APIError.badRequest))
XCTAssertEqual(state, .error(errorToTest))
expectation.fulfill()
}
mockInteractor.getMovieCreditsResult = Result.failure(APIError.badRequest)
mockInteractor.getMovieCreditsResult = Result.failure(errorToTest)
viewModelToTest.getMovieCredits(showLoader: false)
// Assert
wait(for: [expectation], timeout: 1.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import XCTest
@testable import UpcomingMovies
import UpcomingMoviesDomain
@testable import NetworkInfrastructure

final class MovieDetailViewModelTests: XCTestCase {

Expand Down Expand Up @@ -92,7 +91,7 @@ final class MovieDetailViewModelTests: XCTestCase {
viewModelToTest.showErrorRetryView.bind { _ in
expectation.fulfill()
}
mockInteractor.getMovieDetailResult = Result.failure(APIError.badRequest)
mockInteractor.getMovieDetailResult = Result.failure(TestError())
viewModelToTest.getMovieDetail(showLoader: false)
// Assert
wait(for: [expectation], timeout: 1.0)
Expand Down Expand Up @@ -198,7 +197,7 @@ final class MovieDetailViewModelTests: XCTestCase {
let viewModelToTest = createSUT(with: 1, title: "Title")
viewModelToTest.movieAccountState.value = .init(.init(favorite: true, watchlist: false))
let addToWatchListAction = viewModelToTest.getAvailableAlertActions().last
let errorToTest = APIError.badRequest
let errorToTest = TestError()
mockInteractor.addToWatchlistResult = .failure(errorToTest)
let expectation = XCTestExpectation(description: "showErrorAlert event should be sent")
viewModelToTest.showErrorAlert.bind { error in
Expand Down Expand Up @@ -233,7 +232,7 @@ final class MovieDetailViewModelTests: XCTestCase {
let viewModelToTest = createSUT(with: 1, title: "Title")
viewModelToTest.movieAccountState.value = .init(.init(favorite: true, watchlist: true))
let removeFromWatchListAction = viewModelToTest.getAvailableAlertActions().last
let errorToTest = APIError.badRequest
let errorToTest = TestError()
mockInteractor.removeFromWatchlistResult = .failure(errorToTest)
let expectation = XCTestExpectation(description: "showErrorAlert event should be sent")
viewModelToTest.showErrorAlert.bind { error in
Expand Down Expand Up @@ -286,7 +285,7 @@ final class MovieDetailViewModelTests: XCTestCase {
// Arrange
let viewModelToTest = createSUT(with: 1, title: "Title")
viewModelToTest.movieAccountState.value = .init(.init(favorite: true, watchlist: true))
let errorToTest = APIError.badRequest
let errorToTest = TestError()
mockInteractor.markMovieAsFavoriteResult = .failure(errorToTest)
let expectation = XCTestExpectation(description: "showErrorAlert event should be sent")
viewModelToTest.showErrorAlert.bind { error in
Expand Down Expand Up @@ -329,7 +328,7 @@ final class MovieDetailViewModelTests: XCTestCase {
// Arrange
let viewModelToTest = createSUT(with: 1, title: "Title")
viewModelToTest.movieAccountState.value = .init(.init(favorite: false, watchlist: true))
let errorToTest = APIError.badRequest
let errorToTest = TestError()
mockInteractor.markMovieAsFavoriteResult = .failure(errorToTest)
let expectation = XCTestExpectation(description: "showErrorAlert event should be sent")
viewModelToTest.showErrorAlert.bind { error in
Expand Down Expand Up @@ -364,7 +363,7 @@ final class MovieDetailViewModelTests: XCTestCase {
// Arrange
let viewModelToTest = createSUT(with: 1, title: "Title")
mockInteractor.isUserSignedInResult = true
mockInteractor.getMovieAccountStateResult = .failure(APIError.badRequest)
mockInteractor.getMovieAccountStateResult = .failure(TestError())
let expectation = XCTestExpectation(description: "movieAccountState event should be sent")
viewModelToTest.movieAccountState.bind { movieAccountStateModel in
XCTAssertNil(movieAccountStateModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import XCTest
@testable import UpcomingMovies
import UpcomingMoviesDomain
@testable import NetworkInfrastructure

final class UpcomingMoviesViewModelTests: XCTestCase {

Expand Down Expand Up @@ -85,7 +84,7 @@ final class UpcomingMoviesViewModelTests: XCTestCase {

func testGetMoviesError() {
// Arrange
let errorToTest = APIError.badRequest
let errorToTest = TestError()
let expectation = XCTestExpectation(description: "Should get error state")
// Act
viewModelToTest.viewState.bind { state in
Expand Down
Loading