diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+ClientBehavior.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+ClientBehavior.swift index f79c09981f..20a02f8683 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+ClientBehavior.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+ClientBehavior.swift @@ -10,7 +10,7 @@ import Foundation import AWSLocation -extension AWSLocationGeoPlugin { +public extension AWSLocationGeoPlugin { // MARK: - Search @@ -30,8 +30,10 @@ extension AWSLocationGeoPlugin { /// `Geo.Error.networkError` if request failed or network unavailable /// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin /// `Geo.Error.unknown` if error is unknown - public func search(for text: String, - options: Geo.SearchForTextOptions? = nil) async throws -> [Geo.Place] { + func search( + for text: String, + options: Geo.SearchForTextOptions? = nil + ) async throws -> [Geo.Place] { var request = SearchPlaceIndexForTextInput() @@ -41,7 +43,8 @@ extension AWSLocationGeoPlugin { guard request.indexName != nil else { throw Geo.Error.invalidConfiguration( GeoPluginErrorConstants.missingDefaultSearchIndex.errorDescription, - GeoPluginErrorConstants.missingDefaultSearchIndex.recoverySuggestion) + GeoPluginErrorConstants.missingDefaultSearchIndex.recoverySuggestion + ) } request.text = text @@ -49,13 +52,17 @@ extension AWSLocationGeoPlugin { if let area = options?.area { switch area { case .near(let coordinates): - request.biasPosition = [coordinates.longitude, - coordinates.latitude] + request.biasPosition = [ + coordinates.longitude, + coordinates.latitude + ] case .within(let boundingBox): - request.filterBBox = [boundingBox.southwest.longitude, - boundingBox.southwest.latitude, - boundingBox.northeast.longitude, - boundingBox.northeast.latitude] + request.filterBBox = [ + boundingBox.southwest.longitude, + boundingBox.southwest.latitude, + boundingBox.northeast.longitude, + boundingBox.northeast.latitude + ] } } @@ -73,9 +80,7 @@ extension AWSLocationGeoPlugin { let response = try await locationService.searchPlaceIndex(forText: request) var results = [LocationClientTypes.Place]() if let responseResults = response.results { - results = responseResults.compactMap { - $0.place - } + results = responseResults.compactMap(\.place) } let places: [Geo.Place] = results.compactMap { @@ -85,16 +90,18 @@ extension AWSLocationGeoPlugin { return nil } - return Geo.Place(coordinates: Geo.Coordinates(latitude: lat, longitude: long), - label: $0.label, - addressNumber: $0.addressNumber, - street: $0.street, - municipality: $0.municipality, - neighborhood: $0.neighborhood, - region: $0.region, - subRegion: $0.subRegion, - postalCode: $0.postalCode, - country: $0.country) + return Geo.Place( + coordinates: Geo.Coordinates(latitude: lat, longitude: long), + label: $0.label, + addressNumber: $0.addressNumber, + street: $0.street, + municipality: $0.municipality, + neighborhood: $0.neighborhood, + region: $0.region, + subRegion: $0.subRegion, + postalCode: $0.postalCode, + country: $0.country + ) } return places } catch let error as GeoErrorConvertible { @@ -123,8 +130,10 @@ extension AWSLocationGeoPlugin { /// `Geo.Error.networkError` if request failed or network unavailable /// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin /// `Geo.Error.unknown` if error is unknown - public func search(for coordinates: Geo.Coordinates, - options: Geo.SearchForCoordinatesOptions? = nil) async throws -> [Geo.Place] { + func search( + for coordinates: Geo.Coordinates, + options: Geo.SearchForCoordinatesOptions? = nil + ) async throws -> [Geo.Place] { var request = SearchPlaceIndexForPositionInput() @@ -134,11 +143,14 @@ extension AWSLocationGeoPlugin { guard request.indexName != nil else { throw Geo.Error.invalidConfiguration( GeoPluginErrorConstants.missingDefaultSearchIndex.errorDescription, - GeoPluginErrorConstants.missingDefaultSearchIndex.recoverySuggestion) + GeoPluginErrorConstants.missingDefaultSearchIndex.recoverySuggestion + ) } - request.position = [coordinates.longitude, - coordinates.latitude] + request.position = [ + coordinates.longitude, + coordinates.latitude + ] if let maxResults = options?.maxResults { request.maxResults = maxResults as Int @@ -148,9 +160,7 @@ extension AWSLocationGeoPlugin { let response = try await locationService.searchPlaceIndex(forPosition: request) var results = [LocationClientTypes.Place]() if let responseResults = response.results { - results = responseResults.compactMap { - $0.place - } + results = responseResults.compactMap(\.place) } let places: [Geo.Place] = results.compactMap { @@ -160,16 +170,18 @@ extension AWSLocationGeoPlugin { return nil } - return Geo.Place(coordinates: Geo.Coordinates(latitude: lat, longitude: long), - label: $0.label, - addressNumber: $0.addressNumber, - street: $0.street, - municipality: $0.municipality, - neighborhood: $0.neighborhood, - region: $0.region, - subRegion: $0.subRegion, - postalCode: $0.postalCode, - country: $0.country) + return Geo.Place( + coordinates: Geo.Coordinates(latitude: lat, longitude: long), + label: $0.label, + addressNumber: $0.addressNumber, + street: $0.street, + municipality: $0.municipality, + neighborhood: $0.neighborhood, + region: $0.region, + subRegion: $0.subRegion, + postalCode: $0.postalCode, + country: $0.country + ) } return places } catch let error as GeoErrorConvertible { @@ -194,12 +206,13 @@ extension AWSLocationGeoPlugin { /// `Geo.Error.networkError` if request failed or network unavailable /// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin /// `Geo.Error.unknown` if error is unknown - public func availableMaps() async throws -> [Geo.MapStyle] { + func availableMaps() async throws -> [Geo.MapStyle] { let mapStyles = Array(pluginConfig.maps.values) guard !mapStyles.isEmpty else { throw Geo.Error.invalidConfiguration( GeoPluginErrorConstants.missingMaps.errorDescription, - GeoPluginErrorConstants.missingMaps.recoverySuggestion) + GeoPluginErrorConstants.missingMaps.recoverySuggestion + ) } return mapStyles } @@ -213,11 +226,12 @@ extension AWSLocationGeoPlugin { /// `Geo.Error.networkError` if request failed or network unavailable /// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin /// `Geo.Error.unknown` if error is unknown - public func defaultMap() async throws -> Geo.MapStyle { + func defaultMap() async throws -> Geo.MapStyle { guard let mapName = pluginConfig.defaultMap, let mapStyle = pluginConfig.maps[mapName] else { throw Geo.Error.invalidConfiguration( GeoPluginErrorConstants.missingDefaultMap.errorDescription, - GeoPluginErrorConstants.missingDefaultMap.recoverySuggestion) + GeoPluginErrorConstants.missingDefaultMap.recoverySuggestion + ) } return mapStyle } diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Configure.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Configure.swift index 6b194b48af..b07b16e435 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Configure.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Configure.swift @@ -7,12 +7,12 @@ import Foundation @_spi(InternalAmplifyConfiguration) import Amplify +import AWSClientRuntime +import AWSLocation import AWSPluginsCore @_spi(PluginHTTPClientEngine) import InternalAmplifyCredentials -import AWSLocation -import AWSClientRuntime -extension AWSLocationGeoPlugin { +public extension AWSLocationGeoPlugin { /// Configures AWSLocationPlugin with the specified configuration. /// /// This method will be invoked as part of the Amplify configuration flow. @@ -20,7 +20,7 @@ extension AWSLocationGeoPlugin { /// - Parameter configuration: The configuration specified for this plugin. /// - Throws: /// - PluginError.pluginConfigurationError: If one of the configuration values is invalid or empty. - public func configure(using configuration: Any?) throws { + func configure(using configuration: Any?) throws { let pluginConfiguration: AWSLocationGeoPluginConfiguration if let configuration = configuration as? AmplifyOutputsData { pluginConfiguration = try AWSLocationGeoPluginConfiguration(config: configuration) @@ -34,7 +34,7 @@ extension AWSLocationGeoPlugin { } /// Configure AWSLocationPlugin programatically using AWSLocationPluginConfiguration - public func configure(using configuration: AWSLocationGeoPluginConfiguration) throws { + func configure(using configuration: AWSLocationGeoPluginConfiguration) throws { let authService = AWSAuthService() let credentialsProvider = authService.getCredentialsProvider() let region = configuration.regionName @@ -49,9 +49,11 @@ extension AWSLocationGeoPlugin { let location = LocationClient(config: serviceConfiguration) let locationService = AWSLocationAdapter(location: location) - configure(locationService: locationService, - authService: authService, - pluginConfig: configuration) + configure( + locationService: locationService, + authService: authService, + pluginConfig: configuration + ) } // MARK: - Internal @@ -64,9 +66,11 @@ extension AWSLocationGeoPlugin { /// - locationService: The location service object. /// - authService: The authentication service object. /// - pluginConfig: The configuration for the plugin. - func configure(locationService: AWSLocationBehavior, - authService: AWSAuthServiceBehavior, - pluginConfig: AWSLocationGeoPluginConfiguration) { + internal func configure( + locationService: AWSLocationBehavior, + authService: AWSAuthServiceBehavior, + pluginConfig: AWSLocationGeoPluginConfiguration + ) { self.locationService = locationService self.authService = authService self.pluginConfig = pluginConfig diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Reset.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Reset.swift index b1b76ca452..a748002a2c 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Reset.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Reset.swift @@ -8,13 +8,13 @@ import Amplify import Foundation -extension AWSLocationGeoPlugin { +public extension AWSLocationGeoPlugin { /// Resets the state of the plugin. /// /// Sets stored objects to nil to allow deallocation, then calls onComplete closure /// to signal the reset has completed. - public func reset() async { + func reset() async { locationService = nil authService = nil pluginConfig = nil diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/AWSLocationGeoPluginConfiguration.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/AWSLocationGeoPluginConfiguration.swift index 4d25b090a5..b4f25e9fe2 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/AWSLocationGeoPluginConfiguration.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/AWSLocationGeoPluginConfiguration.swift @@ -6,8 +6,8 @@ // @_spi(InternalAmplifyConfiguration) import Amplify -import Foundation import AWSLocation +import Foundation public struct AWSLocationGeoPluginConfiguration { private static func urlString(regionName: String, mapName: String) -> String { @@ -22,18 +22,24 @@ public struct AWSLocationGeoPluginConfiguration { public let regionName: String init(config: JSONValue) throws { - let configObject = try AWSLocationGeoPluginConfiguration.getConfigObject(section: .plugin, - configJSON: config) + let configObject = try AWSLocationGeoPluginConfiguration.getConfigObject( + section: .plugin, + configJSON: config + ) let regionName = try AWSLocationGeoPluginConfiguration.getRegion(configObject) var maps = [String: Geo.MapStyle]() var defaultMap: String? if let mapsConfigJSON = configObject[Section.maps.key] { - let mapsConfigObject = try AWSLocationGeoPluginConfiguration.getConfigObject(section: .maps, - configJSON: mapsConfigJSON) + let mapsConfigObject = try AWSLocationGeoPluginConfiguration.getConfigObject( + section: .maps, + configJSON: mapsConfigJSON + ) maps = try AWSLocationGeoPluginConfiguration.getMaps(mapConfig: mapsConfigObject, regionName: regionName) - defaultMap = try AWSLocationGeoPluginConfiguration.getDefault(section: .maps, - configObject: mapsConfigObject) + defaultMap = try AWSLocationGeoPluginConfiguration.getDefault( + section: .maps, + configObject: mapsConfigObject + ) guard let map = defaultMap, maps[map] != nil else { throw GeoPluginConfigError.mapDefaultNotFound(mapName: defaultMap) } @@ -42,25 +48,33 @@ public struct AWSLocationGeoPluginConfiguration { var searchIndices = [String]() var defaultSearchIndex: String? if let searchConfigJSON = configObject[Section.searchIndices.key] { - let searchConfigObject = try AWSLocationGeoPluginConfiguration.getConfigObject(section: .searchIndices, - configJSON: searchConfigJSON) - searchIndices = try AWSLocationGeoPluginConfiguration.getItemsStrings(section: .searchIndices, - configObject: searchConfigObject) - defaultSearchIndex = try AWSLocationGeoPluginConfiguration.getDefault(section: .searchIndices, - configObject: searchConfigObject) + let searchConfigObject = try AWSLocationGeoPluginConfiguration.getConfigObject( + section: .searchIndices, + configJSON: searchConfigJSON + ) + searchIndices = try AWSLocationGeoPluginConfiguration.getItemsStrings( + section: .searchIndices, + configObject: searchConfigObject + ) + defaultSearchIndex = try AWSLocationGeoPluginConfiguration.getDefault( + section: .searchIndices, + configObject: searchConfigObject + ) guard let index = defaultSearchIndex, searchIndices.contains(index) else { throw GeoPluginConfigError.searchDefaultNotFound(indexName: defaultSearchIndex) } } - self.init(regionName: regionName, - defaultMap: defaultMap, - maps: maps, - defaultSearchIndex: defaultSearchIndex, - searchIndices: searchIndices) + self.init( + regionName: regionName, + defaultMap: defaultMap, + maps: maps, + defaultSearchIndex: defaultSearchIndex, + searchIndices: searchIndices + ) } - + init(config: AmplifyOutputsData) throws { guard let geo = config.geo else { throw GeoPluginConfigError.configurationInvalid(section: .plugin) @@ -71,7 +85,8 @@ public struct AWSLocationGeoPluginConfiguration { if let geoMaps = geo.maps { maps = try AWSLocationGeoPluginConfiguration.getMaps( mapConfig: geoMaps, - regionName: geo.awsRegion) + regionName: geo.awsRegion + ) defaultMap = geoMaps.default // Validate that the default map exists in `maps` @@ -91,18 +106,22 @@ public struct AWSLocationGeoPluginConfiguration { } } - self.init(regionName: geo.awsRegion, - defaultMap: defaultMap, - maps: maps, - defaultSearchIndex: defaultSearchIndex, - searchIndices: searchIndices) + self.init( + regionName: geo.awsRegion, + defaultMap: defaultMap, + maps: maps, + defaultSearchIndex: defaultSearchIndex, + searchIndices: searchIndices + ) } - init(regionName: String, - defaultMap: String?, - maps: [String: Geo.MapStyle], - defaultSearchIndex: String?, - searchIndices: [String]) { + init( + regionName: String, + defaultMap: String?, + maps: [String: Geo.MapStyle], + defaultSearchIndex: String?, + searchIndices: [String] + ) { self.regionName = regionName self.defaultMap = defaultMap self.maps = maps @@ -162,8 +181,10 @@ public struct AWSLocationGeoPluginConfiguration { return itemsJSON } - private static func getItemsObject(section: Section, - configObject: [String: JSONValue]) throws -> [String: JSONValue] { + private static func getItemsObject( + section: Section, + configObject: [String: JSONValue] + ) throws -> [String: JSONValue] { let itemsJSON = try getItemsJSON(section: section, configObject: configObject) let itemsObject = try getConfigObject(section: section, configJSON: itemsJSON) return itemsObject @@ -200,8 +221,10 @@ public struct AWSLocationGeoPluginConfiguration { throw GeoPluginConfigError.mapStyleIsNotString(mapName: mapName) } - let url = URL(string: AWSLocationGeoPluginConfiguration.urlString(regionName: regionName, - mapName: mapName)) + let url = URL(string: AWSLocationGeoPluginConfiguration.urlString( + regionName: regionName, + mapName: mapName + )) guard let styleURL = url else { throw GeoPluginConfigError.mapStyleURLInvalid(mapName: mapName) } @@ -215,11 +238,15 @@ public struct AWSLocationGeoPluginConfiguration { return mapStyles } - private static func getMaps(mapConfig: AmplifyOutputsData.Geo.Maps, - regionName: String) throws -> [String: Geo.MapStyle] { + private static func getMaps( + mapConfig: AmplifyOutputsData.Geo.Maps, + regionName: String + ) throws -> [String: Geo.MapStyle] { let mapTuples: [(String, Geo.MapStyle)] = try mapConfig.items.map { map in - let url = URL(string: AWSLocationGeoPluginConfiguration.urlString(regionName: regionName, - mapName: map.key)) + let url = URL(string: AWSLocationGeoPluginConfiguration.urlString( + regionName: regionName, + mapName: map.key + )) guard let styleURL = url else { throw GeoPluginConfigError.mapStyleURLInvalid(mapName: map.key) } diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/GeoPluginConfigError.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/GeoPluginConfigError.swift index 749533765c..945a30037f 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/GeoPluginConfigError.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/GeoPluginConfigError.swift @@ -10,7 +10,7 @@ import Foundation typealias GeoPluginErrorString = (errorDescription: ErrorDescription, recoverySuggestion: RecoverySuggestion) -struct GeoPluginConfigError { +enum GeoPluginConfigError { static func configurationInvalid(section: AWSLocationGeoPluginConfiguration.Section) -> PluginError { PluginError.pluginConfigurationError( "Unable to decode \(section.key) configuration.", diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Dependency/AWSLocationBehavior.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Dependency/AWSLocationBehavior.swift index fdc71dc22f..2433afbc93 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Dependency/AWSLocationBehavior.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Dependency/AWSLocationBehavior.swift @@ -5,8 +5,8 @@ // SPDX-License-Identifier: Apache-2.0 // -import Foundation import AWSLocation +import Foundation /// Behavior that `AWSLocationAdapter` will use. /// This protocol allows a way to create a Mock and ensure the plugin implementation is testable. diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Constants/GeoPluginErrorConstants.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Constants/GeoPluginErrorConstants.swift index 11250a7976..f3c9b7fc7e 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Constants/GeoPluginErrorConstants.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Constants/GeoPluginErrorConstants.swift @@ -5,21 +5,24 @@ // SPDX-License-Identifier: Apache-2.0 // -import Foundation import Amplify +import Foundation -struct GeoPluginErrorConstants { +enum GeoPluginErrorConstants { static let missingDefaultSearchIndex: GeoPluginErrorString = ( "No default search index was found.", - "Please ensure you have added search to your project before calling search functions.") + "Please ensure you have added search to your project before calling search functions." + ) static let missingDefaultMap: GeoPluginErrorString = ( "No default map was found.", - "Please ensure you have added maps to your project before calling map-related functions.") + "Please ensure you have added maps to your project before calling map-related functions." + ) static let missingMaps: GeoPluginErrorString = ( "No maps are available.", - "Please ensure you have added maps to your project before calling map-related functions.") + "Please ensure you have added maps to your project before calling map-related functions." + ) } // Recovery Messages diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Utils/GeoErrorConvertible.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Utils/GeoErrorConvertible.swift index ad35aea33a..15d21d1ba6 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Utils/GeoErrorConvertible.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Utils/GeoErrorConvertible.swift @@ -6,9 +6,9 @@ // import Amplify -import Foundation -import AWSLocation import AWSClientRuntime +import AWSLocation +import Foundation protocol GeoErrorConvertible { var geoError: Geo.Error { get } diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginAmplifyVersionableTests.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginAmplifyVersionableTests.swift index a39a663998..52f909462f 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginAmplifyVersionableTests.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginAmplifyVersionableTests.swift @@ -5,8 +5,8 @@ // SPDX-License-Identifier: Apache-2.0 // -import XCTest import AWSLocationGeoPlugin +import XCTest // swiftlint:disable:next type_name class AWSLocationGeoPluginAmplifyVersionableTests: XCTestCase { diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginClientBehaviorTests.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginClientBehaviorTests.swift index f9ae3c2e71..e86b6db90f 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginClientBehaviorTests.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginClientBehaviorTests.swift @@ -7,8 +7,8 @@ import Amplify import AWSLocation -@testable import AWSLocationGeoPlugin import XCTest +@testable import AWSLocationGeoPlugin class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase { let searchText = "coffee shop" @@ -28,8 +28,8 @@ class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase { do { _ = try await geoPlugin.search(for: searchText, options: nil) var request = SearchPlaceIndexForTextInput() - request.text = self.searchText - self.mockLocation.verifySearchPlaceIndexForText(request) + request.text = searchText + mockLocation.verifySearchPlaceIndexForText(request) } catch { XCTFail("Failed with error: \(error)") } @@ -53,13 +53,15 @@ class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase { do { _ = try await geoPlugin.search(for: searchText, options: options) var request = SearchPlaceIndexForTextInput() - request.text = self.searchText - request.biasPosition = [(self.coordinates.longitude), - (self.coordinates.latitude)] + request.text = searchText + request.biasPosition = [ + coordinates.longitude, + coordinates.latitude + ] request.filterCountries = options.countries?.map { $0.code } request.maxResults = options.maxResults ?? 0 request.indexName = (options.pluginOptions as? AWSLocationGeoPluginSearchOptions)?.searchIndex - self.mockLocation.verifySearchPlaceIndexForText(request) + mockLocation.verifySearchPlaceIndexForText(request) } catch { XCTFail("Failed with error: \(error)") } @@ -100,9 +102,11 @@ class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase { do { _ = try await geoPlugin.search(for: coordinates, options: nil) var request = SearchPlaceIndexForPositionInput() - request.position = [(self.coordinates.longitude), - (self.coordinates.latitude)] - self.mockLocation.verifySearchPlaceIndexForPosition(request) + request.position = [ + coordinates.longitude, + coordinates.latitude + ] + mockLocation.verifySearchPlaceIndexForPosition(request) } catch { XCTFail("Failed with error: \(error)") } @@ -124,11 +128,13 @@ class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase { do { _ = try await geoPlugin.search(for: coordinates, options: options) var request = SearchPlaceIndexForPositionInput() - request.position = [(self.coordinates.longitude), - (self.coordinates.latitude) ] + request.position = [ + coordinates.longitude, + coordinates.latitude + ] request.maxResults = options.maxResults ?? 0 request.indexName = (options.pluginOptions as? AWSLocationGeoPluginSearchOptions)?.searchIndex - self.mockLocation.verifySearchPlaceIndexForPosition(request) + mockLocation.verifySearchPlaceIndexForPosition(request) } catch { XCTFail("Failed with error: \(error)") } diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginConfigureTests.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginConfigureTests.swift index f534374b07..1f31bb9b5b 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginConfigureTests.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginConfigureTests.swift @@ -6,8 +6,8 @@ // import Amplify -@testable import AWSLocationGeoPlugin import XCTest +@testable import AWSLocationGeoPlugin class AWSLocationGeoPluginConfigureTests: AWSLocationGeoPluginTestBase { // MARK: - Plugin Key test @@ -56,7 +56,8 @@ class AWSLocationGeoPluginConfigureTests: AWSLocationGeoPluginTestBase { XCTFail("Geo configuration should not succeed.") } catch { guard let pluginError = error as? PluginError, - case .pluginConfigurationError = pluginError else { + case .pluginConfigurationError = pluginError + else { XCTFail("Should throw invalidConfiguration exception. But received \(error) ") return } diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginResetTests.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginResetTests.swift index 8362742b53..32fe84527a 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginResetTests.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginResetTests.swift @@ -6,8 +6,8 @@ // import Amplify -@testable import AWSLocationGeoPlugin import XCTest +@testable import AWSLocationGeoPlugin class AWSLocationGeoPluginResetTests: AWSLocationGeoPluginTestBase { func testReset() async { diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginTestBase.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginTestBase.swift index ee44deb0fb..c1b70fff6d 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginTestBase.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginTestBase.swift @@ -5,11 +5,11 @@ // SPDX-License-Identifier: Apache-2.0 // +import XCTest @testable import Amplify @testable import AmplifyTestCommon @testable import AWSLocationGeoPlugin @testable import AWSPluginsTestCommon -import XCTest class AWSLocationGeoPluginTestBase: XCTestCase { var geoPlugin: AWSLocationGeoPlugin! @@ -18,17 +18,21 @@ class AWSLocationGeoPluginTestBase: XCTestCase { var emptyPluginConfig: AWSLocationGeoPluginConfiguration! override func setUp() async throws { - pluginConfig = AWSLocationGeoPluginConfiguration(regionName: GeoPluginTestConfig.regionName, - defaultMap: GeoPluginTestConfig.map, - maps: GeoPluginTestConfig.maps, - defaultSearchIndex: GeoPluginTestConfig.searchIndex, - searchIndices: GeoPluginTestConfig.searchIndices) - - emptyPluginConfig = AWSLocationGeoPluginConfiguration(regionName: GeoPluginTestConfig.regionName, - defaultMap: nil, - maps: [:], - defaultSearchIndex: nil, - searchIndices: []) + pluginConfig = AWSLocationGeoPluginConfiguration( + regionName: GeoPluginTestConfig.regionName, + defaultMap: GeoPluginTestConfig.map, + maps: GeoPluginTestConfig.maps, + defaultSearchIndex: GeoPluginTestConfig.searchIndex, + searchIndices: GeoPluginTestConfig.searchIndices + ) + + emptyPluginConfig = AWSLocationGeoPluginConfiguration( + regionName: GeoPluginTestConfig.regionName, + defaultMap: nil, + maps: [:], + defaultSearchIndex: nil, + searchIndices: [] + ) do { mockLocation = try MockAWSLocation(pluginConfig: pluginConfig) diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginAmplifyOutputsConfigurationTests.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginAmplifyOutputsConfigurationTests.swift index 70e30ab8b4..fd98bfa0fd 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginAmplifyOutputsConfigurationTests.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginAmplifyOutputsConfigurationTests.swift @@ -5,8 +5,8 @@ // SPDX-License-Identifier: Apache-2.0 // -@testable @_spi(InternalAmplifyConfiguration) import Amplify import XCTest +@testable @_spi(InternalAmplifyConfiguration) import Amplify @testable import AWSLocationGeoPlugin @@ -49,7 +49,9 @@ class AWSLocationGeoPluginAmplifyOutputsConfigurationTests: XCTestCase { awsRegion: GeoPluginTestConfig.regionName, maps: .init( items: [GeoPluginTestConfig.map: .init(style: GeoPluginTestConfig.style)], - default: GeoPluginTestConfig.map))) + default: GeoPluginTestConfig.map + ) + )) do { let config = try AWSLocationGeoPluginConfiguration(config: config) XCTAssertNotNil(config) @@ -69,7 +71,9 @@ class AWSLocationGeoPluginAmplifyOutputsConfigurationTests: XCTestCase { awsRegion: GeoPluginTestConfig.regionName, searchIndices: .init( items: [GeoPluginTestConfig.searchIndex], - default: GeoPluginTestConfig.searchIndex))) + default: GeoPluginTestConfig.searchIndex + ) + )) do { let config = try AWSLocationGeoPluginConfiguration(config: config) @@ -92,8 +96,10 @@ class AWSLocationGeoPluginAmplifyOutputsConfigurationTests: XCTestCase { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.configurationInvalid(section: .plugin).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.configurationInvalid(section: .plugin).errorDescription + ) } } @@ -108,15 +114,19 @@ class AWSLocationGeoPluginAmplifyOutputsConfigurationTests: XCTestCase { awsRegion: GeoPluginTestConfig.regionName, maps: .init( items: [GeoPluginTestConfig.map: .init(style: GeoPluginTestConfig.style)], - default: map))) + default: map + ) + )) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.mapDefaultNotFound(mapName: map).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.mapDefaultNotFound(mapName: map).errorDescription + ) } } @@ -129,15 +139,18 @@ class AWSLocationGeoPluginAmplifyOutputsConfigurationTests: XCTestCase { geo: .init( awsRegion: GeoPluginTestConfig.regionName, maps: nil, - searchIndices: .init(items: [GeoPluginTestConfig.searchIndex], default: searchIndex))) + searchIndices: .init(items: [GeoPluginTestConfig.searchIndex], default: searchIndex) + )) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.searchDefaultNotFound(indexName: searchIndex).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.searchDefaultNotFound(indexName: searchIndex).errorDescription + ) } } } diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginConfigurationTests.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginConfigurationTests.swift index 8118fc2fa0..cf5106e31f 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginConfigurationTests.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginConfigurationTests.swift @@ -44,9 +44,11 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { } func testConfigureSuccessOnlyMaps() throws { - let geoPluginConfigJSON = JSONValue(dictionaryLiteral: + let geoPluginConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON)) + (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON) + ) do { let config = try AWSLocationGeoPluginConfiguration(config: geoPluginConfigJSON) @@ -62,9 +64,11 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { } func testConfigureSuccessOnlySearch() throws { - let geoPluginConfigJSON = JSONValue(dictionaryLiteral: + let geoPluginConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON) + ) do { let config = try AWSLocationGeoPluginConfiguration(config: geoPluginConfigJSON) @@ -87,40 +91,50 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.configurationInvalid(section: .plugin).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.configurationInvalid(section: .plugin).errorDescription + ) } } func testConfigureThrowsErrorForInvalidMapsConfiguration() { let mapsConfigJSON = JSONValue(stringLiteral: "notADictionaryLiteral") - let geoPluginConfig = JSONValue(dictionaryLiteral: + let geoPluginConfig = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON)) + (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: geoPluginConfig)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.configurationInvalid(section: .maps).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.configurationInvalid(section: .maps).errorDescription + ) } } func testConfigureThrowsErrorForInvalidSearchConfiguration() { let searchConfigJSON = JSONValue(stringLiteral: "notADictionaryLiteral") - let geoPluginConfig = JSONValue(dictionaryLiteral: + let geoPluginConfig = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, searchConfigJSON)) + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: geoPluginConfig)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.configurationInvalid(section: .searchIndices).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.configurationInvalid(section: .searchIndices).errorDescription + ) } } @@ -131,21 +145,27 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let map = "missingMapName" let mapJSON = JSONValue(stringLiteral: map) - let mapsConfigJSON = JSONValue(dictionaryLiteral: + let mapsConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, GeoPluginTestConfig.mapItemConfigJSON), - (AWSLocationGeoPluginConfiguration.Node.default.key, mapJSON)) + (AWSLocationGeoPluginConfiguration.Node.default.key, mapJSON) + ) - let geoPluginConfig = JSONValue(dictionaryLiteral: + let geoPluginConfig = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON)) + (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: geoPluginConfig)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.mapDefaultNotFound(mapName: map).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.mapDefaultNotFound(mapName: map).errorDescription + ) } } @@ -156,37 +176,47 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let searchIndex = "missingSearchIndex" let searchIndexJSON = JSONValue(stringLiteral: searchIndex) - let searchConfigJSON = JSONValue(dictionaryLiteral: + let searchConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, GeoPluginTestConfig.searchItemsArrayJSON), - (AWSLocationGeoPluginConfiguration.Node.default.key, searchIndexJSON)) + (AWSLocationGeoPluginConfiguration.Node.default.key, searchIndexJSON) + ) - let geoPluginConfig = JSONValue(dictionaryLiteral: + let geoPluginConfig = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, searchConfigJSON)) + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: geoPluginConfig)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.searchDefaultNotFound(indexName: searchIndex).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.searchDefaultNotFound(indexName: searchIndex).errorDescription + ) } } - + /// - Given: geo plugin configuration /// - When: the object initializes missing region /// - Then: the configuration fails to initialize with regionMissing error func testConfigureFailureForMissingRegion() async { - let config = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) + let config = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON), + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.regionMissing.errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.regionMissing.errorDescription + ) } } @@ -194,37 +224,45 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { /// - When: the object initializes with an invalid region /// - Then: the configuration fails to initialize with regionInvalid error func testConfigureFailureForInvalidRegion() async { - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, JSONValue(integerLiteral: 1)), - (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) + let config = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, JSONValue(integerLiteral: 1)), + (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON), + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.regionInvalid.errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.regionInvalid.errorDescription + ) } } - + /// - Given: geo plugin configuration /// - When: the object initializes with a missing default maps section /// - Then: the configuration fails to initialize with defaultMissing error func testConfigureFailureForMissingDefaultMapsSection() async { let mapsConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, GeoPluginTestConfig.mapItemConfigJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) + let config = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.defaultMissing(section: .maps).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.defaultMissing(section: .maps).errorDescription + ) } } - + /// - Given: geo plugin configuration /// - When: the object initializes without default map /// - Then: the configuration fails to initialize with mapDefaultNotFound error @@ -234,19 +272,25 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let mapStyleConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.style.key, mapStyleJSON)) let mapItemConfigJSON = JSONValue(dictionaryLiteral: (mapName, mapStyleConfigJSON)) - let mapsConfigJSON = JSONValue(dictionaryLiteral: + let mapsConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, mapItemConfigJSON), - (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) + (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON) + ) + let config = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.mapDefaultNotFound(mapName: "testMap").errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.mapDefaultNotFound(mapName: "testMap").errorDescription + ) } } @@ -254,18 +298,24 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { /// - When: the object initializes with a invalid default maps section /// - Then: the configuration fails to initialize with defaultNotString error func testConfigureFailureForInvalidDefaultMapsSection() async { - let mapsConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, GeoPluginTestConfig.mapItemConfigJSON), - (AWSLocationGeoPluginConfiguration.Node.default.key, JSONValue(integerLiteral: 1))) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) + let mapsConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, GeoPluginTestConfig.mapItemConfigJSON), + (AWSLocationGeoPluginConfiguration.Node.default.key, JSONValue(integerLiteral: 1)) + ) + let config = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.defaultNotString(section: .maps).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.defaultNotString(section: .maps).errorDescription + ) } } @@ -275,60 +325,76 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { /// - When: the object initializes with a empty default maps section /// - Then: the configuration fails to initialize with defaultIsEmpty error func testConfigureFailureForEmptyDefaultMapsSection() async { - let mapsConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, GeoPluginTestConfig.mapItemConfigJSON), - (AWSLocationGeoPluginConfiguration.Node.default.key, JSONValue(stringLiteral: ""))) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) + let mapsConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, GeoPluginTestConfig.mapItemConfigJSON), + (AWSLocationGeoPluginConfiguration.Node.default.key, JSONValue(stringLiteral: "")) + ) + let config = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.defaultIsEmpty(section: .maps).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.defaultIsEmpty(section: .maps).errorDescription + ) } } - + /// - Given: geo plugin configuration /// - When: the object initializes with a items default maps section /// - Then: the configuration fails to initialize with itemsMissing error func testConfigureFailureForMissingItemsMapsSection() async { - let mapsConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.default.key,GeoPluginTestConfig.testMapJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) + let mapsConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON)) + let config = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.itemsMissing(section: .maps).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.itemsMissing(section: .maps).errorDescription + ) } } - + /// - Given: geo plugin configuration /// - When: the object initializes with a invalid maps section /// - Then: the configuration fails to initialize with mapInvalid error func testConfigureFailureForInvalidMapsSection() async { let mapItemConfigJSON = JSONValue(dictionaryLiteral: ("testMap", JSONValue(stringLiteral: ""))) - let mapsConfigJSON = JSONValue(dictionaryLiteral: + let mapsConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, mapItemConfigJSON), - (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) + (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON) + ) + let config = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.mapInvalid(mapName: "testMap").errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.mapInvalid(mapName: "testMap").errorDescription + ) } } - + /// - Given: geo plugin configuration /// - When: the object initializes with a invalid maps section /// - Then: the configuration fails to initialize with mapStyleMissing error @@ -336,23 +402,29 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let mapStyleConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, JSONValue(stringLiteral: ""))) let mapItemConfigJSON = JSONValue(dictionaryLiteral: ("testMap", mapStyleConfigJSON)) - let mapsConfigJSON = JSONValue(dictionaryLiteral: + let mapsConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, mapItemConfigJSON), - (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) + (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON) + ) + let config = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.mapStyleMissing(mapName: "testMap").errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.mapStyleMissing(mapName: "testMap").errorDescription + ) } } - - + + /// - Given: geo plugin configuration /// - When: the object initializes with a invalid maps section /// - Then: the configuration fails to initialize with mapStyleMissing error @@ -362,12 +434,16 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let mapStyleConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.style.key, mapStyleJSON)) let mapItemConfigJSON = JSONValue(dictionaryLiteral: (mapName, mapStyleConfigJSON)) - let mapsConfigJSON = JSONValue(dictionaryLiteral: + let mapsConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, mapItemConfigJSON), - (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) + (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON) + ) + let config = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case PluginError.pluginConfigurationError(_, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") @@ -375,7 +451,7 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { } } } - + /// - Given: geo plugin configuration /// - When: the object initializes with a invalid map style url /// - Then: the configuration fails to initialize with mapStyleIsNotString error @@ -385,19 +461,25 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let mapStyleConfigJSON = JSONValue(dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.style.key, mapStyleJSON)) let mapItemConfigJSON = JSONValue(dictionaryLiteral: (mapName, mapStyleConfigJSON)) - let mapsConfigJSON = JSONValue(dictionaryLiteral: + let mapsConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, mapItemConfigJSON), - (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON)) + (AWSLocationGeoPluginConfiguration.Node.default.key, GeoPluginTestConfig.testMapJSON) + ) + let config = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, GeoPluginTestConfig.searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.mapStyleIsNotString(mapName: mapName).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.mapStyleIsNotString(mapName: mapName).errorDescription + ) } } @@ -408,19 +490,25 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let searchIndex = "testSearchIndex" let searchIndexJSON = JSONValue(stringLiteral: searchIndex) let searchItemsArrayJSON = JSONValue(stringLiteral: "") - let searchConfigJSON = JSONValue(dictionaryLiteral: + let searchConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, searchItemsArrayJSON), - (AWSLocationGeoPluginConfiguration.Node.default.key, searchIndexJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, searchConfigJSON)) + (AWSLocationGeoPluginConfiguration.Node.default.key, searchIndexJSON) + ) + let config = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON), + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.itemsInvalid(section: .searchIndices).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.itemsInvalid(section: .searchIndices).errorDescription + ) } } @@ -431,22 +519,28 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let searchIndex = "testSearchIndex" let searchIndexJSON = JSONValue(stringLiteral: searchIndex) let searchItemsArrayJSON = JSONValue(arrayLiteral: 1) - let searchConfigJSON = JSONValue(dictionaryLiteral: + let searchConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, searchItemsArrayJSON), - (AWSLocationGeoPluginConfiguration.Node.default.key, searchIndexJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, searchConfigJSON)) + (AWSLocationGeoPluginConfiguration.Node.default.key, searchIndexJSON) + ) + let config = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON), + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.itemsIsNotStringArray(section: .searchIndices).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.itemsIsNotStringArray(section: .searchIndices).errorDescription + ) } } - + /// - Given: geo plugin configuration /// - When: configuration initializes with a mismatch search items and default item /// - Then: the configuration fails to initializes with searchDefaultNotFound error @@ -454,19 +548,25 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { let searchIndex = "testSearchIndex" let searchIndexJSON = JSONValue(stringLiteral: searchIndex) let searchItemsArrayJSON = JSONValue(arrayLiteral: JSONValue(stringLiteral: "test")) - let searchConfigJSON = JSONValue(dictionaryLiteral: + let searchConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, searchItemsArrayJSON), - (AWSLocationGeoPluginConfiguration.Node.default.key, searchIndexJSON)) - let config = JSONValue(dictionaryLiteral:(AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), - (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, searchConfigJSON)) + (AWSLocationGeoPluginConfiguration.Node.default.key, searchIndexJSON) + ) + let config = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, GeoPluginTestConfig.regionJSON), + (AWSLocationGeoPluginConfiguration.Section.maps.key, GeoPluginTestConfig.mapsConfigJSON), + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, searchConfigJSON) + ) XCTAssertThrowsError(try AWSLocationGeoPluginConfiguration(config: config)) { error in guard case let PluginError.pluginConfigurationError(errorDescription, _, _) = error else { XCTFail("Expected PluginError pluginConfigurationError, got: \(error)") return } - XCTAssertEqual(errorDescription, - GeoPluginConfigError.searchDefaultNotFound(indexName: searchIndex).errorDescription) + XCTAssertEqual( + errorDescription, + GeoPluginConfigError.searchDefaultNotFound(indexName: searchIndex).errorDescription + ) } } } diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSClientConfiguration.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSClientConfiguration.swift index ec24a7486d..b34ef18c9b 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSClientConfiguration.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSClientConfiguration.swift @@ -6,8 +6,8 @@ // import AWSClientRuntime -import ClientRuntime import AWSLocation +import ClientRuntime import Foundation import XCTest diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation+ClientBehavior.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation+ClientBehavior.swift index 3f7fbb6c27..87ec14aee0 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation+ClientBehavior.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation+ClientBehavior.swift @@ -6,38 +6,46 @@ // import AWSLocation -@testable import AWSLocationGeoPlugin import Foundation +@testable import AWSLocationGeoPlugin -extension MockAWSLocation { +public extension MockAWSLocation { - public func searchPlaceIndex(forText: SearchPlaceIndexForTextInput, - completionHandler: ((SearchPlaceIndexForTextOutput?, - Error?) -> Void)?) { + func searchPlaceIndex( + forText: SearchPlaceIndexForTextInput, + completionHandler: (( + SearchPlaceIndexForTextOutput?, + Error? + ) -> Void)? + ) { searchPlaceIndexForTextCalled += 1 searchPlaceIndexForTextRequest = forText - if let completionHandler = completionHandler { + if let completionHandler { completionHandler(SearchPlaceIndexForTextOutput(), nil) } } - public func searchPlaceIndex(forPosition: SearchPlaceIndexForPositionInput, - completionHandler: ((SearchPlaceIndexForPositionOutput?, - Error?) -> Void)?) { + func searchPlaceIndex( + forPosition: SearchPlaceIndexForPositionInput, + completionHandler: (( + SearchPlaceIndexForPositionOutput?, + Error? + ) -> Void)? + ) { searchPlaceIndexForPositionCalled += 1 searchPlaceIndexForPositionRequest = forPosition - if let completionHandler = completionHandler { + if let completionHandler { completionHandler(SearchPlaceIndexForPositionOutput(), nil) } } - public func searchPlaceIndex(forText: SearchPlaceIndexForTextInput) async throws -> SearchPlaceIndexForTextOutput { + func searchPlaceIndex(forText: SearchPlaceIndexForTextInput) async throws -> SearchPlaceIndexForTextOutput { searchPlaceIndexForTextCalled += 1 searchPlaceIndexForTextRequest = forText return SearchPlaceIndexForTextOutput() } - public func searchPlaceIndex(forPosition: SearchPlaceIndexForPositionInput) async throws -> SearchPlaceIndexForPositionOutput { + func searchPlaceIndex(forPosition: SearchPlaceIndexForPositionInput) async throws -> SearchPlaceIndexForPositionOutput { searchPlaceIndexForPositionCalled += 1 searchPlaceIndexForPositionRequest = forPosition return SearchPlaceIndexForPositionOutput() diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation.swift index 0dc4080432..ce1ffe3c84 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation.swift @@ -33,16 +33,16 @@ public class MockAWSLocation: AWSLocationBehavior { public func getEscapeHatch() -> LocationClient { getEscapeHatchCalled += 1 - return self.locationClient + return locationClient } } -extension MockAWSLocation { - public func verifyGetEscapeHatch() { +public extension MockAWSLocation { + func verifyGetEscapeHatch() { XCTAssertEqual(getEscapeHatchCalled, 1) } - public func verifySearchPlaceIndexForText(_ request: SearchPlaceIndexForTextInput) { + func verifySearchPlaceIndexForText(_ request: SearchPlaceIndexForTextInput) { XCTAssertEqual(searchPlaceIndexForTextCalled, 1) guard let receivedRequest = searchPlaceIndexForTextRequest else { XCTFail("Did not receive request.") @@ -59,7 +59,7 @@ extension MockAWSLocation { XCTAssertEqual(receivedRequest.maxResults, request.maxResults) } - public func verifySearchPlaceIndexForPosition(_ request: SearchPlaceIndexForPositionInput) { + func verifySearchPlaceIndexForPosition(_ request: SearchPlaceIndexForPositionInput) { XCTAssertEqual(searchPlaceIndexForPositionCalled, 1) guard let receivedRequest = searchPlaceIndexForPositionRequest else { XCTFail("Did not receive request.") diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Support/Constants/GeoPluginTestConfig.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Support/Constants/GeoPluginTestConfig.swift index cf11c975e3..4efca9c8cf 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Support/Constants/GeoPluginTestConfig.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Support/Constants/GeoPluginTestConfig.swift @@ -9,7 +9,7 @@ import Foundation @testable @_spi(InternalAmplifyConfiguration) import Amplify @testable import AWSLocationGeoPlugin -struct GeoPluginTestConfig { +enum GeoPluginTestConfig { static let timeout = 1.0 // Plugin Test Configuration @@ -35,31 +35,38 @@ struct GeoPluginTestConfig { static let mapItemConfigJSON = JSONValue(dictionaryLiteral: (map, mapStyleConfigJSON)) - static let mapsConfigJSON = JSONValue(dictionaryLiteral: + static let mapsConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, mapItemConfigJSON), - (AWSLocationGeoPluginConfiguration.Node.default.key, testMapJSON)) + (AWSLocationGeoPluginConfiguration.Node.default.key, testMapJSON) + ) // MARK: - Search Config JSON static let searchIndexJSON = JSONValue(stringLiteral: searchIndex) static let searchItemsArrayJSON = JSONValue(arrayLiteral: searchIndexJSON) - static let searchConfigJSON = JSONValue(dictionaryLiteral: + static let searchConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.items.key, searchItemsArrayJSON), - (AWSLocationGeoPluginConfiguration.Node.default.key, searchIndexJSON)) + (AWSLocationGeoPluginConfiguration.Node.default.key, searchIndexJSON) + ) // MARK: - Plugin Config JSON static let regionJSON = JSONValue(stringLiteral: regionName) - static let geoPluginConfigJSON = JSONValue(dictionaryLiteral: + static let geoPluginConfigJSON = JSONValue( + dictionaryLiteral: (AWSLocationGeoPluginConfiguration.Node.region.key, regionJSON), (AWSLocationGeoPluginConfiguration.Section.maps.key, mapsConfigJSON), - (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, searchConfigJSON)) + (AWSLocationGeoPluginConfiguration.Section.searchIndices.key, searchConfigJSON) + ) static let geoPluginConfigAmplifyOutputs = AmplifyOutputsData( geo: .init( awsRegion: regionName, maps: .init(items: [map: .init(style: style)], default: map), searchIndices: .init(items: [searchIndex], default: searchIndex), - geofenceCollections: nil)) + geofenceCollections: nil + )) } diff --git a/AmplifyPlugins/Geo/Tests/GeoHostApp/AWSLocationGeoPluginIntegrationTests/AWSLocationGeoPluginIntegrationTests.swift b/AmplifyPlugins/Geo/Tests/GeoHostApp/AWSLocationGeoPluginIntegrationTests/AWSLocationGeoPluginIntegrationTests.swift index 682ef7f4be..6ff5a7bdf1 100644 --- a/AmplifyPlugins/Geo/Tests/GeoHostApp/AWSLocationGeoPluginIntegrationTests/AWSLocationGeoPluginIntegrationTests.swift +++ b/AmplifyPlugins/Geo/Tests/GeoHostApp/AWSLocationGeoPluginIntegrationTests/AWSLocationGeoPluginIntegrationTests.swift @@ -5,8 +5,8 @@ // SPDX-License-Identifier: Apache-2.0 // -import XCTest import AWSLocation +import XCTest @testable import Amplify @testable import AWSCognitoAuthPlugin diff --git a/AmplifyPlugins/Geo/Tests/GeoHostApp/GeoStressTests/GeoStressTests.swift b/AmplifyPlugins/Geo/Tests/GeoHostApp/GeoStressTests/GeoStressTests.swift index a512832e52..5b9c77b5f6 100644 --- a/AmplifyPlugins/Geo/Tests/GeoHostApp/GeoStressTests/GeoStressTests.swift +++ b/AmplifyPlugins/Geo/Tests/GeoHostApp/GeoStressTests/GeoStressTests.swift @@ -33,9 +33,9 @@ final class GeoStressTests: XCTestCase { override func tearDown() async throws { await Amplify.reset() } - + // MARK: - Stress Tests - + /// Test if concurrent execution of search(for: text) is successful /// - Given: Geo plugin with a valid configuration. /// - When: @@ -44,9 +44,9 @@ final class GeoStressTests: XCTestCase { /// - Place results are returned. /// func testMultipleSearchForText() async { - let successExpectation = expectation(description: "searchForText was successful") + let successExpectation = expectation(description: "searchForText was successful") successExpectation.expectedFulfillmentCount = concurrencyLimit - for _ in 1...concurrencyLimit { + for _ in 1 ... concurrencyLimit { Task { do { let options = Geo.SearchForTextOptions(area: .near(coordinates)) @@ -58,10 +58,10 @@ final class GeoStressTests: XCTestCase { } } } - + await fulfillment(of: [successExpectation], timeout: timeout) } - + /// Test if concurrent execution of search(for: coordinates) is successful /// - Given: Geo plugin with a valid configuration. /// - When: @@ -72,7 +72,7 @@ final class GeoStressTests: XCTestCase { func testMultipleSearchForCoordinates() async { let successExpectation = expectation(description: "searchForCoordinates was successful") successExpectation.expectedFulfillmentCount = concurrencyLimit - for _ in 1...concurrencyLimit { + for _ in 1 ... concurrencyLimit { Task { do { let places = try await Amplify.Geo.search(for: coordinates, options: nil) @@ -84,7 +84,7 @@ final class GeoStressTests: XCTestCase { } } } - + await fulfillment(of: [successExpectation], timeout: timeout) }