Skip to content

Commit

Permalink
Merge pull request #775 from DeluxeAlonso/feature/unit-tests
Browse files Browse the repository at this point in the history
Feature/unit tests
  • Loading branch information
DeluxeAlonso authored Aug 30, 2023
2 parents ff677a9 + e88aa61 commit a806944
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UpcomingMoviesDomain

struct Video: Decodable {
struct Video: Codable {

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

import UpcomingMoviesDomain

public struct VideoResult: Decodable {
public struct VideoResult: Codable {

let results: [Video]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation

// swiftlint:disable large_tuple
final class MockURLSession: URLSession {

var dataTaskWithRequestCompletionHandler: (Data?, URLResponse?, Error?) = (nil, nil, nil)
Expand Down
52 changes: 51 additions & 1 deletion NetworkInfrastructure/Services/MovieClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import XCTest
@testable import NetworkInfrastructure

// swiftlint:disable all
final class MovieClientTests: XCTestCase {

private var urlSession: MockURLSession!
Expand Down Expand Up @@ -292,7 +293,15 @@ final class MovieClientTests: XCTestCase {

func testGetMovieDetailSuccess() throws {
// Arrange
let data = try JSONEncoder().encode(MovieDetailResult(id: 1, title: "", genres: [], overview: "", posterPath: nil, backdropPath: nil, releaseDate: "", voteAverage: nil))
let movieDetailResult = MovieDetailResult(id: 1,
title: "",
genres: [],
overview: "",
posterPath: nil,
backdropPath: nil,
releaseDate: "",
voteAverage: nil)
let data = try JSONEncoder().encode(movieDetailResult)
guard let url = URL(string: "www.google.com") else {
XCTFail("Invalid URL")
return
Expand All @@ -313,4 +322,45 @@ final class MovieClientTests: XCTestCase {
wait(for: [expectation], timeout: 1.0)
}

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class MockAuthPermissionCoordinator: AuthPermissionCoordinatorProtocol {
var dismissResult: Void?
private(set) var dismissCallCount = 0
func dismiss(completion: (() -> Void)?) {
if let dismissResult {
if dismissResult != nil {
completion?()
}
dismissCallCount += 1
Expand Down

0 comments on commit a806944

Please sign in to comment.