diff --git a/RevenueCatUI/Data/LocalizedAlertError.swift b/RevenueCatUI/Data/LocalizedAlertError.swift index 61048ac87b..b3622c5464 100644 --- a/RevenueCatUI/Data/LocalizedAlertError.swift +++ b/RevenueCatUI/Data/LocalizedAlertError.swift @@ -23,12 +23,16 @@ struct LocalizedAlertError: LocalizedError { } var errorDescription: String? { - return "\(self.underlyingError.domain) \(self.underlyingError.code)" + if self.underlyingError is ErrorCode { + return "Error" + } else { + return "\(self.underlyingError.domain) \(self.underlyingError.code)" + } } var failureReason: String? { if let errorCode = self.underlyingError as? ErrorCode { - return errorCode.description + return "Error \(self.underlyingError.code): \(errorCode.description)" } else { return self.underlyingError.localizedDescription } diff --git a/Tests/RevenueCatUITests/Data/LocalizedAlertErrorTests.swift b/Tests/RevenueCatUITests/Data/LocalizedAlertErrorTests.swift new file mode 100644 index 0000000000..abd7a81572 --- /dev/null +++ b/Tests/RevenueCatUITests/Data/LocalizedAlertErrorTests.swift @@ -0,0 +1,44 @@ +// +// LocalizedAlertErrorTests.swift +// +// +// Created by Nacho Soto on 1/16/24. +// + +import Nimble +import RevenueCat +@testable import RevenueCatUI +import StoreKit +import XCTest + +@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) +class LocalizedAlertGenericErrorTests: TestCase { + + private static let error = LocalizedAlertError( + error: StoreKitError.networkError(URLError(.notConnectedToInternet)) as NSError + ) + + func testErrorDescription() { + expect(Self.error.errorDescription) == "StoreKit.StoreKitError 0" + } + + func testFailureReason() { + expect(Self.error.failureReason) == "The operation couldn’t be completed. (NSURLErrorDomain error -1009.)" + } + +} + +@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) +class LocalizedAlertErrorCodeTests: TestCase { + + private static let error = LocalizedAlertError(error: ErrorCode.storeProblemError as NSError) + + func testErrorDescription() { + expect(Self.error.errorDescription) == "Error" + } + + func testFailureReason() { + expect(Self.error.failureReason) == "Error 2: There was a problem with the App Store." + } + +}