Skip to content

Commit

Permalink
Merge pull request #789 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 14, 2023
2 parents 24f3061 + ff0f5a2 commit c5bad2d
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 SessionResult: Decodable {
struct SessionResult: Codable {

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

func testCreateSessionIdSuccess() throws {
// Arrange
let data = try JSONEncoder().encode(SessionResult(success: true, sessionId: ""))
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: "Create session id success")
// Act
authClient.createSessionId(with: "") { result in
switch result {
case .success:
break
case .failure:
XCTFail("Create session id error")
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

func testCreateSessionIdError() throws {
// Arrange
urlSession.dataTaskWithRequestCompletionHandler = (nil, nil, nil)
let expectation = XCTestExpectation(description: "Create session id error")
// Act
authClient.createSessionId(with: "") { result in
switch result {
case .success:
XCTFail("Create session id success")
case .failure:
break
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

}

0 comments on commit c5bad2d

Please sign in to comment.