Skip to content

Commit

Permalink
Merge pull request #788 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 13, 2023
2 parents 73aec98 + b37282d commit 24f3061
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2019 Alonso. All rights reserved.
//

struct AccessToken: Decodable {
struct AccessToken: Codable {

let token: String
let accountId: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,45 @@ final class AuthClientTests: XCTestCase {
wait(for: [expectation], timeout: 1.0)
}

func testGetAccessTokenSuccess() throws {
// Arrange
let data = try JSONEncoder().encode(AccessToken(token: "", accountId: ""))
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 access token success")
// Act
authClient.getAccessToken(with: "", requestToken: "") { result in
switch result {
case .success:
break
case .failure:
XCTFail("Get access token error")
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

func testGetAccessTokenError() throws {
// Arrange
urlSession.dataTaskWithRequestCompletionHandler = (nil, nil, nil)
let expectation = XCTestExpectation(description: "Get access token error")
// Act
authClient.getAccessToken(with: "", requestToken: "") { result in
switch result {
case .success:
XCTFail("Get access token success")
case .failure:
break
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

}

0 comments on commit 24f3061

Please sign in to comment.