-
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 #787 from DeluxeAlonso/feature/unit-tests
Feature/unit tests
- Loading branch information
Showing
2 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
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
69 changes: 69 additions & 0 deletions
69
NetworkInfrastructure/NetworkInfrastructureTests/Services/AuthClientTests.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,69 @@ | ||
// | ||
// AuthClientTests.swift | ||
// NetworkInfrastructure-Unit-NetworkInfrastructureTests | ||
// | ||
// Created by Alonso on 12/09/23. | ||
// | ||
|
||
import XCTest | ||
@testable import NetworkInfrastructure | ||
|
||
final class AuthClientTests: XCTestCase { | ||
|
||
private var urlSession: MockURLSession! | ||
private var authClient: AuthClient! | ||
|
||
override func setUpWithError() throws { | ||
try super.setUpWithError() | ||
urlSession = MockURLSession() | ||
authClient = AuthClient(session: urlSession) | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
urlSession = nil | ||
authClient = nil | ||
try super.tearDownWithError() | ||
} | ||
|
||
func testGetRequestTokenSuccess() throws { | ||
// Arrange | ||
let data = try JSONEncoder().encode(RequestTokenResult(success: true, token: "")) | ||
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 request token success") | ||
// Act | ||
authClient.getRequestToken(with: "") { result in | ||
switch result { | ||
case .success: | ||
break | ||
case .failure: | ||
XCTFail("Get request token error") | ||
} | ||
expectation.fulfill() | ||
} | ||
// Assert | ||
wait(for: [expectation], timeout: 1.0) | ||
} | ||
|
||
func testGetRequestTokenError() throws { | ||
// Arrange | ||
urlSession.dataTaskWithRequestCompletionHandler = (nil, nil, nil) | ||
let expectation = XCTestExpectation(description: "Get request token error") | ||
// Act | ||
authClient.getRequestToken(with: "") { result in | ||
switch result { | ||
case .success: | ||
XCTFail("Get request token success") | ||
case .failure: | ||
break | ||
} | ||
expectation.fulfill() | ||
} | ||
// Assert | ||
wait(for: [expectation], timeout: 1.0) | ||
} | ||
|
||
} |