Skip to content

Commit

Permalink
Merge pull request #785 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 10, 2023
2 parents aa00134 + 1b0c12e commit a7dbe2c
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 MarkAsFavoriteResult: Decodable {
struct MarkAsFavoriteResult: Codable {

let statusCode: Int
let statusMessage: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,45 @@ final class AccountClientTests: XCTestCase {
wait(for: [expectation], timeout: 1.0)
}

func testMarkAsFavoriteSuccess() throws {
// Arrange
let data = try JSONEncoder().encode(MarkAsFavoriteResult(statusCode: 200, statusMessage: ""))
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: "Mark as favorite success")
// Act
accountClient.markAsFavorite(1, sessionId: "", accountId: 1, favorite: true) { result in
switch result {
case .success:
break
case .failure:
XCTFail("Mark as favorite error")
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

func testMarkAsFavoriteError() throws {
// Arrange
urlSession.dataTaskWithRequestCompletionHandler = (nil, nil, nil)
let expectation = XCTestExpectation(description: "Mark as favorite error")
// Act
accountClient.markAsFavorite(1, sessionId: "", accountId: 1, favorite: true) { result in
switch result {
case .success:
XCTFail("Mark as favorite success")
case .failure:
break
}
expectation.fulfill()
}
// Assert
wait(for: [expectation], timeout: 1.0)
}

}

0 comments on commit a7dbe2c

Please sign in to comment.