-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #780 from DeluxeAlonso/feature/unit-tests
Feature/unit tests
- Loading branch information
Showing
1 changed file
with
111 additions
and
0 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
NetworkInfrastructure/NetworkInfrastructureTests/Services/AccountClientTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// | ||
// AccountClientTests.swift | ||
// NetworkInfrastructure-Unit-NetworkInfrastructureTests | ||
// | ||
// Created by Alonso on 3/09/23. | ||
// | ||
|
||
import XCTest | ||
@testable import NetworkInfrastructure | ||
|
||
final class AccountClientTests: XCTestCase { | ||
|
||
private var urlSession: MockURLSession! | ||
private var accountClient: AccountClient! | ||
|
||
override func setUpWithError() throws { | ||
try super.setUpWithError() | ||
urlSession = MockURLSession() | ||
accountClient = AccountClient(session: urlSession) | ||
|
||
} | ||
|
||
override func tearDownWithError() throws { | ||
urlSession = nil | ||
accountClient = nil | ||
try super.tearDownWithError() | ||
} | ||
|
||
func testGetFavoriteListSuccess() 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 favorite list success") | ||
// Act | ||
accountClient.getFavoriteList(page: 1, sortBy: .createdAtAsc, sessionId: "", accountId: 1) { result in | ||
switch result { | ||
case .success: | ||
break | ||
case .failure: | ||
XCTFail("Get favorite list error") | ||
} | ||
expectation.fulfill() | ||
} | ||
// Assert | ||
wait(for: [expectation], timeout: 1.0) | ||
} | ||
|
||
func testGetFavoriteListError() throws { | ||
// Arrange | ||
urlSession.dataTaskWithRequestCompletionHandler = (nil, nil, nil) | ||
let expectation = XCTestExpectation(description: "Get favorite list error") | ||
// Act | ||
accountClient.getFavoriteList(page: 1, sortBy: .createdAtAsc, sessionId: "", accountId: 1) { result in | ||
switch result { | ||
case .success: | ||
XCTFail("Get favorite list success") | ||
case .failure: | ||
break | ||
} | ||
expectation.fulfill() | ||
} | ||
// Assert | ||
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) | ||
} | ||
|
||
} |