Skip to content

Commit

Permalink
DTPOMERSER-1001 Address Fix issues non_optional_string_data_conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
grmeyer-hw-dev committed Jul 7, 2024
1 parent 47b2f88 commit 64a22c1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class AuthenticationTokenProvider: HyperwalletAuthenticationTokenProvider
let task = defaultSession.dataTask(with: request) {(data, response, error) in
DispatchQueue.main.async {
guard let data = data,
let clientToken = String(data: data, encoding: .utf8),
let clientToken = String(data: data, as: UTF8.self),
let response = response as? HTTPURLResponse else {
completionHandler(nil, HyperwalletAuthenticationErrorType.unexpected(error?.localizedDescription ??
"authentication token cannot be retrieved"))
Expand Down
4 changes: 2 additions & 2 deletions Tests/AnyCodableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AnyCodableTests: XCTestCase {

// Then
XCTAssertNotNil(jsonBody)
let jsonBodyString = String(data: jsonBody, encoding: .utf8)!
let jsonBodyString = String(data: jsonBody, as: UTF8.self)

Check failure on line 23 in Tests/AnyCodableTests.swift

View workflow job for this annotation

GitHub Actions / Test - macos-13 - 15.2 - unit_tests

incorrect argument label in call (have 'data:as:', expected 'decoding:as:')
XCTAssertTrue(((jsonBodyString.contains("USD"))))
}

Expand Down Expand Up @@ -69,7 +69,7 @@ class AnyCodableTests: XCTestCase {

func testDecode_arraySupportedTypes() {
// Given
let jsonBody = "[1, \"String\", 1.2, true, null]".data(using: .utf8)!
let jsonBody = Data("[1, \"String\", 1.2, true, null]".utf8)

// When
let result = try! JSONDecoder().decode(Array<AnyCodable>.self, from: jsonBody)
Expand Down
10 changes: 5 additions & 5 deletions Tests/HTTPTransactionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ class HTTPTransactionTests: XCTestCase {
func testPerformGraphQl_emptyResponseData_returnNilDataAndGraphQlErrors() {
// Given - SDK is initialized

let graphQlResponse = """
let graphQlResponse = Data("""
{}
""".data(using: .utf8)
""".utf8)
var response: Connection<HyperwalletTransferMethodConfiguration>?
var hyperwalletError: HyperwalletErrorType?

Expand Down Expand Up @@ -248,7 +248,7 @@ class HTTPTransactionTests: XCTestCase {
currency: "ARS",
transferMethodType: "BANK_ACCOUNT",
profile: "INDIVIDUAL")
httpClientMock.data = "{}".data(using: .utf8)
httpClientMock.data = Data("{}".utf8)
httpClientMock.urlResponse = HTTPURLResponse(url: URL(string: "http://localhost")!,
statusCode: 403,
httpVersion: "post",
Expand Down Expand Up @@ -305,7 +305,7 @@ class HTTPTransactionTests: XCTestCase {
var response: [String: String]?
var hyperwalletError: HyperwalletErrorType?

httpClientMock.data = "{}".data(using: .utf8)
httpClientMock.data = Data("{}".utf8)
httpClientMock.urlResponse = HTTPURLResponse(url: URL(string: "http://localhost")!,
statusCode: 403,
httpVersion: "post",
Expand Down Expand Up @@ -632,7 +632,7 @@ class HTTPTransactionTests: XCTestCase {

let requestHandler = HTTPTransaction.requestHandler(completionHandler)

requestHandler("{}".data(using: .utf8)!, urlResponse, nil)
requestHandler(Data("{}".utf8), urlResponse, nil)

// Then
XCTAssertNil(response, "The response should be null")
Expand Down
4 changes: 2 additions & 2 deletions Tests/Helper/HTTPClientMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import Foundation
class HTTPClientMock: HTTPClientProtocol {
var hasPerformed = false
var request: URLRequest?
var data: Data? = "{}".data(using: .utf8)
var data: Data? = Data("{}".utf8)
var urlResponse: URLResponse?
var error: Error?

/// Resets mock status
func reset() {
hasPerformed = false
request = nil
data = "{}".data(using: .utf8)
data = Data("{}".utf8)
urlResponse = nil
error = nil
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/TransactionTypeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ class TransactionTypeTests: XCTestCase {
if httpMethod == .get {
XCTAssertNil(urlRequest.httpBody, "The HTTP body should be nil")
} else {
let httpBody = String(data: urlRequest.httpBody!, encoding: .utf8)
let httpBody = String(data: urlRequest.httpBody!, as: UTF8.self)
let payloadData = try JSONEncoder().encode(payload)
let payloadString = String(data: payloadData, encoding: .utf8)
let payloadString = String(data: payloadData, as: UTF8.self)
XCTAssertEqual(httpBody, payloadString, "The HTTP body should be equals to payload")
}

Expand Down Expand Up @@ -165,7 +165,7 @@ class TransactionTypeTests: XCTestCase {
if httpMethod == .get {
XCTAssertNil(urlRequest.httpBody, "The HTTP body should be nil")
} else {
let query = String(data: urlRequest.httpBody!, encoding: .utf8)
let query = String(data: urlRequest.httpBody!, as: UTF8.self)
let payloadString = payload.toGraphQl(userToken: configuration.userToken)
XCTAssertEqual(query, payloadString, "The HTTP body should be equals to payload")
}
Expand Down

0 comments on commit 64a22c1

Please sign in to comment.