From 9cc5808d62788d4038e624f327945c8e5086091c Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Sun, 5 Jan 2025 21:05:45 +0100 Subject: [PATCH 1/5] Remove some unused code --- .../WordPressAuthenticator.swift | 25 --------- .../WordPressAuthenticatorTests.swift | 54 ------------------- 2 files changed, 79 deletions(-) diff --git a/WooCommerce/WordPressAuthenticator/Authenticator/WordPressAuthenticator.swift b/WooCommerce/WordPressAuthenticator/Authenticator/WordPressAuthenticator.swift index e4ac4ce1162..2f729720461 100644 --- a/WooCommerce/WordPressAuthenticator/Authenticator/WordPressAuthenticator.swift +++ b/WooCommerce/WordPressAuthenticator/Authenticator/WordPressAuthenticator.swift @@ -99,26 +99,6 @@ import WordPressUI // MARK: - Public Methods - public func supportPushNotificationReceived() { - NotificationCenter.default.post(name: .wordpressSupportNotificationReceived, object: nil) - } - - public func supportPushNotificationCleared() { - NotificationCenter.default.post(name: .wordpressSupportNotificationCleared, object: nil) - } - - /// Indicates if the specified ViewController belongs to the Authentication Flow, or not. - /// - public class func isAuthenticationViewController(_ viewController: UIViewController) -> Bool { - return viewController is NUXViewControllerBase - } - - /// Indicates if the received URL is a Google Authentication Callback. - /// - @objc public func isGoogleAuthUrl(_ url: URL) -> Bool { - return url.absoluteString.hasPrefix(configuration.googleLoginScheme) - } - /// Indicates if the received URL is a WordPress.com Authentication Callback. /// @objc public func isWordPressAuthUrl(_ url: URL) -> Bool { @@ -134,11 +114,6 @@ import WordPressUI // MARK: - Helpers for presenting the login flow - /// Used to present the new login flow from the app delegate - @objc public class func showLoginFromPresenter(_ presenter: UIViewController, animated: Bool) { - showLogin(from: presenter, animated: animated) - } - /// Shows login UI from the given presenter view controller. /// /// - Parameters: diff --git a/WooCommerce/WordPressAuthenticatorTests/Authenticator/WordPressAuthenticatorTests.swift b/WooCommerce/WordPressAuthenticatorTests/Authenticator/WordPressAuthenticatorTests.swift index b444d0be942..c4fb5a9a980 100644 --- a/WooCommerce/WordPressAuthenticatorTests/Authenticator/WordPressAuthenticatorTests.swift +++ b/WooCommerce/WordPressAuthenticatorTests/Authenticator/WordPressAuthenticatorTests.swift @@ -55,50 +55,7 @@ class WordPressAuthenticatorTests: XCTestCase { XCTAssertEqual(correctedURL, url) } - // MARK: WordPressAuthenticator Notification Tests - func testDispatchesSupportPushNotificationReceived() { - let authenticator = WordpressAuthenticatorProvider.getWordpressAuthenticator() - _ = expectation(forNotification: .wordpressSupportNotificationReceived, object: nil, handler: nil) - - authenticator.supportPushNotificationReceived() - - waitForExpectations(timeout: timeout, handler: nil) - } - - func testDispatchesSupportPushNotificationCleared() { - let authenticator = WordpressAuthenticatorProvider.getWordpressAuthenticator() - _ = expectation(forNotification: .wordpressSupportNotificationCleared, object: nil, handler: nil) - - authenticator.supportPushNotificationCleared() - - waitForExpectations(timeout: timeout, handler: nil) - } - // MARK: View Tests - func testWordpressAuthIsAuthenticationViewController() { - let loginViewcontroller = LoginViewController() - let nuxViewController = NUXViewController() - let nuxTableViewController = NUXTableViewController() - let basicViewController = UIViewController() - - XCTAssertTrue(WordPressAuthenticator.isAuthenticationViewController(loginViewcontroller)) - XCTAssertTrue(WordPressAuthenticator.isAuthenticationViewController(nuxViewController)) - XCTAssertTrue(WordPressAuthenticator.isAuthenticationViewController(nuxTableViewController)) - XCTAssertFalse(WordPressAuthenticator.isAuthenticationViewController(basicViewController)) - } - - func testShowLoginFromPresenterReturnsLoginInitialVC() { - let presenterSpy = ModalViewControllerPresentingSpy() - let expectation = XCTNSPredicateExpectation(predicate: NSPredicate(block: { (_, _) -> Bool in - return presenterSpy.presentedVC != nil - }), object: .none) - - WordPressAuthenticator.showLoginFromPresenter(presenterSpy, animated: true) - wait(for: [expectation], timeout: timeout) - - XCTAssertTrue(presenterSpy.presentedVC is LoginNavigationController) - } - func testShowLoginForJustWPComPresentsCorrectVC() { let presenterSpy = ModalViewControllerPresentingSpy() let expectation = XCTNSPredicateExpectation(predicate: NSPredicate(block: { (_, _) -> Bool in @@ -164,17 +121,6 @@ class WordPressAuthenticatorTests: XCTestCase { } // MARK: WordPressAuthenticator URL verification Tests - func testIsGoogleAuthURL() { - let authenticator = WordpressAuthenticatorProvider.getWordpressAuthenticator() - let googleURL = URL(string: "com.googleuserconsent.apps/82ekn2932nub23h23hn3")! - let magicLinkURL = URL(string: "https://magic-login")! - let wordpressComURL = URL(string: "https://WordPress.com")! - - XCTAssertTrue(authenticator.isGoogleAuthUrl(googleURL)) - XCTAssertFalse(authenticator.isGoogleAuthUrl(magicLinkURL)) - XCTAssertFalse(authenticator.isGoogleAuthUrl(wordpressComURL)) - } - func testIsWordPressAuthURL() { let authenticator = WordpressAuthenticatorProvider.getWordpressAuthenticator() let magicLinkURL = URL(string: "https://magic-login")! From cce43dcd5b8b7eb3d6cb650557faeb2013305e86 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Sun, 5 Jan 2025 21:33:17 +0100 Subject: [PATCH 2/5] Delete duplicated imports in WordPressAuthenticator header --- .../WordPressAuthenticator.h | 47 +------------------ 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/WooCommerce/WordPressAuthenticator/WordPressAuthenticator.h b/WooCommerce/WordPressAuthenticator/WordPressAuthenticator.h index ba674f8b8ee..845e776cdda 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressAuthenticator.h +++ b/WooCommerce/WordPressAuthenticator/WordPressAuthenticator.h @@ -57,54 +57,9 @@ FOUNDATION_EXPORT const unsigned char WordPressAuthenticatorVersionString[]; #import #import #import - -// --- // -#import -#import -#import -#import -#import - -#import -#import -#import - -#import -#import -#import +// Used _somewhere_ which I haven't followed up yet #import -#import -#import -#import -#import -#import -#import #import -#import -#import -#import -#import -#import -#import -#import -#import #import #import #import -#import - -//#import -//#import -//#import -//#import -//#import -//#import -//#import -//#import -//#import -//#import -//#import - -//#import - -//#import From 84dc94e690d4232e41f15c62f9c91e50b310c240 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Sun, 5 Jan 2025 21:35:55 +0100 Subject: [PATCH 3/5] Consolidate logging in WordPressAuth + WordPressKit --- .../WooCommerce.xcodeproj/project.pbxproj | 1 - .../WordPressAuthenticator.h | 1 - .../CoreAPI/WordPressComOAuthClient.swift | 6 +-- .../CoreAPI/WordPressOrgXMLRPCValidator.swift | 18 +++---- .../CoreAPI/WordPressRSDParser.swift | 2 +- .../WordPressKit/Logging/WPKitLogging.h | 22 --------- .../WordPressKit/Logging/WPKitLogging.m | 49 ------------------- .../WordPressKit/Logging/WPKitLogging.swift | 19 ------- .../Services/AccountSettingsRemote.swift | 2 +- .../AtomicAuthenticationServiceRemote.swift | 8 +-- .../Services/AtomicSiteServiceRemote.swift | 4 +- .../Services/BlogServiceRemoteREST.m | 2 +- .../Services/BlogServiceRemoteXMLRPC.m | 10 ++-- .../BloggingPromptsServiceRemote.swift | 2 +- .../Services/DashboardServiceRemote.swift | 2 +- .../Domains/DomainsServiceRemote.swift | 10 ++-- .../Services/FeatureFlagRemote.swift | 6 +-- .../Services/MediaServiceRemoteREST.m | 6 +-- .../Services/MenusServiceRemote.m | 2 +- .../PlanServiceRemote_ApiVersion1_3.swift | 8 +-- .../Services/PluginServiceRemote.swift | 10 ++-- .../PostServiceRemoteREST+Revisions.swift | 6 +-- ...ReaderPostServiceRemote+RelatedPosts.swift | 4 +- ...eaderPostServiceRemote+Subscriptions.swift | 8 +-- .../Services/ReaderPostServiceRemote+V2.swift | 2 +- .../ReaderSiteSearchServiceRemote.swift | 6 +-- .../Services/ReaderSiteServiceRemote.m | 4 +- .../ReaderTopicServiceRemote+Interests.swift | 6 +-- ...eaderTopicServiceRemote+Subscription.swift | 6 +-- .../Services/RemoteConfigRemote.swift | 6 +-- .../Services/TaxonomyServiceRemoteREST.m | 2 +- .../Services/TaxonomyServiceRemoteXMLRPC.m | 2 +- .../Services/TransactionsServiceRemote.swift | 2 +- ...rdPressComServiceRemote+SiteCreation.swift | 8 +-- ...rdPressComServiceRemote+SiteSegments.swift | 6 +-- ...dPressComServiceRemote+SiteVerticals.swift | 8 +-- ...ComServiceRemote+SiteVerticalsPrompt.swift | 6 +-- .../Utilities/LoggingTests+WordPressKit.swift | 26 +++++----- .../Tests/Utilities/LoggingTests.m | 12 ++--- 39 files changed, 109 insertions(+), 201 deletions(-) delete mode 100644 WooCommerce/WordPressAuthenticator/WordPressKit/Logging/WPKitLogging.h delete mode 100644 WooCommerce/WordPressAuthenticator/WordPressKit/Logging/WPKitLogging.m delete mode 100644 WooCommerce/WordPressAuthenticator/WordPressKit/Logging/WPKitLogging.swift diff --git a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj index 80b4d5454d5..3bad6976fe2 100644 --- a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj +++ b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj @@ -6221,7 +6221,6 @@ WordPressKit/APIInterface/include/WordPressComRESTAPIVersion.h, WordPressKit/APIInterface/include/WordPressComRESTAPIVersionedPathBuilder.h, WordPressKit/BasicBlogAPIObjc/ServiceRemoteWordPressComREST.h, - WordPressKit/Logging/WPKitLogging.h, WordPressKit/Models/RemoteComment.h, WordPressKit/Models/RemoteMedia.h, WordPressKit/Models/RemotePost.h, diff --git a/WooCommerce/WordPressAuthenticator/WordPressAuthenticator.h b/WooCommerce/WordPressAuthenticator/WordPressAuthenticator.h index 845e776cdda..c25899881df 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressAuthenticator.h +++ b/WooCommerce/WordPressAuthenticator/WordPressAuthenticator.h @@ -44,7 +44,6 @@ FOUNDATION_EXPORT const unsigned char WordPressAuthenticatorVersionString[]; #import #import #import -#import #import #import #import diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/CoreAPI/WordPressComOAuthClient.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/CoreAPI/WordPressComOAuthClient.swift index 3060708b86e..26cce1858fe 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/CoreAPI/WordPressComOAuthClient.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/CoreAPI/WordPressComOAuthClient.swift @@ -187,7 +187,7 @@ public final class WordPressComOAuthClient: NSObject { .mapSuccess { response in let responseObject = try JSONSerialization.jsonObject(with: response.body) - // WPKitLogVerbose("Received OAuth2 response: \(self.cleanedUpResponseForLogging(responseObject as AnyObject? ?? "nil" as AnyObject))") + // WPAuthenticatorLoggingVerbose("Received OAuth2 response: \(self.cleanedUpResponseForLogging(responseObject as AnyObject? ?? "nil" as AnyObject))") guard let responseDictionary = responseObject as? [String: AnyObject] else { throw URLError(.cannotParseResponse) @@ -380,7 +380,7 @@ public final class WordPressComOAuthClient: NSObject { .perform(request: builder, errorType: AuthenticationFailure.self) .mapUnacceptableStatusCodeError(AuthenticationFailure.init(response:body:)) .mapSuccess { response in - // WPKitLogVerbose("Received Social Login Oauth response.") + // WPAuthenticatorLoggingVerbose("Received Social Login Oauth response.") // Make sure we received expected data. let responseObject = try? JSONSerialization.jsonObject(with: response.body) @@ -700,7 +700,7 @@ public final class WordPressComOAuthClient: NSObject { .mapSuccess { response in let responseObject = try JSONSerialization.jsonObject(with: response.body) - // WPKitLogVerbose("Received Social Login Oauth response: \(self.cleanedUpResponseForLogging(responseObject as AnyObject? ?? "nil" as AnyObject))") + // WPAuthenticatorLoggingVerbose("Received Social Login Oauth response: \(self.cleanedUpResponseForLogging(responseObject as AnyObject? ?? "nil" as AnyObject))") guard let responseDictionary = responseObject as? [String: AnyObject], let responseData = responseDictionary["data"] as? [String: AnyObject], let authToken = responseData["bearer_token"] as? String else { diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/CoreAPI/WordPressOrgXMLRPCValidator.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/CoreAPI/WordPressOrgXMLRPCValidator.swift index c26d54abd91..643a9e3e06d 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/CoreAPI/WordPressOrgXMLRPCValidator.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/CoreAPI/WordPressOrgXMLRPCValidator.swift @@ -137,13 +137,13 @@ open class WordPressOrgXMLRPCValidator: NSObject { xmlrpcURL = try urlForXMLRPCFromURLString(nextSite, addXMLRPC: true) originalXMLRPCURL = try urlForXMLRPCFromURLString(nextSite, addXMLRPC: false) } catch let error as NSError { - // WPKitLogError(error.localizedDescription) + // WPAuthenticatorLoggingError(error.localizedDescription) errorHandler(error) return } validateXMLRPCURL(xmlrpcURL, success: success, failure: { (error) in - // WPKitLogError(error.localizedDescription) + // WPAuthenticatorLoggingError(error.localizedDescription) if (error.domain == NSURLErrorDomain && error.code == NSURLErrorUserCancelledAuthentication) || (error.domain == NSURLErrorDomain && error.code == NSURLErrorCannotFindHost) || (error.domain == NSURLErrorDomain && error.code == NSURLErrorNetworkConnectionLost) || @@ -152,12 +152,12 @@ open class WordPressOrgXMLRPCValidator: NSObject { return } // Try the original given url as an XML-RPC endpoint - // WPKitLogError("Try the original given url as an XML-RPC endpoint: \(originalXMLRPCURL)") + // WPAuthenticatorLoggingError("Try the original given url as an XML-RPC endpoint: \(originalXMLRPCURL)") self.validateXMLRPCURL(originalXMLRPCURL, success: success, failure: { (error) in - // WPKitLogError(error.localizedDescription) + // WPAuthenticatorLoggingError(error.localizedDescription) // Fetch the original url and look for the RSD link self.guessXMLRPCURLFromHTMLURL(originalXMLRPCURL, success: success, failure: { (error) in - // WPKitLogError(error.localizedDescription) + // WPAuthenticatorLoggingError(error.localizedDescription) errorHandler(error) }) @@ -193,7 +193,7 @@ open class WordPressOrgXMLRPCValidator: NSObject { if baseURL.lastPathComponent != "xmlrpc.php" && addXMLRPC { // Assume the given url is the home page and XML-RPC sits at /xmlrpc.php - // WPKitLogInfo("Assume the given url is the home page and XML-RPC sits at /xmlrpc.php") + // WPAuthenticatorLoggingInfo("Assume the given url is the home page and XML-RPC sits at /xmlrpc.php") resultURLString = "\(resultURLString)/xmlrpc.php" } @@ -263,7 +263,7 @@ open class WordPressOrgXMLRPCValidator: NSObject { private func guessXMLRPCURLFromHTMLURL(_ htmlURL: URL, success: @escaping (_ xmlrpcURL: URL) -> Void, failure: @escaping (_ error: NSError) -> Void) { - // WPKitLogInfo("Fetch the original url and look for the RSD link by using RegExp") + // WPAuthenticatorLoggingInfo("Fetch the original url and look for the RSD link by using RegExp") var isWpSite = false let session = URLSession(configuration: URLSessionConfiguration.ephemeral) @@ -338,7 +338,7 @@ open class WordPressOrgXMLRPCValidator: NSObject { private func guessXMLRPCURLFromRSD(_ rsd: String, success: @escaping (_ xmlrpcURL: URL) -> Void, failure: @escaping (_ error: NSError) -> Void) { - // WPKitLogInfo("Parse the RSD document at the following URL: \(rsd)") + // WPAuthenticatorLoggingInfo("Parse the RSD document at the following URL: \(rsd)") guard let rsdURL = URL(string: rsd) else { failure(WordPressOrgXMLRPCValidatorError.invalid as NSError) return @@ -358,7 +358,7 @@ open class WordPressOrgXMLRPCValidator: NSObject { failure(WordPressOrgXMLRPCValidatorError.invalid as NSError) return } - // WPKitLogInfo("Bingo! We found the WordPress XML-RPC element: \(xmlrpcURL)") + // WPAuthenticatorLoggingInfo("Bingo! We found the WordPress XML-RPC element: \(xmlrpcURL)") self.validateXMLRPCURL(xmlrpcURL, success: success, failure: failure) }) dataTask.resume() diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/CoreAPI/WordPressRSDParser.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/CoreAPI/WordPressRSDParser.swift index 5d6d1f78401..dad58bad2e7 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/CoreAPI/WordPressRSDParser.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/CoreAPI/WordPressRSDParser.swift @@ -47,7 +47,7 @@ open class WordPressRSDParser: NSObject, XMLParserDelegate { } open func parser(_ parser: XMLParser, parseErrorOccurred parseError: Error) { - // WPKitLogInfo("Error parsing RSD: \(parseError)") + // WPAuthenticatorLoggingInfo("Error parsing RSD: \(parseError)") } } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Logging/WPKitLogging.h b/WooCommerce/WordPressAuthenticator/WordPressKit/Logging/WPKitLogging.h deleted file mode 100644 index 71b827aafba..00000000000 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Logging/WPKitLogging.h +++ /dev/null @@ -1,22 +0,0 @@ -#import - -@import WordPressShared; - -NS_ASSUME_NONNULL_BEGIN - -FOUNDATION_EXTERN id _Nullable WPKitGetLoggingDelegate(void); -FOUNDATION_EXTERN void WPKitSetLoggingDelegate(id _Nullable logger); - -FOUNDATION_EXTERN void WPKitLogError(NSString *str, ...) NS_FORMAT_FUNCTION(1, 2); -FOUNDATION_EXTERN void WPKitLogWarning(NSString *str, ...) NS_FORMAT_FUNCTION(1, 2); -FOUNDATION_EXTERN void WPKitLogInfo(NSString *str, ...) NS_FORMAT_FUNCTION(1, 2); -FOUNDATION_EXTERN void WPKitLogDebug(NSString *str, ...) NS_FORMAT_FUNCTION(1, 2); -FOUNDATION_EXTERN void WPKitLogVerbose(NSString *str, ...) NS_FORMAT_FUNCTION(1, 2); - -FOUNDATION_EXTERN void WPKitLogvError(NSString *str, va_list args) NS_FORMAT_FUNCTION(1, 0); -FOUNDATION_EXTERN void WPKitLogvWarning(NSString *str, va_list args) NS_FORMAT_FUNCTION(1, 0); -FOUNDATION_EXTERN void WPKitLogvInfo(NSString *str, va_list args) NS_FORMAT_FUNCTION(1, 0); -FOUNDATION_EXTERN void WPKitLogvDebug(NSString *str, va_list args) NS_FORMAT_FUNCTION(1, 0); -FOUNDATION_EXTERN void WPKitLogvVerbose(NSString *str, va_list args) NS_FORMAT_FUNCTION(1, 0); - -NS_ASSUME_NONNULL_END diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Logging/WPKitLogging.m b/WooCommerce/WordPressAuthenticator/WordPressKit/Logging/WPKitLogging.m deleted file mode 100644 index 59757186ba1..00000000000 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Logging/WPKitLogging.m +++ /dev/null @@ -1,49 +0,0 @@ -#import "WPKitLogging.h" - -static id wordPressKitLogger = nil; - -id _Nullable WPKitGetLoggingDelegate(void) -{ - return wordPressKitLogger; -} - -void WPKitSetLoggingDelegate(id _Nullable logger) -{ - wordPressKitLogger = logger; -} - -#define WPKitLogv(logFunc) \ - ({ \ - id logger = WPKitGetLoggingDelegate(); \ - if (logger == NULL) { \ - NSLog(@"[WordPressKit] Warning: please call `WPKitSetLoggingDelegate` to set a error logger."); \ - return; \ - } \ - if (![logger respondsToSelector:@selector(logFunc)]) { \ - NSLog(@"[WordPressKit] Warning: %@ does not implement " #logFunc, logger); \ - return; \ - } \ - /* Originally `performSelector:withObject:` was used to call the logging function, but for unknown reason */ \ - /* it causes a crash on `objc_retain`. So I have to switch to this strange "syntax" to call the logging function directly. */ \ - [logger logFunc [[NSString alloc] initWithFormat:str arguments:args]]; \ - }) - -#define WPKitLog(logFunc) \ - ({ \ - va_list args; \ - va_start(args, str); \ - WPKitLogv(logFunc); \ - va_end(args); \ - }) - -void WPKitLogError(NSString *str, ...) { WPKitLog(logError:); } -void WPKitLogWarning(NSString *str, ...) { WPKitLog(logWarning:); } -void WPKitLogInfo(NSString *str, ...) { WPKitLog(logInfo:); } -void WPKitLogDebug(NSString *str, ...) { WPKitLog(logDebug:); } -void WPKitLogVerbose(NSString *str, ...) { WPKitLog(logVerbose:); } - -void WPKitLogvError(NSString *str, va_list args) { WPKitLogv(logError:); } -void WPKitLogvWarning(NSString *str, va_list args) { WPKitLogv(logWarning:); } -void WPKitLogvInfo(NSString *str, va_list args) { WPKitLogv(logInfo:); } -void WPKitLogvDebug(NSString *str, va_list args) { WPKitLogv(logDebug:); } -void WPKitLogvVerbose(NSString *str, va_list args) { WPKitLogv(logVerbose:); } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Logging/WPKitLogging.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Logging/WPKitLogging.swift deleted file mode 100644 index f01875b94e7..00000000000 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Logging/WPKitLogging.swift +++ /dev/null @@ -1,19 +0,0 @@ -func WPKitLogError(_ format: String, _ arguments: CVarArg...) { - withVaList(arguments) { WPKitLogvError(format, $0) } -} - -func WPKitLogWarning(_ format: String, _ arguments: CVarArg...) { - withVaList(arguments) { WPKitLogvWarning(format, $0) } -} - -func WPKitLogInfo(_ format: String, _ arguments: CVarArg...) { - withVaList(arguments) { WPKitLogvInfo(format, $0) } -} - -func WPKitLogDebug(_ format: String, _ arguments: CVarArg...) { - withVaList(arguments) { WPKitLogvDebug(format, $0) } -} - -func WPKitLogVerbose(_ format: String, _ arguments: CVarArg...) { - withVaList(arguments) { WPKitLogvVerbose(format, $0) } -} diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/AccountSettingsRemote.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/AccountSettingsRemote.swift index e029ab5d335..a5d8b091724 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/AccountSettingsRemote.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/AccountSettingsRemote.swift @@ -174,7 +174,7 @@ public class AccountSettingsRemote: ServiceRemoteWordPressComREST { let blockEmailNotifications = response["subscription_delivery_email_blocked"] as? Bool, let twoStepEnabled = response["two_step_enabled"] as? Bool else { - WPKitLogError("Error decoding me/settings response: \(responseObject)") + WPAuthenticatorLogError("Error decoding me/settings response: \(responseObject)") throw ResponseError.decodingFailure } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/AtomicAuthenticationServiceRemote.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/AtomicAuthenticationServiceRemote.swift index 2b7d62ac2c9..e83eacb57a5 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/AtomicAuthenticationServiceRemote.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/AtomicAuthenticationServiceRemote.swift @@ -40,13 +40,13 @@ public class AtomicAuthenticationServiceRemote: ServiceRemoteWordPressComREST { private func cookie(from responseObject: Any) throws -> HTTPCookie { guard let response = responseObject as? [String: AnyObject] else { let error = ResponseError.responseIsNotADictionary(response: responseObject) - WPKitLogError("❗️Error: \(error)") + WPAuthenticatorLogError("❗️Error: \(error)") throw error } guard let cookies = response["cookies"] as? [[String: Any]] else { let error = ResponseError.decodingFailure(response: response) - WPKitLogError("❗️Error: \(error)") + WPAuthenticatorLogError("❗️Error: \(error)") throw error } @@ -59,7 +59,7 @@ public class AtomicAuthenticationServiceRemote: ServiceRemoteWordPressComREST { let expires = cookieDictionary["expires"] as? Int else { let error = ResponseError.decodingFailure(response: response) - WPKitLogError("❗️Error: \(error)") + WPAuthenticatorLogError("❗️Error: \(error)") throw error } @@ -73,7 +73,7 @@ public class AtomicAuthenticationServiceRemote: ServiceRemoteWordPressComREST { .expires: expirationDate ]) else { let error = ResponseError.couldNotInstantiateCookie(name: name, value: value, domain: domain, path: path, expires: expirationDate) - WPKitLogError("❗️Error: \(error)") + WPAuthenticatorLogError("❗️Error: \(error)") throw error } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/AtomicSiteServiceRemote.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/AtomicSiteServiceRemote.swift index c6eecfdf6bc..71b013ebf90 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/AtomicSiteServiceRemote.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/AtomicSiteServiceRemote.swift @@ -35,7 +35,7 @@ public final class AtomicSiteServiceRemote: ServiceRemoteWordPressComREST { let response = try JSONDecoder.apiDecoder.decode(AtomicErrorLogsResponse.self, from: data) success(response) } catch { - WPKitLogError("Error parsing campaigns response: \(error), \(responseObject)") + WPAuthenticatorLogError("Error parsing campaigns response: \(error), \(responseObject)") failure(error) } } failure: { error, _ in @@ -79,7 +79,7 @@ public final class AtomicSiteServiceRemote: ServiceRemoteWordPressComREST { let response = try JSONDecoder.apiDecoder.decode(AtomicWebServerLogsResponse.self, from: data) success(response) } catch { - WPKitLogError("Error parsing campaigns response: \(error), \(responseObject)") + WPAuthenticatorLogError("Error parsing campaigns response: \(error), \(responseObject)") failure(error) } } failure: { error, _ in diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/BlogServiceRemoteREST.m b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/BlogServiceRemoteREST.m index abcdff30813..e36e5a95302 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/BlogServiceRemoteREST.m +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/BlogServiceRemoteREST.m @@ -147,7 +147,7 @@ - (void)syncPostTypesWithSuccess:(PostTypesHandler)success return [self remotePostTypeWithDictionary:json]; }]; if (!postTypes.count) { - WPKitLogError(@"Response to %@ did not include post types for site.", requestUrl); + WPAuthenticatorLogError(@"Response to %@ did not include post types for site.", requestUrl); failure(nil); return; } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/BlogServiceRemoteXMLRPC.m b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/BlogServiceRemoteXMLRPC.m index 305208a71e9..c5382490897 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/BlogServiceRemoteXMLRPC.m +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/BlogServiceRemoteXMLRPC.m @@ -84,7 +84,7 @@ - (void)syncPostTypesWithSuccess:(PostTypesHandler)success failure:(void (^)(NSE return [self remotePostTypeFromXMLRPCDictionary:json]; }]; if (!postTypes.count) { - WPKitLogError(@"Response to wp.getPostTypes did not include post types for site."); + WPAuthenticatorLogError(@"Response to wp.getPostTypes did not include post types for site."); failure(nil); return; } @@ -92,7 +92,7 @@ - (void)syncPostTypesWithSuccess:(PostTypesHandler)success failure:(void (^)(NSE success(postTypes); } } failure:^(NSError *error, NSHTTPURLResponse *response) { - WPKitLogError(@"Error syncing post types (%@): %@", response.URL, error); + WPAuthenticatorLogError(@"Error syncing post types (%@): %@", response.URL, error); if (failure) { failure(error); @@ -137,7 +137,7 @@ - (void)syncPostFormatsWithSuccess:(PostFormatsHandler)success failure:(void (^) success(respDict); } } failure:^(NSError *error, NSHTTPURLResponse *response) { - WPKitLogError(@"Error syncing post formats (%@): %@", response.URL, error); + WPAuthenticatorLogError(@"Error syncing post formats (%@): %@", response.URL, error); if (failure) { failure(error); @@ -158,7 +158,7 @@ - (void)syncBlogOptionsWithSuccess:(OptionsHandler)success failure:(void (^)(NSE success(responseObject); } } failure:^(NSError *error, NSHTTPURLResponse *response) { - WPKitLogError(@"Error syncing blog options: %@", error); + WPAuthenticatorLogError(@"Error syncing blog options: %@", error); if (failure) { failure(error); @@ -180,7 +180,7 @@ - (void)updateBlogOptionsWith:(NSDictionary *)remoteBlogOptions success:(Success success(); } } failure:^(NSError *error, NSHTTPURLResponse *response) { - WPKitLogError(@"Error updating blog options: %@", error); + WPAuthenticatorLogError(@"Error updating blog options: %@", error); if (failure) { failure(error); } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/BloggingPromptsServiceRemote.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/BloggingPromptsServiceRemote.swift index af39889b099..5d092a8149c 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/BloggingPromptsServiceRemote.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/BloggingPromptsServiceRemote.swift @@ -103,7 +103,7 @@ open class BloggingPromptsServiceRemote: ServiceRemoteWordPressComREST { // The parameter shouldn't be empty at this point. // If by some chance it is, let's abort and return early. There could be something wrong with the parsing process. guard !parameters.isEmpty else { - WPKitLogError("Error encoding RemoteBloggingPromptsSettings object: \(settings)") + WPAuthenticatorLogError("Error encoding RemoteBloggingPromptsSettings object: \(settings)") completion(.failure(RequestError.encodingFailure)) return } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/DashboardServiceRemote.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/DashboardServiceRemote.swift index 983ff6f5a80..c9707e92ef1 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/DashboardServiceRemote.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/DashboardServiceRemote.swift @@ -28,7 +28,7 @@ open class DashboardServiceRemote: ServiceRemoteWordPressComREST { success(cards) }, failure: { error, _ in failure(error) - WPKitLogError("Error fetching dashboard cards: \(error)") + WPAuthenticatorLogError("Error fetching dashboard cards: \(error)") }) } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/Domains/DomainsServiceRemote.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/Domains/DomainsServiceRemote.swift index 51b5738601d..898ddf9e32e 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/Domains/DomainsServiceRemote.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/Domains/DomainsServiceRemote.swift @@ -118,7 +118,7 @@ public class DomainsServiceRemote: ServiceRemoteWordPressComREST { do { try success(mapDomainsResponse(response)) } catch { - WPKitLogError("Error parsing domains response (\(error)): \(response)") + WPAuthenticatorLogError("Error parsing domains response (\(error)): \(response)") failure(error) } }, failure: { @@ -162,7 +162,7 @@ public class DomainsServiceRemote: ServiceRemoteWordPressComREST { let decodedResult = try JSONDecoder.apiDecoder.decode([WPState].self, from: data) success(decodedResult) } catch { - WPKitLogError("Error parsing State list for country code (\(error)): \(response)") + WPAuthenticatorLogError("Error parsing State list for country code (\(error)): \(response)") failure(error) } }, failure: { error, _ in @@ -184,7 +184,7 @@ public class DomainsServiceRemote: ServiceRemoteWordPressComREST { let decodedResult = try JSONDecoder.apiDecoder.decode(DomainContactInformation.self, from: data) success(decodedResult) } catch { - WPKitLogError("Error parsing DomainContactInformation (\(error)): \(response)") + WPAuthenticatorLogError("Error parsing DomainContactInformation (\(error)): \(response)") failure(error) } }) { (error, _) in @@ -210,7 +210,7 @@ public class DomainsServiceRemote: ServiceRemoteWordPressComREST { let decodedResult = try JSONDecoder.apiDecoder.decode(ValidateDomainContactInformationResponse.self, from: data) success(decodedResult) } catch { - WPKitLogError("Error parsing ValidateDomainContactInformationResponse (\(error)): \(response)") + WPAuthenticatorLogError("Error parsing ValidateDomainContactInformationResponse (\(error)): \(response)") failure(error) } }) { (error, _) in @@ -247,7 +247,7 @@ public class DomainsServiceRemote: ServiceRemoteWordPressComREST { let suggestions = try map(suggestions: response) success(suggestions) } catch { - WPKitLogError("Error parsing domains response (\(error)): \(response)") + WPAuthenticatorLogError("Error parsing domains response (\(error)): \(response)") failure(error) } }, failure: { diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/FeatureFlagRemote.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/FeatureFlagRemote.swift index 205e8b05390..14f48512f4b 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/FeatureFlagRemote.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/FeatureFlagRemote.swift @@ -44,11 +44,11 @@ open class FeatureFlagRemote: ServiceRemoteWordPressComREST { } }, failure: { error, response in - WPKitLogError("Error retrieving remote feature flags") - WPKitLogError("\(error)") + WPAuthenticatorLogError("Error retrieving remote feature flags") + WPAuthenticatorLogError("\(error)") if let response = response { - WPKitLogDebug("Response Code: \(response.statusCode)") + WPAuthenticatorLogDebug("Response Code: \(response.statusCode)") } callback(.failure(error)) diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/MediaServiceRemoteREST.m b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/MediaServiceRemoteREST.m index d1a81b1c5ac..de38ef55cbe 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/MediaServiceRemoteREST.m +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/MediaServiceRemoteREST.m @@ -172,7 +172,7 @@ - (void)uploadMedia:(NSArray *)mediaItems } } } failure:^(NSError *error, NSHTTPURLResponse *httpResponse) { - WPKitLogDebug(@"Error uploading multiple media files: %@", [error localizedDescription]); + WPAuthenticatorLogDebug(@"Error uploading multiple media files: %@", [error localizedDescription]); if (failure) { failure(error); } @@ -225,7 +225,7 @@ - (void)uploadMedia:(RemoteMedia *)media } } failure:^(NSError *error, NSHTTPURLResponse *httpResponse) { - WPKitLogDebug(@"Error uploading file: %@", [error localizedDescription]); + WPAuthenticatorLogDebug(@"Error uploading file: %@", [error localizedDescription]); if (failure) { failure(error); } @@ -235,7 +235,7 @@ - (void)uploadMedia:(RemoteMedia *)media } - (NSError *)processMediaUploadErrors:(NSArray *)errorList { - WPKitLogDebug(@"Error uploading file: %@", errorList); + WPAuthenticatorLogDebug(@"Error uploading file: %@", errorList); NSError * error = nil; if (errorList.count > 0) { NSString *errorMessage = [errorList.firstObject description]; diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/MenusServiceRemote.m b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/MenusServiceRemote.m index d62be23de2a..848f19430f9 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/MenusServiceRemote.m +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/MenusServiceRemote.m @@ -408,7 +408,7 @@ - (NSDictionary *)menuLocationJSONDictionaryFromLocation:(RemoteMenuLocation *)l - (void)handleResponseErrorWithMessage:(NSString *)message url:(NSString *)urlStr failure:(nullable MenusServiceRemoteFailureBlock)failure { - WPKitLogError(@"%@ - URL: %@", message, urlStr); + WPAuthenticatorLogError(@"%@ - URL: %@", message, urlStr); NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:@{NSLocalizedDescriptionKey: message}]; diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/Plans/PlanServiceRemote_ApiVersion1_3.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/Plans/PlanServiceRemote_ApiVersion1_3.swift index b9fefa665cc..f5026a45d7f 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/Plans/PlanServiceRemote_ApiVersion1_3.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/Plans/PlanServiceRemote_ApiVersion1_3.swift @@ -18,9 +18,9 @@ import WordPressShared do { try success(PlanServiceRemote_ApiVersion1_3.mapPlansResponse(response)) } catch { - WPKitLogError("Error parsing plans response for site \(siteID)") - WPKitLogError("\(error)") - WPKitLogDebug("Full response: \(response)") + WPAuthenticatorLoggingError("Error parsing plans response for site \(siteID)") + WPAuthenticatorLoggingError("\(error)") + WPAuthenticatorLoggingDebug("Full response: \(response)") failure(error) } }, @@ -50,7 +50,7 @@ import WordPressShared currentlyActivePlan = decodedResult } } catch let error { - WPKitLogError("Error parsing plans response for site \(error)") + WPAuthenticatorLoggingError("Error parsing plans response for site \(error)") } } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/PluginServiceRemote.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/PluginServiceRemote.swift index a72c30ee780..734d81c30d9 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/PluginServiceRemote.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/PluginServiceRemote.swift @@ -26,7 +26,7 @@ public class PluginServiceRemote: ServiceRemoteWordPressComREST { failure(self.errorFromResponse(response)) } }, failure: { (error, _) in - WPKitLogError("[PluginServiceRemoteError] Error fetching site plugins: \(error)") + WPAuthenticatorLogError("[PluginServiceRemoteError] Error fetching site plugins: \(error)") failure(error) }) } @@ -55,7 +55,7 @@ public class PluginServiceRemote: ServiceRemoteWordPressComREST { } }, failure: { (error, _) in - WPKitLogError("[PluginServiceRemoteError] Error updating plugin: \(error)") + WPAuthenticatorLogError("[PluginServiceRemoteError] Error updating plugin: \(error)") failure(error) }) } @@ -115,7 +115,7 @@ public class PluginServiceRemote: ServiceRemoteWordPressComREST { failure(self.errorFromResponse(response)) } }, failure: { (error, _) in - WPKitLogError("[PluginServiceRemoteError] Error installing plugin: \(error)") + WPAuthenticatorLogError("[PluginServiceRemoteError] Error installing plugin: \(error)") failure(error) } ) @@ -134,7 +134,7 @@ public class PluginServiceRemote: ServiceRemoteWordPressComREST { success: { _, _ in success() }, failure: { (error, _) in - WPKitLogError("[PluginServiceRemoteError] Error removing plugin: \(error)") + WPAuthenticatorLogError("[PluginServiceRemoteError] Error removing plugin: \(error)") failure(error) } ) @@ -154,7 +154,7 @@ public class PluginServiceRemote: ServiceRemoteWordPressComREST { success() }, failure: { (error, _) in - WPKitLogError("[PluginServiceRemoteError] Error modifying plugin: \(error)") + WPAuthenticatorLogError("[PluginServiceRemoteError] Error modifying plugin: \(error)") failure(error) }) } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/PostServiceRemoteREST+Revisions.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/PostServiceRemoteREST+Revisions.swift index 0f9f61c06d6..e1b22d244f2 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/PostServiceRemoteREST+Revisions.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/PostServiceRemoteREST+Revisions.swift @@ -23,7 +23,7 @@ public extension PostServiceRemoteREST { failure(error) } }, failure: { error, _ in - WPKitLogError("\(error)") + WPAuthenticatorLogError("\(error)") failure(error) }) } @@ -49,7 +49,7 @@ public extension PostServiceRemoteREST { success(latestRevision) }, failure: { error, _ in - WPKitLogError("\(error)") + WPAuthenticatorLogError("\(error)") failure(error) } ) @@ -79,7 +79,7 @@ private extension PostServiceRemoteREST { } completion(revisions, nil) } catch { - WPKitLogError("\(error)") + WPAuthenticatorLogError("\(error)") completion(nil, error) } } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderPostServiceRemote+RelatedPosts.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderPostServiceRemote+RelatedPosts.swift index b65851fd9a9..5557912f202 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderPostServiceRemote+RelatedPosts.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderPostServiceRemote+RelatedPosts.swift @@ -35,12 +35,12 @@ extension ReaderPostServiceRemote { success(envelope.posts) } catch { - WPKitLogError("Error parsing the reader related posts response: \(error)") + WPAuthenticatorLogError("Error parsing the reader related posts response: \(error)") failure(error) } }, failure: { (error, _) in - WPKitLogError("Error fetching reader related posts: \(error)") + WPAuthenticatorLogError("Error fetching reader related posts: \(error)") failure(error) } ) diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderPostServiceRemote+Subscriptions.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderPostServiceRemote+Subscriptions.swift index 9661cf4794c..695268de1c1 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderPostServiceRemote+Subscriptions.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderPostServiceRemote+Subscriptions.swift @@ -40,7 +40,7 @@ extension ReaderPostServiceRemote { failure(error) } }) { error, _ in - WPKitLogError("Error fetching subscription status: \(error)") + WPAuthenticatorLogError("Error fetching subscription status: \(error)") failure(error) } } @@ -70,7 +70,7 @@ extension ReaderPostServiceRemote { failure(error) } }) { error, _ in - WPKitLogError("Error subscribing to comments in the post: \(error)") + WPAuthenticatorLogError("Error subscribing to comments in the post: \(error)") failure(error) } } @@ -100,7 +100,7 @@ extension ReaderPostServiceRemote { failure(error) } }) { error, _ in - WPKitLogError("Error unsubscribing from comments in the post: \(error)") + WPAuthenticatorLogError("Error unsubscribing from comments in the post: \(error)") failure(error) } } @@ -138,7 +138,7 @@ extension ReaderPostServiceRemote { success() }, failure: { error, _ in - WPKitLogError("Error updating post subscription: \(error)") + WPAuthenticatorLogError("Error updating post subscription: \(error)") failure(error) }) } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderPostServiceRemote+V2.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderPostServiceRemote+V2.swift index d085ec2e0f5..e61c4c1f230 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderPostServiceRemote+V2.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderPostServiceRemote+V2.swift @@ -24,7 +24,7 @@ extension ReaderPostServiceRemote { let posts = postsDictionary?.compactMap { RemoteReaderPost(dictionary: $0) } ?? [] success(posts, nextPageHandle) }, failure: { error, _ in - WPKitLogError("Error fetching reader posts: \(error)") + WPAuthenticatorLogError("Error fetching reader posts: \(error)") failure(error) }) } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderSiteSearchServiceRemote.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderSiteSearchServiceRemote.swift index ae03296929c..aabccfaf067 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderSiteSearchServiceRemote.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderSiteSearchServiceRemote.swift @@ -45,7 +45,7 @@ public class ReaderSiteSearchServiceRemote: ServiceRemoteWordPressComREST { failure(error) } }, failure: { error, _ in - WPKitLogError("\(error)") + WPAuthenticatorLogError("\(error)") failure(error) }) } @@ -63,8 +63,8 @@ private extension ReaderSiteSearchServiceRemote { let feeds = envelope.feeds.filter({ $0.feedID != nil || $0.blogID != nil }) return (feeds, envelope.total) } catch { - WPKitLogError("\(error)") - WPKitLogDebug("Full response: \(response)") + WPAuthenticatorLogError("\(error)") + WPAuthenticatorLogDebug("Full response: \(response)") throw ReaderSiteSearchServiceRemote.ResponseError.decodingFailure } } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderSiteServiceRemote.m b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderSiteServiceRemote.m index 00d438417ad..56a93c9f24d 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderSiteServiceRemote.m +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderSiteServiceRemote.m @@ -85,7 +85,7 @@ - (void)followSiteAtURL:(NSString *)siteURL success:(void (^)(void))success fail BOOL subscribed = [[dict numberForKey:@"subscribed"] boolValue]; if (!subscribed) { if (failure) { - WPKitLogError(@"Error following site at url: %@", siteURL); + WPAuthenticatorLogError(@"Error following site at url: %@", siteURL); NSError *error = [self errorForUnsuccessfulFollowSite]; failure(error); } @@ -114,7 +114,7 @@ - (void)unfollowSiteAtURL:(NSString *)siteURL success:(void (^)(void))success fa BOOL subscribed = [[dict numberForKey:@"subscribed"] boolValue]; if (subscribed) { if (failure) { - WPKitLogError(@"Error unfollowing site at url: %@", siteURL); + WPAuthenticatorLogError(@"Error unfollowing site at url: %@", siteURL); NSError *error = [self errorForUnsuccessfulFollowSite]; failure(error); } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderTopicServiceRemote+Interests.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderTopicServiceRemote+Interests.swift index 93d064f218b..4f0b7dc1fb5 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderTopicServiceRemote+Interests.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderTopicServiceRemote+Interests.swift @@ -19,11 +19,11 @@ extension ReaderTopicServiceRemote { success(envelope.interests) } catch { - WPKitLogError("Error parsing the reader interests response: \(error)") + WPAuthenticatorLogError("Error parsing the reader interests response: \(error)") failure(error) } }, failure: { error, _ in - WPKitLogError("Error fetching reader interests: \(error)") + WPAuthenticatorLogError("Error fetching reader interests: \(error)") failure(error) }) @@ -39,7 +39,7 @@ extension ReaderTopicServiceRemote { wordPressComRESTAPI.post(path, parameters: parameters, success: { _, _ in success() }) { error, _ in - WPKitLogError("Error fetching reader interests: \(error)") + WPAuthenticatorLogError("Error fetching reader interests: \(error)") failure(error) } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderTopicServiceRemote+Subscription.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderTopicServiceRemote+Subscription.swift index 4e597b0dcf2..a7a6a8adc09 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderTopicServiceRemote+Subscription.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/ReaderTopicServiceRemote+Subscription.swift @@ -82,13 +82,13 @@ extension ReaderTopicServiceRemote { private func POST(with request: ReaderTopicServiceSubscriptionsRequest, parameters: [String: AnyObject]? = nil, success: @escaping () -> Void, failure: @escaping (ReaderTopicServiceError?) -> Void) { let urlRequest = path(forEndpoint: request.path, withVersion: request.apiVersion) - WPKitLogInfo("URL: \(urlRequest)") + WPAuthenticatorLogInfo("URL: \(urlRequest)") wordPressComRESTAPI.post(urlRequest, parameters: parameters, success: { (_, response) in - WPKitLogInfo("Success \(response?.url?.absoluteString ?? "unknown url")") + WPAuthenticatorLogInfo("Success \(response?.url?.absoluteString ?? "unknown url")") success() }) { (error, response) in - WPKitLogError("Error: \(error.localizedDescription)") + WPAuthenticatorLogError("Error: \(error.localizedDescription)") let urlAbsoluteString = response?.url?.absoluteString ?? NSLocalizedString("unknown url", comment: "Used when the response doesn't have a valid url to display") failure(ReaderTopicServiceError.remoteResponse(message: error.localizedDescription, url: urlAbsoluteString)) } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/RemoteConfigRemote.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/RemoteConfigRemote.swift index 4fdc076dd53..cb42cf18d7a 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/RemoteConfigRemote.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/RemoteConfigRemote.swift @@ -24,11 +24,11 @@ open class RemoteConfigRemote: ServiceRemoteWordPressComREST { } }, failure: { error, response in - WPKitLogError("Error retrieving remote config values") - WPKitLogError("\(error)") + WPAuthenticatorLogError("Error retrieving remote config values") + WPAuthenticatorLogError("\(error)") if let response = response { - WPKitLogDebug("Response Code: \(response.statusCode)") + WPAuthenticatorLogDebug("Response Code: \(response.statusCode)") } callback(.failure(error)) diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/TaxonomyServiceRemoteREST.m b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/TaxonomyServiceRemoteREST.m index 77bd045cb51..9964d198667 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/TaxonomyServiceRemoteREST.m +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/TaxonomyServiceRemoteREST.m @@ -344,7 +344,7 @@ - (void)handleResponseErrorWithMessage:(NSString *)message url:(NSString *)urlStr failure:(nullable void(^)(NSError *error))failure { - WPKitLogError(@"%@ - URL: %@", message, urlStr); + WPAuthenticatorLogError(@"%@ - URL: %@", message, urlStr); NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:@{NSLocalizedDescriptionKey: message}]; diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/TaxonomyServiceRemoteXMLRPC.m b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/TaxonomyServiceRemoteXMLRPC.m index e2e9a26de36..70d04a7301e 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/TaxonomyServiceRemoteXMLRPC.m +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/TaxonomyServiceRemoteXMLRPC.m @@ -343,7 +343,7 @@ - (void)handleResponseErrorWithMessage:(NSString *)message method:(NSString *)methodStr failure:(nullable void(^)(NSError *error))failure { - WPKitLogError(@"%@ - method: %@", message, methodStr); + WPAuthenticatorLogError(@"%@ - method: %@", message, methodStr); NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:@{NSLocalizedDescriptionKey: message}]; diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/TransactionsServiceRemote.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/TransactionsServiceRemote.swift index 2ba8bf85fcf..1152679f54e 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/TransactionsServiceRemote.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/TransactionsServiceRemote.swift @@ -28,7 +28,7 @@ import WordPressShared let decodedResult = try JSONDecoder.apiDecoder.decode([WPCountry].self, from: data) success(decodedResult) } catch { - WPKitLogError("Error parsing Supported Countries (\(error)): \(response)") + WPAuthenticatorLogError("Error parsing Supported Countries (\(error)): \(response)") failure(error) } }, failure: { error, _ in diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteCreation.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteCreation.swift index c65f80e5f91..0d3ebfd9316 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteCreation.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteCreation.swift @@ -195,7 +195,7 @@ public extension WordPressComServiceRemote { do { requestParameters = try encodeRequestParameters(request: request) } catch { - WPKitLogError("Failed to encode \(SiteCreationRequest.self) : \(error)") + WPAuthenticatorLogError("Failed to encode \(SiteCreationRequest.self) : \(error)") completion(.failure(SiteCreationError.requestEncodingFailure)) return @@ -205,7 +205,7 @@ public extension WordPressComServiceRemote { path, parameters: requestParameters, success: { [weak self] responseObject, httpResponse in - WPKitLogInfo("\(responseObject) | \(String(describing: httpResponse))") + WPAuthenticatorLogInfo("\(responseObject) | \(String(describing: httpResponse))") guard let self = self else { return @@ -215,12 +215,12 @@ public extension WordPressComServiceRemote { let response = try self.decodeResponse(responseObject: responseObject) completion(.success(response)) } catch { - WPKitLogError("Failed to decode \(SiteCreationResponse.self) : \(error.localizedDescription)") + WPAuthenticatorLogError("Failed to decode \(SiteCreationResponse.self) : \(error.localizedDescription)") completion(.failure(SiteCreationError.responseDecodingFailure)) } }, failure: { error, httpResponse in - WPKitLogError("\(error) | \(String(describing: httpResponse))") + WPAuthenticatorLogError("\(error) | \(String(describing: httpResponse))") completion(.failure(SiteCreationError.serviceFailure)) }) } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteSegments.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteSegments.swift index 179d0a2157d..b98abd1eabc 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteSegments.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteSegments.swift @@ -97,7 +97,7 @@ public extension WordPressComServiceRemote { remotePath, parameters: nil, success: { [weak self] responseObject, httpResponse in - WPKitLogInfo("\(responseObject) | \(String(describing: httpResponse))") + WPAuthenticatorLogInfo("\(responseObject) | \(String(describing: httpResponse))") guard let self = self else { return @@ -108,12 +108,12 @@ public extension WordPressComServiceRemote { let validContent = self.validSegments(response) completion(.success(validContent)) } catch { - WPKitLogError("Failed to decode \([SiteVertical].self) : \(error.localizedDescription)") + WPAuthenticatorLogError("Failed to decode \([SiteVertical].self) : \(error.localizedDescription)") completion(.failure(SiteSegmentsError.responseDecodingFailure)) } }, failure: { error, httpResponse in - WPKitLogError("\(error) | \(String(describing: httpResponse))") + WPAuthenticatorLogError("\(error) | \(String(describing: httpResponse))") completion(.failure(SiteSegmentsError.serviceFailure)) }) } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteVerticals.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteVerticals.swift index 81e54e85775..529c7a6f3d4 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteVerticals.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteVerticals.swift @@ -86,7 +86,7 @@ public extension WordPressComServiceRemote { do { requestParameters = try encodeRequestParameters(request: request) } catch { - WPKitLogError("Failed to encode \(SiteCreationRequest.self) : \(error)") + WPAuthenticatorLogError("Failed to encode \(SiteCreationRequest.self) : \(error)") completion(.failure(SiteVerticalsError.requestEncodingFailure)) return @@ -96,7 +96,7 @@ public extension WordPressComServiceRemote { path, parameters: requestParameters, success: { [weak self] responseObject, httpResponse in - WPKitLogInfo("\(responseObject) | \(String(describing: httpResponse))") + WPAuthenticatorLogInfo("\(responseObject) | \(String(describing: httpResponse))") guard let self = self else { return @@ -106,12 +106,12 @@ public extension WordPressComServiceRemote { let response = try self.decodeResponse(responseObject: responseObject) completion(.success(response)) } catch { - WPKitLogError("Failed to decode \([SiteVertical].self) : \(error.localizedDescription)") + WPAuthenticatorLogError("Failed to decode \([SiteVertical].self) : \(error.localizedDescription)") completion(.failure(SiteVerticalsError.responseDecodingFailure)) } }, failure: { error, httpResponse in - WPKitLogError("\(error) | \(String(describing: httpResponse))") + WPAuthenticatorLogError("\(error) | \(String(describing: httpResponse))") completion(.failure(SiteVerticalsError.serviceFailure)) }) } diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteVerticalsPrompt.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteVerticalsPrompt.swift index bfee3bff8cb..fb662c01699 100644 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteVerticalsPrompt.swift +++ b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/WordPressComServiceRemote+SiteVerticalsPrompt.swift @@ -49,7 +49,7 @@ public extension WordPressComServiceRemote { path, parameters: requestParameters, success: { [weak self] responseObject, httpResponse in - WPKitLogInfo("\(responseObject) | \(String(describing: httpResponse))") + WPAuthenticatorLogInfo("\(responseObject) | \(String(describing: httpResponse))") guard let self = self else { return @@ -59,12 +59,12 @@ public extension WordPressComServiceRemote { let response = try self.decodeResponse(responseObject: responseObject) completion(response) } catch { - WPKitLogError("Failed to decode SiteVerticalsPrompt : \(error.localizedDescription)") + WPAuthenticatorLogError("Failed to decode SiteVerticalsPrompt : \(error.localizedDescription)") completion(nil) } }, failure: { error, httpResponse in - WPKitLogError("\(error) | \(String(describing: httpResponse))") + WPAuthenticatorLogError("\(error) | \(String(describing: httpResponse))") completion(nil) }) } diff --git a/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests+WordPressKit.swift b/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests+WordPressKit.swift index 6d54e98b80c..621d67cb455 100644 --- a/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests+WordPressKit.swift +++ b/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests+WordPressKit.swift @@ -36,34 +36,34 @@ class LoggingTest_WordPressKit: XCTestCase { private let logger = CaptureLogs() override func setUp() { - WPKitSetLoggingDelegate(logger) + WPAuthenticatorSetLoggingDelegate(logger) } func testLogging() { - WPKitLogVerbose("This is a verbose log") - WPKitLogVerbose("This is a verbose log %@", "with an argument") + WPAuthenticatorLogVerbose("This is a verbose log") + WPAuthenticatorLogVerbose("This is a verbose log %@", "with an argument") XCTAssertEqual(self.logger.verboseLogs, ["This is a verbose log", "This is a verbose log with an argument"]) - WPKitLogDebug("This is a debug log") - WPKitLogDebug("This is a debug log %@", "with an argument") + WPAuthenticatorLogDebug("This is a debug log") + WPAuthenticatorLogDebug("This is a debug log %@", "with an argument") XCTAssertEqual(self.logger.debugLogs, ["This is a debug log", "This is a debug log with an argument"]) - WPKitLogInfo("This is an info log") - WPKitLogInfo("This is an info log %@", "with an argument") + WPAuthenticatorLogInfo("This is an info log") + WPAuthenticatorLogInfo("This is an info log %@", "with an argument") XCTAssertEqual(self.logger.infoLogs, ["This is an info log", "This is an info log with an argument"]) - WPKitLogWarning("This is a warning log") - WPKitLogWarning("This is a warning log %@", "with an argument") + WPAuthenticatorLogWarning("This is a warning log") + WPAuthenticatorLogWarning("This is a warning log %@", "with an argument") XCTAssertEqual(self.logger.warningLogs, ["This is a warning log", "This is a warning log with an argument"]) - WPKitLogError("This is an error log") - WPKitLogError("This is an error log %@", "with an argument") + WPAuthenticatorLogError("This is an error log") + WPAuthenticatorLogError("This is an error log %@", "with an argument") XCTAssertEqual(self.logger.errorLogs, ["This is an error log", "This is an error log with an argument"]) } func testNoLogging() { - WPKitSetLoggingDelegate(nil) - XCTAssertNoThrow(WPKitLogInfo("this log should not be printed")) + WPAuthenticatorSetLoggingDelegate(nil) + XCTAssertNoThrow(WPAuthenticatorLogInfo("this log should not be printed")) XCTAssertEqual(self.logger.infoLogs.count, 0) } diff --git a/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests.m b/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests.m index e5dafb96872..83b96349682 100644 --- a/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests.m +++ b/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests.m @@ -51,24 +51,24 @@ // //- (void)testLogging //{ -// WPKitLogInfo(@"This is an info log"); -// WPKitLogInfo(@"This is an info log %@", @"with an argument"); +// WPAuthenticatorLoggingInfo(@"This is an info log"); +// WPAuthenticatorLoggingInfo(@"This is an info log %@", @"with an argument"); // XCTAssertEqualObjects(self.logger.infoLogs, (@[@"This is an info log", @"This is an info log with an argument"])); // -// WPKitLogError(@"This is an error log"); -// WPKitLogError(@"This is an error log %@", @"with an argument"); +// WPAuthenticatorLoggingError(@"This is an error log"); +// WPAuthenticatorLoggingError(@"This is an error log %@", @"with an argument"); // XCTAssertEqualObjects(self.logger.errorLogs, (@[@"This is an error log", @"This is an error log with an argument"])); //} // //- (void)testUnimplementedLoggingMethod //{ -// XCTAssertNoThrow(WPKitLogVerbose(@"verbose logging is not implemented")); +// XCTAssertNoThrow(WPAuthenticatorLoggingVerbose(@"verbose logging is not implemented")); //} // //- (void)testNoLogging //{ // WPKitSetLoggingDelegate(nil); -// XCTAssertNoThrow(WPKitLogInfo(@"this log should not be printed")); +// XCTAssertNoThrow(WPAuthenticatorLoggingInfo(@"this log should not be printed")); // XCTAssertEqual(self.logger.infoLogs.count, 0); //} // From c9697831bb6356c7c1c6569fa8b5603e9aef50dc Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Sun, 5 Jan 2025 21:40:36 +0100 Subject: [PATCH 4/5] Remove more unused code --- .../Services/Plans/PlanServiceRemote.swift | 212 ----------- .../PlanServiceRemote_ApiVersion1_3.swift | 63 ---- .../Utility/ZendeskMetadata.swift | 29 -- .../Tests/PlanServiceRemoteTests.swift | 333 ------------------ 4 files changed, 637 deletions(-) delete mode 100644 WooCommerce/WordPressAuthenticator/WordPressKit/Services/Plans/PlanServiceRemote.swift delete mode 100644 WooCommerce/WordPressAuthenticator/WordPressKit/Services/Plans/PlanServiceRemote_ApiVersion1_3.swift delete mode 100644 WooCommerce/WordPressAuthenticator/WordPressKit/Utility/ZendeskMetadata.swift delete mode 100644 WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/PlanServiceRemoteTests.swift diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/Plans/PlanServiceRemote.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/Plans/PlanServiceRemote.swift deleted file mode 100644 index d654f394bf7..00000000000 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/Plans/PlanServiceRemote.swift +++ /dev/null @@ -1,212 +0,0 @@ -import Foundation -import WordPressShared - -public class PlanServiceRemote: ServiceRemoteWordPressComREST { - public typealias AvailablePlans = (plans: [RemoteWpcomPlan], groups: [RemotePlanGroup], features: [RemotePlanFeature]) - - typealias EndpointResponse = [String: AnyObject] - - public enum ResponseError: Int, Error { - // Error decoding JSON - case decodingFailure - // Depricated. An unsupported plan. - case unsupportedPlan - // Deprecated. No active plan identified in the results. - case noActivePlan - } - - // MARK: - Endpoints - - /// Get the list of WordPress.com plans, their descriptions, and their features. - /// - public func getWpcomPlans(_ success: @escaping (AvailablePlans) -> Void, failure: @escaping (Error) -> Void) { - let endpoint = "plans/mobile" - let path = self.path(forEndpoint: endpoint, withVersion: ._2_0) - - wordPressComRESTAPI.get(path, - parameters: nil, - success: { - response, _ in - - guard let response = response as? EndpointResponse else { - failure(PlanServiceRemote.ResponseError.decodingFailure) - return - } - - let plans = self.parseWpcomPlans(response) - let groups = self.parseWpcomPlanGroups(response) - let features = self.parseWpcomPlanFeatures(response) - - success((plans, groups, features)) - }, failure: { - error, _ in - failure(error) - }) - } - - /// Fetch the plan ID and name for each of the user's sites. - /// Accepts locale as a parameter in order to override automatic localization - /// and return non-localized results when needed. - /// - public func getPlanDescriptionsForAllSitesForLocale(_ locale: String, success: @escaping ([Int: RemotePlanSimpleDescription]) -> Void, failure: @escaping (Error) -> Void) { - let endpoint = "me/sites" - let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - let parameters: [String: String] = [ - "fields": "ID, plan", - "locale": locale - ] - - wordPressComRESTAPI.get(path, - parameters: parameters as [String: AnyObject], - success: { - response, _ in - - guard let response = response as? EndpointResponse else { - failure(PlanServiceRemote.ResponseError.decodingFailure) - return - } - - let result = self.parsePlanDescriptionsForSites(response) - success(result) - }, - failure: { - error, _ in - failure(error) - }) - } - - // MARK: - Non-public methods - - func parsePlanDescriptionsForSites(_ response: EndpointResponse) -> [Int: RemotePlanSimpleDescription] { - var result = [Int: RemotePlanSimpleDescription]() - - guard let sites = response["sites"] as? [EndpointResponse] else { - return result - } - - for site in sites { - guard - let tpl = parsePlanDescriptionForSite(site) - else { - continue - } - result[tpl.siteID] = tpl.plan - } - - return result - } - - func parsePlanDescriptionForSite(_ site: EndpointResponse) -> (siteID: Int, plan: RemotePlanSimpleDescription)? { - guard - let siteID = site["ID"] as? Int, - let plan = site["plan"] as? EndpointResponse, - let planID = plan["product_id"] as? Int, - let planName = plan["product_name_short"] as? String, - let planSlug = plan["product_slug"] as? String else { - return nil - } - - var name = planName - if planSlug.contains("jetpack") { - name = name + " (Jetpack)" - } - - return (siteID, RemotePlanSimpleDescription(planID: planID, name: name)) - } - - func parseWpcomPlans(_ response: EndpointResponse) -> [RemoteWpcomPlan] { - guard let json = response["plans"] as? [EndpointResponse] else { - return [RemoteWpcomPlan]() - } - - return json.compactMap { parseWpcomPlan($0) } - } - - func parseWpcomPlanProducts(_ products: [EndpointResponse]) -> String { - let parsedResult = products.compactMap { $0["plan_id"] as? String } - return parsedResult.joined(separator: ",") - } - - func parseWpcomPlanGroups(_ response: EndpointResponse) -> [RemotePlanGroup] { - guard let json = response["groups"] as? [EndpointResponse] else { - return [RemotePlanGroup]() - } - return json.compactMap { parsePlanGroup($0) } - } - - func parseWpcomPlanFeatures(_ response: EndpointResponse) -> [RemotePlanFeature] { - guard let json = response["features"] as? [EndpointResponse] else { - return [RemotePlanFeature]() - } - return json.compactMap { parsePlanFeature($0) } - } - - func parseWpcomPlan(_ item: EndpointResponse) -> RemoteWpcomPlan? { - guard - let groups = (item["groups"] as? [String])?.joined(separator: ","), - let productsArray = item["products"] as? [EndpointResponse], - let name = item["name"] as? String, - let shortname = item["short_name"] as? String, - let tagline = item["tagline"] as? String, - let description = item["description"] as? String, - let features = (item["features"] as? [String])?.joined(separator: ","), - let icon = item["icon"] as? String, - let supportPriority = item["support_priority"] as? Int, - let supportName = item["support_name"] as? String, - let nonLocalizedShortname = item["nonlocalized_short_name"] as? String else { - return nil - } - - let products = parseWpcomPlanProducts(productsArray) - - return RemoteWpcomPlan(groups: groups, - products: products, - name: name, - shortname: shortname, - tagline: tagline, - description: description, - features: features, - icon: icon, - supportPriority: supportPriority, - supportName: supportName, - nonLocalizedShortname: nonLocalizedShortname) - } - - func parsePlanGroup(_ item: EndpointResponse) -> RemotePlanGroup? { - guard - let slug = item["slug"] as? String, - let name = item["name"] as? String else { - return nil - } - return RemotePlanGroup(slug: slug, name: name) - } - - func parsePlanFeature(_ item: EndpointResponse) -> RemotePlanFeature? { - guard - let slug = item["id"] as? String, - let title = item["name"] as? String, - let description = item["description"] as? String else { - return nil - } - return RemotePlanFeature(slug: slug, title: title, description: description, iconURL: nil) - } - - /// Retrieves Zendesk meta data: plan and Jetpack addons, if available - public func getZendeskMetadata(siteID: Int, completion: @escaping (Result) -> Void) { - let endpoint = "me/sites" - let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - let parameters = ["fields": "ID, zendesk_site_meta"] as [String: AnyObject] - - Task { @MainActor [wordPressComRestApi] in - await wordPressComRestApi.perform(.get, URLString: path, parameters: parameters, type: ZendeskSiteContainer.self) - .eraseToError() - .flatMap { container in - guard let metadata = container.body.sites.filter({ $0.ID == siteID }).first?.zendeskMetadata else { - return .failure(PlanServiceRemoteError.noMetadata) - } - return .success(metadata) - } - .execute(completion) - } - } -} diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/Plans/PlanServiceRemote_ApiVersion1_3.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Services/Plans/PlanServiceRemote_ApiVersion1_3.swift deleted file mode 100644 index f5026a45d7f..00000000000 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Services/Plans/PlanServiceRemote_ApiVersion1_3.swift +++ /dev/null @@ -1,63 +0,0 @@ -import Foundation -import WordPressShared - -@objc public class PlanServiceRemote_ApiVersion1_3: ServiceRemoteWordPressComREST { - - public typealias SitePlans = (activePlan: RemotePlan_ApiVersion1_3, availablePlans: [RemotePlan_ApiVersion1_3]) - - public func getPlansForSite(_ siteID: Int, - success: @escaping (SitePlans) -> Void, - failure: @escaping (Error) -> Void) { - let endpoint = "sites/\(siteID)/plans" - let path = self.path(forEndpoint: endpoint, withVersion: ._1_3) - - wordPressComRESTAPI.get( - path, - parameters: nil, - success: { response, _ in - do { - try success(PlanServiceRemote_ApiVersion1_3.mapPlansResponse(response)) - } catch { - WPAuthenticatorLoggingError("Error parsing plans response for site \(siteID)") - WPAuthenticatorLoggingError("\(error)") - WPAuthenticatorLoggingDebug("Full response: \(response)") - failure(error) - } - }, - failure: { error, _ in - failure(error) - } - ) - } - - private static func mapPlansResponse(_ response: Any) throws - -> (activePlan: RemotePlan_ApiVersion1_3, availablePlans: [RemotePlan_ApiVersion1_3]) { - - guard let json = response as? [String: AnyObject] else { - throw PlanServiceRemote.ResponseError.decodingFailure - } - - var activePlans: [RemotePlan_ApiVersion1_3] = [] - var currentlyActivePlan: RemotePlan_ApiVersion1_3? - - try json.forEach { (key, value) in - let data = try JSONSerialization.data(withJSONObject: value, options: .prettyPrinted) - do { - let decodedResult = try JSONDecoder.apiDecoder.decode(RemotePlan_ApiVersion1_3.self, from: data) - decodedResult.planID = key - activePlans.append(decodedResult) - if decodedResult.isCurrentPlan { - currentlyActivePlan = decodedResult - } - } catch let error { - WPAuthenticatorLoggingError("Error parsing plans response for site \(error)") - } - } - - guard let activePlan = currentlyActivePlan else { - throw PlanServiceRemote.ResponseError.noActivePlan - } - return (activePlan, activePlans) - } - -} diff --git a/WooCommerce/WordPressAuthenticator/WordPressKit/Utility/ZendeskMetadata.swift b/WooCommerce/WordPressAuthenticator/WordPressKit/Utility/ZendeskMetadata.swift deleted file mode 100644 index 4090f0d4f50..00000000000 --- a/WooCommerce/WordPressAuthenticator/WordPressKit/Utility/ZendeskMetadata.swift +++ /dev/null @@ -1,29 +0,0 @@ -public struct ZendeskSiteContainer: Decodable { - public let sites: [ZendeskSite] -} - -public struct ZendeskSite: Decodable { - public let ID: Int - public let zendeskMetadata: ZendeskMetadata - - private enum CodingKeys: String, CodingKey { - case ID = "ID" - case zendeskMetadata = "zendesk_site_meta" - } -} - -public struct ZendeskMetadata: Decodable { - public let plan: String - public let jetpackAddons: [String] - - private enum CodingKeys: String, CodingKey { - case plan = "plan" - case jetpackAddons = "addon" - } -} - -/// Errors generated by the metadata decoding process -public enum PlanServiceRemoteError: Error { - // thrown when no metadata were found - case noMetadata -} diff --git a/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/PlanServiceRemoteTests.swift b/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/PlanServiceRemoteTests.swift deleted file mode 100644 index f70d4abc814..00000000000 --- a/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/PlanServiceRemoteTests.swift +++ /dev/null @@ -1,333 +0,0 @@ -import Foundation -import XCTest -@testable import WordPressAuthenticator - -class PlanServiceRemoteTests: RemoteTestCase, RESTTestable { - - // MARK: - Constants - - let siteID = 321 - - let getPlansBadJsonFailureMockFilename = "site-plans-bad-json-failure.json" - let getPlansSuccessMockFilename_ApiVersion1_3 = "site-plans-v3-success.json" - let getPlansEmptyFailureMockFilename_ApiVersion1_3 = "site-plans-v3-empty-failure.json" - let getPlansBadJsonFailureMockFilename_ApiVersion1_3 = "site-plans-v3-bad-json-failure.json" - let getWpcomPlansSuccessMockFilename = "plans-mobile-success.json" - let getPlansMeSitesSuccessMockFilename = "plans-me-sites-success.json" - let getZendeskMetadataSuccessMockFilename = "site-zendesk-metadata-success.json" - - // MARK: - Properties - - var sitePlansEndpoint: String { return "sites/\(siteID)/plans" } - var plansMobileEndpoint = "plans/mobile" - var meSitesEndpoint = "me/sites" - - var remote: PlanServiceRemote! - var remoteV3: PlanServiceRemote_ApiVersion1_3! - - // MARK: - Overridden Methods - - override func setUp() { - super.setUp() - - remote = PlanServiceRemote(wordPressComRestApi: getRestApi()) - remoteV3 = PlanServiceRemote_ApiVersion1_3(wordPressComRestApi: getRestApi()) - } - - override func tearDown() { - super.tearDown() - - remote = nil - } - - // MARK: - v1.3 Plans Tests - - func testGetPlansSucceeds_ApiVersion1_3() { - let expect = expectation(description: "Get plans for site success") - - stubRemoteResponse(sitePlansEndpoint, filename: getPlansSuccessMockFilename_ApiVersion1_3, contentType: .ApplicationJSON) - - remoteV3.getPlansForSite(siteID, success: { sitePlans in - XCTAssertEqual(sitePlans.activePlan.hasDomainCredit, true, "Active plan should have domain credit") - XCTAssertEqual(sitePlans.availablePlans.count, 7, "The availible plans count should be 7") - expect.fulfill() - }) { _ in - XCTFail("This callback shouldn't get called") - expect.fulfill() - } - - waitForExpectations(timeout: timeout, handler: nil) - } - - func testGetPlansWithEmptyResponseArrayFails_ApiVersion1_3() { - let expect = expectation(description: "Get plans with empty response array success") - - stubRemoteResponse(sitePlansEndpoint, filename: getPlansEmptyFailureMockFilename_ApiVersion1_3, contentType: .ApplicationJSON) - remoteV3.getPlansForSite(siteID, success: { _ in - XCTFail("The site should always return plans.") - expect.fulfill() - }, failure: { error in - let error = error as NSError - XCTAssertEqual(error.domain, String(reflecting: PlanServiceRemote.ResponseError.self), "The error domain should be PlanServiceRemote.ResponseError") - XCTAssertEqual(error.code, PlanServiceRemote.ResponseError.noActivePlan.rawValue, "The error code should be 2 - no active plan") - expect.fulfill() - }) - - waitForExpectations(timeout: timeout, handler: nil) - } - - func testGetPlansWithBadJsonFails_ApiVersion1_3() { - let expect = expectation(description: "Get plans with invalid json response failure") - - stubRemoteResponse(sitePlansEndpoint, filename: getPlansBadJsonFailureMockFilename_ApiVersion1_3, contentType: .ApplicationJSON, status: 200) - remoteV3.getPlansForSite(siteID, success: { _ in - XCTFail("This callback shouldn't get called") - expect.fulfill() - }, failure: { _ in - expect.fulfill() - }) - - waitForExpectations(timeout: timeout, handler: nil) - } - - // MARK: - v2 plans/mobile Tests - - func testGetWpcomPlansSucceeds() { - let expect = expectation(description: "Get wpcom plans success") - - stubRemoteResponse(plansMobileEndpoint, filename: getWpcomPlansSuccessMockFilename, contentType: .ApplicationJSON) - - remote.getWpcomPlans({ plans in - XCTAssertEqual(plans.plans.count, 6, "The number of plans returned should be 6.") - XCTAssertEqual(plans.features.count, 33, "The number of features returned should be 33.") - XCTAssertEqual(plans.groups.count, 2, "The number of groups returned should be 2.") - - expect.fulfill() - }) { _ in - XCTFail("This callback shouldn't get called") - expect.fulfill() - } - - waitForExpectations(timeout: timeout, handler: nil) - } - - func testGetWpcomPlansWithServerErrorFails() { - let expect = expectation(description: "Get plans server error failure") - - stubRemoteResponse(plansMobileEndpoint, data: Data(), contentType: .NoContentType, status: 500) - remote.getWpcomPlans({ _ in - XCTFail("This callback shouldn't get called") - expect.fulfill() - }, failure: { error in - let error = error as NSError - XCTAssertEqual(error.domain, "WordPressKit.WordPressComRestApiError", "The error domain should be WordPressComRestApiError") - XCTAssertEqual(error.code, WordPressComRestApiErrorCode.unknown.rawValue, "The error code should be 7 - unknown") - expect.fulfill() - }) - - waitForExpectations(timeout: timeout, handler: nil) - } - - func testGetWpcomPlansWithBadJsonFails() { - let expect = expectation(description: "Get plans with invalid json response failure") - - stubRemoteResponse(plansMobileEndpoint, filename: getPlansBadJsonFailureMockFilename, contentType: .ApplicationJSON, status: 200) - remote.getWpcomPlans({ _ in - XCTFail("This callback shouldn't get called") - expect.fulfill() - }, failure: { _ in - expect.fulfill() - }) - - waitForExpectations(timeout: timeout, handler: nil) - } - - func testParseWpcomPlan() { - let str = """ - { - "groups": [ - "personal", - "business" - ], - "products": [ - { - "plan_id": 1003 - }, - { - "plan_id": 1023 - } - ], - "name": "WordPress.com Premium", - "short_name": "Premium", - "support_priority": 4, - "support_name": "premium", - "nonlocalized_short_name": "Premium", - "tagline": "Best for Entrepreneurs and Freelancers", - "description": "Build a unique website with advanced design tools, CSS editing, lots of space for audio and video, and the ability to monetize your site with ads.", - "features": [ - "custom-domain", - "jetpack-essentials", - "support-live", - "themes-premium", - "design-custom", - "space-13G", - "no-ads", - "simple-payments", - "wordads", - "videopress" - ], - "icon": "" - } - """ - let data = str.data(using: .utf8)! - let json = (try? JSONSerialization.jsonObject(with: data, options: [])) as! [String: AnyObject] - XCTAssertNotNil(remote.parseWpcomPlan(json)) - } - - func testParseWpcomGroup() { - let str = """ - { - "slug": "personal", - "name": "Personal" - } - """ - let data = str.data(using: .utf8)! - let json = (try? JSONSerialization.jsonObject(with: data, options: [])) as! [String: AnyObject] - XCTAssertNotNil(remote.parsePlanGroup(json)) - } - - func testParseWpcomFeature() { - let str = """ - { - "id": "subdomain", - "name": "WordPress.com Subdomain", - "description": "Your site address will use a WordPress.com subdomain (sitename.wordpress.com)." - } - """ - let data = str.data(using: .utf8)! - let json = (try? JSONSerialization.jsonObject(with: data, options: [])) as! [String: AnyObject] - XCTAssertNotNil(remote.parsePlanFeature(json)) - } - - func testUnexpectedJsonFormatYieldsNil() { - let str = """ - { - "key": "unexpected json" - } - """ - let data = str.data(using: .utf8)! - let json = (try? JSONSerialization.jsonObject(with: data, options: [])) as! [String: AnyObject] - XCTAssertNil(remote.parseWpcomPlan(json)) - XCTAssertNil(remote.parsePlanGroup(json)) - XCTAssertNil(remote.parsePlanFeature(json)) - } - - // MARK: - Test Plan Descriptions - - func testPlanDescriptionsForAllSitesForLocale() { - let expect = expectation(description: "Get plan descriptions success") - stubRemoteResponse(meSitesEndpoint, filename: getPlansMeSitesSuccessMockFilename, contentType: .ApplicationJSON) - - remote.getPlanDescriptionsForAllSitesForLocale("en", success: { (response) in - XCTAssertEqual(response.count, 5) - expect.fulfill() - }) { _ in - XCTFail("This callback shouldn't get called") - expect.fulfill() - } - - waitForExpectations(timeout: timeout, handler: nil) - } - - func testPlanDescriptionsForAllSitesFailure() { - let expect = expectation(description: "Get plan descriptions failure") - stubRemoteResponse(meSitesEndpoint, data: Data(), contentType: .NoContentType, status: 500) - - remote.getPlanDescriptionsForAllSitesForLocale("en", success: { (_) in - XCTFail("This callback shouldn't get called") - expect.fulfill() - }) { error in - let error = error as NSError - XCTAssertEqual(error.domain, "WordPressKit.WordPressComRestApiError", "The error domain should be WordPressComRestApiError") - XCTAssertEqual(error.code, WordPressComRestApiErrorCode.unknown.rawValue, "The error code should be 7 - unknown") - expect.fulfill() - } - - waitForExpectations(timeout: timeout, handler: nil) - } - - func testParsePlanDescriptions() { - let jetpackFlag = " (Jetpack)" - - let str1 = """ - { - "ID": 1, - "plan": { - "product_id": 2002, - "product_slug": "jetpack_free", - "product_name_short": "Free" - } - } - """ - let data1 = str1.data(using: .utf8)! - let json1 = (try? JSONSerialization.jsonObject(with: data1, options: [])) as! [String: AnyObject] - - let result = remote.parsePlanDescriptionForSite(json1)! - - XCTAssertEqual(result.siteID, 1) - XCTAssertTrue(result.plan.name.contains(jetpackFlag)) - - let str2 = """ - { - "ID": 2, - "plan": { - "product_id": 1, - "product_slug": "free", - "product_name_short": "Free" - } - } - """ - let data2 = str2.data(using: .utf8)! - let json2 = (try? JSONSerialization.jsonObject(with: data2, options: [])) as! [String: AnyObject] - - let result2 = remote.parsePlanDescriptionForSite(json2)! - - XCTAssertEqual(result2.siteID, 2) - XCTAssertFalse(result2.plan.name.contains(jetpackFlag)) - } - - // MARK: - Zendesk - - func testZendeskMetadata() throws { - stubRemoteResponse("rest/v1.1/me/sites?fields=ID%2C%20zendesk_site_meta", filename: getZendeskMetadataSuccessMockFilename, contentType: .ApplicationJSON, status: 200) - - var result: Result? = nil - let completed = expectation(description: "API call completed") - remote.getZendeskMetadata(siteID: 123, completion: { - result = $0 - completed.fulfill() - }) - wait(for: [completed], timeout: 0.3) - - try XCTAssertEqual(XCTUnwrap(result).get().plan, "free") - } - - func testZendeskMetadataSiteNotFound() throws { - stubRemoteResponse("rest/v1.1/me/sites?fields=ID%2C%20zendesk_site_meta", filename: getZendeskMetadataSuccessMockFilename, contentType: .ApplicationJSON, status: 200) - - var result: Result? = nil - let completed = expectation(description: "API call completed") - remote.getZendeskMetadata(siteID: 9999, completion: { - result = $0 - completed.fulfill() - }) - wait(for: [completed], timeout: 0.3) - - switch try XCTUnwrap(result) { - case .failure(PlanServiceRemoteError.noMetadata): - XCTAssertTrue(true) - default: - XCTFail("Unexpected result: \(String(describing: result))") - } - } -} From f12f5125882da686b0624a3a0592422b407a4229 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 6 Jan 2025 09:41:02 +0100 Subject: [PATCH 5/5] Delete no-longer necessary tests for WordPressKit logging --- .../Utilities/LoggingTests+WordPressKit.swift | 70 ----------------- .../Tests/Utilities/LoggingTests.m | 75 ------------------- 2 files changed, 145 deletions(-) delete mode 100644 WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests+WordPressKit.swift delete mode 100644 WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests.m diff --git a/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests+WordPressKit.swift b/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests+WordPressKit.swift deleted file mode 100644 index 621d67cb455..00000000000 --- a/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests+WordPressKit.swift +++ /dev/null @@ -1,70 +0,0 @@ -import XCTest - -@testable import WordPressAuthenticator - -private class CaptureLogs: NSObject, WordPressLoggingDelegate { - private(set) var verboseLogs = [String]() - private(set) var debugLogs = [String]() - private(set) var infoLogs = [String]() - private(set) var warningLogs = [String]() - private(set)var errorLogs = [String]() - - func logError(_ str: String) { - errorLogs.append(str) - } - - func logWarning(_ str: String) { - warningLogs.append(str) - } - - func logInfo(_ str: String) { - infoLogs.append(str) - } - - func logDebug(_ str: String) { - debugLogs.append(str) - } - - func logVerbose(_ str: String) { - verboseLogs.append(str) - } - -} - -class LoggingTest_WordPressKit: XCTestCase { - - private let logger = CaptureLogs() - - override func setUp() { - WPAuthenticatorSetLoggingDelegate(logger) - } - - func testLogging() { - WPAuthenticatorLogVerbose("This is a verbose log") - WPAuthenticatorLogVerbose("This is a verbose log %@", "with an argument") - XCTAssertEqual(self.logger.verboseLogs, ["This is a verbose log", "This is a verbose log with an argument"]) - - WPAuthenticatorLogDebug("This is a debug log") - WPAuthenticatorLogDebug("This is a debug log %@", "with an argument") - XCTAssertEqual(self.logger.debugLogs, ["This is a debug log", "This is a debug log with an argument"]) - - WPAuthenticatorLogInfo("This is an info log") - WPAuthenticatorLogInfo("This is an info log %@", "with an argument") - XCTAssertEqual(self.logger.infoLogs, ["This is an info log", "This is an info log with an argument"]) - - WPAuthenticatorLogWarning("This is a warning log") - WPAuthenticatorLogWarning("This is a warning log %@", "with an argument") - XCTAssertEqual(self.logger.warningLogs, ["This is a warning log", "This is a warning log with an argument"]) - - WPAuthenticatorLogError("This is an error log") - WPAuthenticatorLogError("This is an error log %@", "with an argument") - XCTAssertEqual(self.logger.errorLogs, ["This is an error log", "This is an error log with an argument"]) - } - - func testNoLogging() { - WPAuthenticatorSetLoggingDelegate(nil) - XCTAssertNoThrow(WPAuthenticatorLogInfo("this log should not be printed")) - XCTAssertEqual(self.logger.infoLogs.count, 0) - } - -} diff --git a/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests.m b/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests.m deleted file mode 100644 index 83b96349682..00000000000 --- a/WooCommerce/WordPressAuthenticatorTests/WordPressKit/WordPressKitTests/Tests/Utilities/LoggingTests.m +++ /dev/null @@ -1,75 +0,0 @@ -// WordPressKit Objective-C tests have been "disabled" by brute force commenting them due to -// compilation issues as part of the WordPressAuthenticator and WordPressKit libraries fold into -// WooCommerce. See https://github.com/woocommerce/woocommerce-ios/issues/14329 -// -//#import -//@import WordPressAuthenticator; -// -//@interface CaptureLogs : NSObject -// -//@property (nonatomic, strong) NSMutableArray *infoLogs; -//@property (nonatomic, strong) NSMutableArray *errorLogs; -// -//@end -// -//@implementation CaptureLogs -// -//- (instancetype)init -//{ -// if ((self = [super init])) { -// self.infoLogs = [NSMutableArray new]; -// self.errorLogs = [NSMutableArray new]; -// } -// return self; -//} -// -//- (void)logInfo:(NSString *)str -//{ -// [self.infoLogs addObject:str]; -//} -// -//- (void)logError:(NSString *)str -//{ -// [self.errorLogs addObject:str]; -//} -// -//@end -// -//@interface ObjCLoggingTest : XCTestCase -// -//@property (nonatomic, strong) CaptureLogs *logger; -// -//@end -// -//@implementation ObjCLoggingTest -// -//- (void)setUp -//{ -// self.logger = [CaptureLogs new]; -// WPKitSetLoggingDelegate(self.logger); -//} -// -//- (void)testLogging -//{ -// WPAuthenticatorLoggingInfo(@"This is an info log"); -// WPAuthenticatorLoggingInfo(@"This is an info log %@", @"with an argument"); -// XCTAssertEqualObjects(self.logger.infoLogs, (@[@"This is an info log", @"This is an info log with an argument"])); -// -// WPAuthenticatorLoggingError(@"This is an error log"); -// WPAuthenticatorLoggingError(@"This is an error log %@", @"with an argument"); -// XCTAssertEqualObjects(self.logger.errorLogs, (@[@"This is an error log", @"This is an error log with an argument"])); -//} -// -//- (void)testUnimplementedLoggingMethod -//{ -// XCTAssertNoThrow(WPAuthenticatorLoggingVerbose(@"verbose logging is not implemented")); -//} -// -//- (void)testNoLogging -//{ -// WPKitSetLoggingDelegate(nil); -// XCTAssertNoThrow(WPAuthenticatorLoggingInfo(@"this log should not be printed")); -// XCTAssertEqual(self.logger.infoLogs.count, 0); -//} -// -//@end