Skip to content

Commit

Permalink
Merge pull request #777 from DeluxeAlonso/feature/unit-tests
Browse files Browse the repository at this point in the history
Feature/unit tests
  • Loading branch information
DeluxeAlonso authored Sep 1, 2023
2 parents 363a79d + f8d5b11 commit 75d9244
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UpcomingMoviesDomain

struct Cast: Decodable {
struct Cast: Codable {

let id: Int
let character: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UpcomingMoviesDomain

struct Crew: Decodable {
struct Crew: Codable {

let id: Int
let job: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UpcomingMoviesDomain

struct CreditResult: Decodable {
struct CreditResult: Codable {

let id: Int
let cast: [Cast]
Expand Down
41 changes: 41 additions & 0 deletions NetworkInfrastructure/Services/MovieClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,45 @@ final class MovieClientTests: XCTestCase {
wait(for: [expectation], timeout: 1.0)
}

func testGetMovieCreditsError() throws {
// Arrange
urlSession.dataTaskWithRequestCompletionHandler = (nil, nil, nil)
let expectation = XCTestExpectation(description: "Get movie credits error")
// Act
movieClient.getMovieCredits(with: 1) { result in
switch result {
case .success:
XCTFail("Get movie credits success")
case .failure:
break
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

func testGetMovieCreditsSuccess() throws {
// Arrange
let data = try JSONEncoder().encode(CreditResult(id: 1, cast: [], crew: []))
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 movie credits success")
// Act
movieClient.getMovieCredits(with: 1) { result in
switch result {
case .success:
break
case .failure:
XCTFail("Get movie credits error")
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

}

0 comments on commit 75d9244

Please sign in to comment.