From 00c14fa6a47830b990d176c18f9deb24ffa3d4f5 Mon Sep 17 00:00:00 2001 From: Aaqibhafeez Khan Date: Wed, 14 Oct 2026 03:07:15 +0530 Subject: [PATCH] fix(ios): expose localized provider configuration errors --- package/ios/GoogleMapsAPIKey.swift | 6 +++- .../MapProviderConfigurationErrorTests.swift | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 package/iosTests/MapProviderConfigurationErrorTests.swift diff --git a/package/ios/GoogleMapsAPIKey.swift b/package/ios/GoogleMapsAPIKey.swift index ecc15789..bcb9c9d0 100644 --- a/package/ios/GoogleMapsAPIKey.swift +++ b/package/ios/GoogleMapsAPIKey.swift @@ -25,7 +25,7 @@ enum GoogleMapsAPIKey { } #endif -enum MapProviderConfigurationError: LocalizedError { +enum MapProviderConfigurationError: LocalizedError, CustomStringConvertible { case missingGoogleMapsIosApiKey case googleMapsSdkNotLinked case unsupportedIOSProvider(MapProvider) @@ -41,4 +41,8 @@ enum MapProviderConfigurationError: LocalizedError { return "Map provider \"\(provider)\" is not supported on iOS." } } + + var description: String { + errorDescription ?? "Map provider configuration failed." + } } diff --git a/package/iosTests/MapProviderConfigurationErrorTests.swift b/package/iosTests/MapProviderConfigurationErrorTests.swift new file mode 100644 index 00000000..d8e43af4 --- /dev/null +++ b/package/iosTests/MapProviderConfigurationErrorTests.swift @@ -0,0 +1,32 @@ +import XCTest + +@testable import NitroMaps + +final class MapProviderConfigurationErrorTests: XCTestCase { + func testMissingGoogleMapsAPIKeyUsesLocalizedDescription() { + let error = MapProviderConfigurationError.missingGoogleMapsIosApiKey + + XCTAssertEqual( + String(describing: error), + "react-native-better-maps: provider=\"google\" on iOS requires GoogleMapsIosApiKey in the host app Info.plist." + ) + XCTAssertEqual(String(describing: error), error.localizedDescription) + } + + func testUnlinkedGoogleMapsSDKUsesLocalizedDescription() { + let error = MapProviderConfigurationError.googleMapsSdkNotLinked + + XCTAssertEqual( + String(describing: error), + "react-native-better-maps: provider=\"google\" on iOS requires the Google Maps SDK to be linked. Configure iosGoogleMapsApiKey or googleMapsApiKey in the config plugin, or set betterMaps.iosGoogleProvider=true in Podfile.properties.json, then run pod install." + ) + XCTAssertEqual(String(describing: error), error.localizedDescription) + } + + func testUnsupportedProviderUsesLocalizedDescription() { + let error = MapProviderConfigurationError.unsupportedIOSProvider(.mapbox) + + XCTAssertEqual(String(describing: error), "Map provider \"mapbox\" is not supported on iOS.") + XCTAssertEqual(String(describing: error), error.localizedDescription) + } +}