diff --git a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/GeoPluginConfigError.swift b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/GeoPluginConfigError.swift index fdf3fa39b3..ea23fb628c 100644 --- a/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/GeoPluginConfigError.swift +++ b/AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/GeoPluginConfigError.swift @@ -79,10 +79,6 @@ struct GeoPluginConfigError { } // MARK: - Maps - static let mapConfigMissing = """ - Map configuration is missing from amplifyconfiguration.json. - Make sure amplifyconfiguration.json includes a `maps` section. - """ static func mapInvalid(mapName: String) -> PluginError { PluginError.pluginConfigurationError( @@ -120,11 +116,6 @@ struct GeoPluginConfigError { } // MARK: - Search - static let searchConfigMissing = """ - Search configuration is missing from amplifyconfiguration.json. - Make amplifyconfiguration.json includes a `searchIndices` section. - """ - static func searchDefaultNotFound(indexName: String?) -> PluginError { PluginError.pluginConfigurationError( "Configured default search index \(indexName ?? "nil") was not found in searchIndices.", diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginConfigurationTests.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginConfigurationTests.swift index 06c68a424b..a1566b2fe2 100644 --- a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginConfigurationTests.swift +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/Configuration/AWSLocationGeoPluginConfigurationTests.swift @@ -137,6 +137,9 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { } } + /// - Given: geo plugin configuration + /// - When: the object initializes missing default map + /// - Then: the configuration fails to initialize with mapDefaultNotFound error func testConfigureThrowsErrorForDefaultMapNotFound() { let map = "missingMapName" let mapJSON = JSONValue(stringLiteral: map) @@ -159,6 +162,9 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { } } + /// - Given: geo plugin configuration + /// - When: the object initializes missing default search + /// - Then: the configuration fails to initialize with searchDefaultNotFound error func testConfigureThrowsErrorForDefaultSearchIndexNotFound() { let searchIndex = "missingSearchIndex" let searchIndexJSON = JSONValue(stringLiteral: searchIndex) @@ -180,4 +186,302 @@ class AWSLocationGeoPluginConfigurationTests: XCTestCase { 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)) + 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) + } + } + + /// - Given: geo plugin configuration + /// - 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)) + 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) + } + } + + /// - 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)) + 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) + } + } + + /// - Given: geo plugin configuration + /// - When: the object initializes without default map + /// - Then: the configuration fails to initialize with mapDefaultNotFound error + func testConfigureFailureWithoutDefaultMapsSection() async { + let mapName = "test" + let mapStyleJSON = JSONValue(stringLiteral: "VectorEsriStreets") + let mapStyleConfigJSON = JSONValue(dictionaryLiteral: + (AWSLocationGeoPluginConfiguration.Node.style.key, mapStyleJSON)) + let mapItemConfigJSON = JSONValue(dictionaryLiteral: (mapName, mapStyleConfigJSON)) + 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)) + 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) + } + } + + /// - Given: geo plugin configuration + /// - 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)) + 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) + } + + } + + + /// - Given: geo plugin configuration + /// - 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)) + 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) + } + } + + /// - 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)) + 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) + } + } + + /// - 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: + (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)) + 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) + } + } + + /// - Given: geo plugin configuration + /// - When: the object initializes with a invalid maps section + /// - Then: the configuration fails to initialize with mapStyleMissing error + func testConfigureFailureForMapStyleMissingError() async { + let mapStyleConfigJSON = JSONValue(dictionaryLiteral: + (AWSLocationGeoPluginConfiguration.Node.region.key, JSONValue(stringLiteral: ""))) + let mapItemConfigJSON = JSONValue(dictionaryLiteral: ("testMap", mapStyleConfigJSON)) + 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)) + 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) + } + } + + + /// - Given: geo plugin configuration + /// - When: the object initializes with a invalid maps section + /// - Then: the configuration fails to initialize with mapStyleMissing error + func testConfigureFailureForInvalidMapStyleURLError() async { + let mapName = "test Map" + let mapStyleJSON = JSONValue(stringLiteral: "VectorEsriStreets") + let mapStyleConfigJSON = JSONValue(dictionaryLiteral: + (AWSLocationGeoPluginConfiguration.Node.style.key, mapStyleJSON)) + let mapItemConfigJSON = JSONValue(dictionaryLiteral: (mapName, mapStyleConfigJSON)) + 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)) + 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.mapStyleURLInvalid(mapName: mapName).errorDescription) + } + } + + /// - Given: geo plugin configuration + /// - When: the object initializes with a invalid map style url + /// - Then: the configuration fails to initialize with mapStyleIsNotString error + func testConfigureFailureForMapStyleIsNotStringError() async { + let mapName = "testSearchIndex" + let mapStyleJSON = JSONValue(integerLiteral: 1) + let mapStyleConfigJSON = JSONValue(dictionaryLiteral: + (AWSLocationGeoPluginConfiguration.Node.style.key, mapStyleJSON)) + let mapItemConfigJSON = JSONValue(dictionaryLiteral: (mapName, mapStyleConfigJSON)) + 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)) + 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) + } + } + + /// - Given: geo plugin configuration + /// - When: object initializes with a invalid items search indices section + /// - Then: object fails to initialize with itemsInvalid error + func testConfigureFailureForInvalidItemsSearchIndicesSection() async { + let searchIndex = "testSearchIndex" + let searchIndexJSON = JSONValue(stringLiteral: searchIndex) + let searchItemsArrayJSON = JSONValue(stringLiteral: "") + 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)) + 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) + } + } + + /// - Given: geo plugin configuration + /// - When: configuration is initialize with with an array of int literals ofr search items + /// - Then: the object fails to initialize with a itemsIsNotStringArray error + func testConfigureFailureForEmptyItemsSearchIndicesSection() async { + let searchIndex = "testSearchIndex" + let searchIndexJSON = JSONValue(stringLiteral: searchIndex) + let searchItemsArrayJSON = JSONValue(arrayLiteral: 1) + 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)) + 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) + } + } + + /// - Given: geo plugin configuration + /// - When: configuration initializes with a mismatch search items and default item + /// - Then: the configuration fails to initializes with searchDefaultNotFound error + func testConfigureFailureForMissingDefaultSearchSection() async { + let searchIndex = "testSearchIndex" + let searchIndexJSON = JSONValue(stringLiteral: searchIndex) + let searchItemsArrayJSON = JSONValue(arrayLiteral: JSONValue(stringLiteral: "test")) + 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)) + 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) + } + } } diff --git a/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/GeoErrorHelperTests.swift b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/GeoErrorHelperTests.swift new file mode 100644 index 0000000000..9ae8f0ec1f --- /dev/null +++ b/AmplifyPlugins/Geo/Tests/AWSLocationGeoPluginTests/GeoErrorHelperTests.swift @@ -0,0 +1,187 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +@testable import AWSClientRuntime +@testable import AWSLocation +@testable import Amplify +@testable import AWSLocationGeoPlugin +import XCTest + +class GeoErrorHelperTests: AWSLocationGeoPluginTestBase { + /// - Given: a generic error + /// - When: GeoErrorHelper.mapAWSLocationError is called with the generic error + /// - Then: a default Geo.Error.unknown is returned + func testGeoErrorHelperMapsDefaultError() { + let error = GeoErrorHelper.mapAWSLocationError(GenericError.validation) + switch error { + case .unknown(_, _, _): + break + default: + XCTFail("Failed to map to default error") + } + } + + /// - Given: SearchPlaceIndexForTextOutputError of access denied + /// - When: GeoErrorHelper.mapAWSLocationError is called with the SearchPlaceIndexForTextOutputError + /// - Then: a default Geo.Error.accessDenied is returned + func testGeoErrorHelperMapsSearchPlaceIndexForTextOutputErrorAccessDenied() { + let error = GeoErrorHelper.mapAWSLocationError(SearchPlaceIndexForTextOutputError.accessDeniedException(AccessDeniedException())) + switch error { + case .accessDenied(_, _, _): + break + default: + XCTFail("Failed to map to default error") + } + } + + /// - Given: SearchPlaceIndexForTextOutputError of internal server + /// - When: GeoErrorHelper.mapAWSLocationError is called with the SearchPlaceIndexForTextOutputError + /// - Then: a default Geo.Error.serviceError is returned + func testGeoErrorHelperMapsSearchPlaceIndexForTextOutputErrorInternalServer() { + let error = GeoErrorHelper.mapAWSLocationError(SearchPlaceIndexForTextOutputError.internalServerException(InternalServerException())) + switch error { + case .serviceError(_, _, _): + break + default: + XCTFail("Failed to map to default error") + } + } + + /// - Given: SearchPlaceIndexForTextOutputError of resource not found + /// - When: GeoErrorHelper.mapAWSLocationError is called with the SearchPlaceIndexForTextOutputError + /// - Then: a default Geo.Error.serviceError is returned + func testGeoErrorHelperMapsSearchPlaceIndexForTextOutputErrorResourceNotFound() { + let error = GeoErrorHelper.mapAWSLocationError(SearchPlaceIndexForTextOutputError.resourceNotFoundException(ResourceNotFoundException())) + switch error { + case .serviceError(_, _, _): + break + default: + XCTFail("Failed to map to service error") + } + } + + /// - Given: SearchPlaceIndexForTextOutputError of throttling + /// - When: GeoErrorHelper.mapAWSLocationError is called with the SearchPlaceIndexForTextOutputError + /// - Then: a default Geo.Error.serviceError is returned + func testGeoErrorHelperMapsSearchPlaceIndexForTextOutputErrorThrottling() { + let error = GeoErrorHelper.mapAWSLocationError(SearchPlaceIndexForTextOutputError.throttlingException(ThrottlingException())) + switch error { + case .serviceError(_, _, _): + break + default: + XCTFail("Failed to map to service error") + } + } + + /// - Given: SearchPlaceIndexForTextOutputError of validation + /// - When: GeoErrorHelper.mapAWSLocationError is called with the SearchPlaceIndexForTextOutputError + /// - Then: a default Geo.Error.serviceError is returned + func testGeoErrorHelperMapsSearchPlaceIndexForTextOutputErrorValidation() { + let error = GeoErrorHelper.mapAWSLocationError(SearchPlaceIndexForTextOutputError.validationException(ValidationException())) + switch error { + case .serviceError(_, _, _): + break + default: + XCTFail("Failed to map to service error") + } + } + + /// - Given: SearchPlaceIndexForTextOutputError of unknown + /// - When: GeoErrorHelper.mapAWSLocationError is called with the SearchPlaceIndexForTextOutputError + /// - Then: a default Geo.Error.unknown is returned + func testGeoErrorHelperMapsSearchPlaceIndexForTextOutputErrorUnknown() { + let error = GeoErrorHelper.mapAWSLocationError(SearchPlaceIndexForTextOutputError.unknown(UnknownAWSHttpServiceError())) + switch error { + case .unknown(_, _, _): + break + default: + XCTFail("Failed to map to unknown error") + } + } + + /// - Given: SearchPlaceIndexForPositionOutputError of access denied + /// - When: GeoErrorHelper.mapAWSLocationError is called with the SearchPlaceIndexForPositionOutputError + /// - Then: a default Geo.Error.accessDenied is returned + func testGeoErrorHelperMapsSearchPlaceIndexForPositionOutputErrorAccessDenied() { + let error = GeoErrorHelper.mapAWSLocationError(SearchPlaceIndexForPositionOutputError.accessDeniedException(AccessDeniedException())) + switch error { + case .accessDenied(_, _, _): + break + default: + XCTFail("Failed to map to default error") + } + } + + /// - Given: SearchPlaceIndexForPositionOutputError of internal server + /// - When: GeoErrorHelper.mapAWSLocationError is called with the SearchPlaceIndexForPositionOutputError + /// - Then: a default Geo.Error.serviceError is returned + func testGeoErrorHelperMapsSearchPlaceIndexForPositionOutputErrorInternalServer() { + let error = GeoErrorHelper.mapAWSLocationError(SearchPlaceIndexForPositionOutputError.internalServerException(InternalServerException())) + switch error { + case .serviceError(_, _, _): + break + default: + XCTFail("Failed to map to default error") + } + } + + /// - Given: SearchPlaceIndexForPositionOutputError of resource not found + /// - When: GeoErrorHelper.mapAWSLocationError is called with the SearchPlaceIndexForPositionOutputError + /// - Then: a default Geo.Error.serviceError is returned + func testGeoErrorHelperMapsSearchPlaceIndexForPositionOutputErrorErrorResourceNotFound() { + let error = GeoErrorHelper.mapAWSLocationError(SearchPlaceIndexForPositionOutputError.resourceNotFoundException(ResourceNotFoundException())) + switch error { + case .serviceError(_, _, _): + break + default: + XCTFail("Failed to map to service error") + } + } + + /// - Given: SearchPlaceIndexForPositionOutputError of throttling + /// - When: GeoErrorHelper.mapAWSLocationError is called with the SearchPlaceIndexForPositionOutputError + /// - Then: a default Geo.Error.serviceError is returned + func testGeoErrorHelperMapsSearchPlaceIndexForPositionOutputErrorThrottling() { + let error = GeoErrorHelper.mapAWSLocationError(SearchPlaceIndexForPositionOutputError.throttlingException(ThrottlingException())) + switch error { + case .serviceError(_, _, _): + break + default: + XCTFail("Failed to map to service error") + } + } + + /// - Given: SearchPlaceIndexForPositionOutputError of validation + /// - When: GeoErrorHelper.mapAWSLocationError is called with the SearchPlaceIndexForPositionOutputError + /// - Then: a default Geo.Error.serviceError is returned + func testGeoErrorHelperMapsSearchPlaceIndexForPositionOutputErrorValidation() { + let error = GeoErrorHelper.mapAWSLocationError(SearchPlaceIndexForPositionOutputError.validationException(ValidationException())) + switch error { + case .serviceError(_, _, _): + break + default: + XCTFail("Failed to map to service error") + } + } + + /// - Given: SearchPlaceIndexForPositionOutputError of unknown + /// - When: GeoErrorHelper.mapAWSLocationError is called with the SearchPlaceIndexForPositionOutputError + /// - Then: a default Geo.Error.unknown is returned + func testGeoErrorHelperMapsSSearchPlaceIndexForPositionOutputErrorUnknown() { + let error = GeoErrorHelper.mapAWSLocationError(SearchPlaceIndexForPositionOutputError.unknown(UnknownAWSHttpServiceError())) + switch error { + case .unknown(_, _, _): + break + default: + XCTFail("Failed to map to unknown error") + } + } +} + +enum GenericError: Error { + case validation +}