From 9becf9e5229f883b6ed742a76efa34a8963635c2 Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Mon, 9 Sep 2024 16:36:16 -0500 Subject: [PATCH] updated swiftformat rules --- .../AWSLocationGeoPlugin+ClientBehavior.swift | 92 +++-- .../AWSLocationGeoPlugin+Configure.swift | 17 +- .../AWSLocationGeoPluginConfiguration.swift | 102 +++--- .../Constants/GeoPluginErrorConstants.swift | 9 +- ...LocationGeoPluginClientBehaviorTests.swift | 18 +- .../AWSLocationGeoPluginTestBase.swift | 26 +- ...uginAmplifyOutputsConfigurationTests.swift | 33 +- ...SLocationGeoPluginConfigurationTests.swift | 326 ++++++++++++------ .../MockAWSLocation+ClientBehavior.swift | 22 +- .../Constants/GeoPluginTestConfig.swift | 21 +- 10 files changed, 424 insertions(+), 242 deletions(-) diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+ClientBehavior.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+ClientBehavior.swift index 3796a1ce68..20a02f8683 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+ClientBehavior.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+ClientBehavior.swift @@ -30,9 +30,10 @@ public 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 - 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() @@ -42,7 +43,8 @@ public extension AWSLocationGeoPlugin { guard request.indexName != nil else { throw Geo.Error.invalidConfiguration( GeoPluginErrorConstants.missingDefaultSearchIndex.errorDescription, - GeoPluginErrorConstants.missingDefaultSearchIndex.recoverySuggestion) + GeoPluginErrorConstants.missingDefaultSearchIndex.recoverySuggestion + ) } request.text = text @@ -50,13 +52,17 @@ public 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 + ] } } @@ -84,16 +90,18 @@ public 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 { @@ -122,9 +130,10 @@ public 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 - 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 @@ public 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 @@ -158,16 +170,18 @@ public 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 { @@ -197,7 +211,8 @@ public extension AWSLocationGeoPlugin { guard !mapStyles.isEmpty else { throw Geo.Error.invalidConfiguration( GeoPluginErrorConstants.missingMaps.errorDescription, - GeoPluginErrorConstants.missingMaps.recoverySuggestion) + GeoPluginErrorConstants.missingMaps.recoverySuggestion + ) } return mapStyles } @@ -215,7 +230,8 @@ public extension AWSLocationGeoPlugin { 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 d1d9d29d4b..b07b16e435 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Configure.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Configure.swift @@ -49,9 +49,11 @@ public 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,10 +66,11 @@ public extension AWSLocationGeoPlugin { /// - locationService: The location service object. /// - authService: The authentication service object. /// - pluginConfig: The configuration for the plugin. - internal 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/Configuration/AWSLocationGeoPluginConfiguration.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/AWSLocationGeoPluginConfiguration.swift index 65bdc81afc..b4f25e9fe2 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/AWSLocationGeoPluginConfiguration.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/AWSLocationGeoPluginConfiguration.swift @@ -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,23 +48,31 @@ 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 { @@ -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,19 +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 @@ -163,9 +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 @@ -202,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) } @@ -217,12 +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/Support/Constants/GeoPluginErrorConstants.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Constants/GeoPluginErrorConstants.swift index 828cca0bc5..f3c9b7fc7e 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Constants/GeoPluginErrorConstants.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Support/Constants/GeoPluginErrorConstants.swift @@ -11,15 +11,18 @@ import Foundation 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/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginClientBehaviorTests.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginClientBehaviorTests.swift index 438cccc387..a26a9e14ff 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginClientBehaviorTests.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginClientBehaviorTests.swift @@ -54,8 +54,10 @@ class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase { _ = try await geoPlugin.search(for: searchText, options: options) var request = SearchPlaceIndexForTextInput() request.text = searchText - request.biasPosition = [coordinates.longitude, - coordinates.latitude] + request.biasPosition = [ + coordinates.longitude, + coordinates.latitude + ] request.filterCountries = options.countries?.map(\.code) request.maxResults = options.maxResults ?? 0 request.indexName = (options.pluginOptions as? AWSLocationGeoPluginSearchOptions)?.searchIndex @@ -100,8 +102,10 @@ class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase { do { _ = try await geoPlugin.search(for: coordinates, options: nil) var request = SearchPlaceIndexForPositionInput() - request.position = [coordinates.longitude, - coordinates.latitude] + request.position = [ + coordinates.longitude, + coordinates.latitude + ] mockLocation.verifySearchPlaceIndexForPosition(request) } catch { XCTFail("Failed with error: \(error)") @@ -124,8 +128,10 @@ class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase { do { _ = try await geoPlugin.search(for: coordinates, options: options) var request = SearchPlaceIndexForPositionInput() - request.position = [coordinates.longitude, - coordinates.latitude] + request.position = [ + coordinates.longitude, + coordinates.latitude + ] request.maxResults = options.maxResults ?? 0 request.indexName = (options.pluginOptions as? AWSLocationGeoPluginSearchOptions)?.searchIndex mockLocation.verifySearchPlaceIndexForPosition(request) diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginTestBase.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginTestBase.swift index 4f0afb004f..c1b70fff6d 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginTestBase.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/AWSLocationGeoPluginTestBase.swift @@ -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 6d7391e662..fd98bfa0fd 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginAmplifyOutputsConfigurationTests.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginAmplifyOutputsConfigurationTests.swift @@ -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 d2a7e7c3a1..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,21 +176,27 @@ 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 + ) } } @@ -178,15 +204,19 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { /// - 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,16 +224,20 @@ 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 + ) } } @@ -212,16 +246,20 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { /// - 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 + ) } } @@ -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,18 +325,24 @@ 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 + ) } } @@ -295,16 +351,20 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { /// - 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 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 + ) } } @@ -313,19 +373,25 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { /// - 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 + ) } } @@ -336,19 +402,25 @@ 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 + ) } } @@ -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)") @@ -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,19 +519,25 @@ 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 + ) } } @@ -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/MockAWSLocation+ClientBehavior.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation+ClientBehavior.swift index bb864f0ed1..87ec14aee0 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation+ClientBehavior.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Mocks/MockAWSLocation+ClientBehavior.swift @@ -11,10 +11,13 @@ import Foundation public extension MockAWSLocation { - func searchPlaceIndex(forText: SearchPlaceIndexForTextInput, - completionHandler: ((SearchPlaceIndexForTextOutput?, - Error?) -> Void)?) - { + func searchPlaceIndex( + forText: SearchPlaceIndexForTextInput, + completionHandler: (( + SearchPlaceIndexForTextOutput?, + Error? + ) -> Void)? + ) { searchPlaceIndexForTextCalled += 1 searchPlaceIndexForTextRequest = forText if let completionHandler { @@ -22,10 +25,13 @@ public extension MockAWSLocation { } } - func searchPlaceIndex(forPosition: SearchPlaceIndexForPositionInput, - completionHandler: ((SearchPlaceIndexForPositionOutput?, - Error?) -> Void)?) - { + func searchPlaceIndex( + forPosition: SearchPlaceIndexForPositionInput, + completionHandler: (( + SearchPlaceIndexForPositionOutput?, + Error? + ) -> Void)? + ) { searchPlaceIndexForPositionCalled += 1 searchPlaceIndexForPositionRequest = forPosition if let completionHandler { diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Support/Constants/GeoPluginTestConfig.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Support/Constants/GeoPluginTestConfig.swift index 1587de563c..4efca9c8cf 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Support/Constants/GeoPluginTestConfig.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Support/Constants/GeoPluginTestConfig.swift @@ -35,31 +35,38 @@ enum 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 + )) }