From 64a22c1839e0129b24b6ca677a63f63187ae4454 Mon Sep 17 00:00:00 2001 From: Gustavo Meyer Date: Sun, 7 Jul 2024 11:56:38 -0700 Subject: [PATCH] DTPOMERSER-1001 Address Fix issues non_optional_string_data_conversion --- README.md | 2 +- Tests/AnyCodableTests.swift | 4 ++-- Tests/HTTPTransactionTests.swift | 10 +++++----- Tests/Helper/HTTPClientMock.swift | 4 ++-- Tests/TransactionTypeTests.swift | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 62497014..800dfc57 100644 --- a/README.md +++ b/README.md @@ -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")) diff --git a/Tests/AnyCodableTests.swift b/Tests/AnyCodableTests.swift index 717956d1..2eca3515 100644 --- a/Tests/AnyCodableTests.swift +++ b/Tests/AnyCodableTests.swift @@ -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) XCTAssertTrue(((jsonBodyString.contains("USD")))) } @@ -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.self, from: jsonBody) diff --git a/Tests/HTTPTransactionTests.swift b/Tests/HTTPTransactionTests.swift index 5878ba3b..179e633f 100644 --- a/Tests/HTTPTransactionTests.swift +++ b/Tests/HTTPTransactionTests.swift @@ -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? var hyperwalletError: HyperwalletErrorType? @@ -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", @@ -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", @@ -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") diff --git a/Tests/Helper/HTTPClientMock.swift b/Tests/Helper/HTTPClientMock.swift index d6779dac..3e645793 100644 --- a/Tests/Helper/HTTPClientMock.swift +++ b/Tests/Helper/HTTPClientMock.swift @@ -4,7 +4,7 @@ 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? @@ -12,7 +12,7 @@ class HTTPClientMock: HTTPClientProtocol { func reset() { hasPerformed = false request = nil - data = "{}".data(using: .utf8) + data = Data("{}".utf8) urlResponse = nil error = nil } diff --git a/Tests/TransactionTypeTests.swift b/Tests/TransactionTypeTests.swift index e7449933..956920cc 100644 --- a/Tests/TransactionTypeTests.swift +++ b/Tests/TransactionTypeTests.swift @@ -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") } @@ -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") }