From 6cb725565cc68409a051a98f5d806c38668ace80 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Tue, 13 Feb 2024 13:25:01 -0500 Subject: [PATCH 01/17] Fix typo --- .../MapboxSearchIntegrationTests/OfflineIntegrationTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index c8cdb2580..4b649dbdf 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -65,7 +65,7 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase { XCTAssert(region.completedResourceCount > 0) XCTAssertEqual(region.requiredResourceCount, region.completedResourceCount) case .failure(let error): - XCTFail("Unable to load Regin, \(error.localizedDescription)") + XCTFail("Unable to load Region, \(error.localizedDescription)") } loadDataExpectation.fulfill() } From 92a19caa49a3f6185dc1a268ef48810d384d519b Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 14 Feb 2024 11:08:50 -0500 Subject: [PATCH 02/17] Move MockResponse to protocol, add httpMethod and path fields - Rename existing MockResponse to LegacyResponse and conform to new MockResponse - Move httpMethod and path accessors out of MockWebServer and into MockResponse instances - Begin moving toward generalized MockResponses to distinguish Mocks by API type of geocoding, SBS, and search-box --- .../MockServerIntegrationTestCase.swift | 2 +- Tests/MapboxSearchUITests/BaseTestCase.swift | 1 + ...tegorySuggestionsIntegrationTestCase.swift | 4 +- ...estionsNavigationIntegrationTestCase.swift | 4 +- .../FeedbackIntegrationTestCase.swift | 4 +- .../MockWebServer/MockResponse.swift | 89 +++++++++++++++++- .../MockWebServer/MockWebServer.swift | 94 ++----------------- 7 files changed, 104 insertions(+), 94 deletions(-) diff --git a/Tests/MapboxSearchIntegrationTests/MockServerIntegrationTestCase.swift b/Tests/MapboxSearchIntegrationTests/MockServerIntegrationTestCase.swift index b75bfe048..cb2401b33 100644 --- a/Tests/MapboxSearchIntegrationTests/MockServerIntegrationTestCase.swift +++ b/Tests/MapboxSearchIntegrationTests/MockServerIntegrationTestCase.swift @@ -5,7 +5,7 @@ import XCTest class MockServerIntegrationTestCase: XCTestCase { let server = MockWebServer() - func setServerResponse(_ response: MockResponse, query: String? = nil) throws { + func setServerResponse(_ response: LegacyResponse, query: String? = nil) throws { try server.setResponse(response, query: query) } diff --git a/Tests/MapboxSearchUITests/BaseTestCase.swift b/Tests/MapboxSearchUITests/BaseTestCase.swift index ff38336d7..6ad969531 100644 --- a/Tests/MapboxSearchUITests/BaseTestCase.swift +++ b/Tests/MapboxSearchUITests/BaseTestCase.swift @@ -1,5 +1,6 @@ import XCTest +/// UI tests will always use the recommended API engine type for each provided SearchEngine and SearchEngine samples. class BaseTestCase: XCTestCase { static let defaultTimeout: TimeInterval = 10.0 diff --git a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift index 51b6b7feb..bd2cb4712 100644 --- a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift @@ -6,8 +6,8 @@ class CategorySuggestionsIntegrationTestCase: MockServerUITestCase { try super.setUpWithError() app.launch() - try server.setResponse(.suggestCategories) - try server.setResponse(.retrieveCategory) + try server.setResponse(LegacyResponse.suggestCategories) + try server.setResponse(LegacyResponse.retrieveCategory) } func testCafeCategorySuggestions() throws { diff --git a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsNavigationIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsNavigationIntegrationTestCase.swift index 3b29734ee..47fb77072 100644 --- a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsNavigationIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsNavigationIntegrationTestCase.swift @@ -5,8 +5,8 @@ class CategorySuggestionsNavigationIntegrationTestCase: MockServerUITestCase { try super.setUpWithError() app.launch() - try server.setResponse(.suggestCategories) - try server.setResponse(.retrieveCategory) + try server.setResponse(LegacyResponse.suggestCategories) + try server.setResponse(LegacyResponse.retrieveCategory) } func testCancelCategorySuggestionsSearch() { diff --git a/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift index 3ef0bfc73..ca31af53c 100644 --- a/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift @@ -6,8 +6,8 @@ class FeedbackIntegrationTestCase: MockServerUITestCase { override func setUpWithError() throws { try super.setUpWithError() - try server.setResponse(.suggestSanFrancisco) - try server.setResponse(.retrieveSanFrancisco) + try server.setResponse(LegacyResponse.suggestSanFrancisco) + try server.setResponse(LegacyResponse.retrieveSanFrancisco) } func testSendFeedback() throws { diff --git a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift index 613d561fd..db2b0cb71 100644 --- a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift +++ b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift @@ -1,6 +1,17 @@ import Foundation -enum MockResponse { +protocol MockResponse { + /// Resource from test bundle containing response JSON. + var filepath: String { get } + + /// HTTP Method used for this request, "GET" or "POST". + var httpMethod: MockWebServer.HTTPMethod { get } + + /// URL path for this request. + var path: String { get } +} + +enum LegacyResponse: MockResponse { case suggestEmpty case suggestMinsk case suggestSanFrancisco @@ -66,4 +77,80 @@ enum MockResponse { return bundle.path(forResource: "address-retrieve-san-francisco", ofType: "json")! } } + + var path: String { + var path = "/search/v1" + + switch self { + case .suggestAddressSanFrancisco: + path = "/autofill/v1/suggest/:query" + + case .retrieveAddressSanFrancisco: + path = "/autofill/v1/retrieve/:action.id" + + case .forwardGeocoding: + path = "/geocoding/v5/mapbox.places/:query" + + case .suggestMinsk: + path += "/suggest/Minsk" + + case .suggestSanFrancisco: + path += "/suggest/San Francisco" + + case .suggestEmpty, + .suggestCategories, + .suggestWithCoordinates, + .suggestWithMixedCoordinates, + .suggestCategoryWithCoordinates, + .recursion: + path += "/suggest/:query" + + case .retrieveSanFrancisco, + .retrieveCategory, + .retrieveMinsk, + .retrievePoi: + path += "/retrieve" + + case .reverseGeocoding: + path = "geocoding/v5/mapbox.places/:location" + + case .reverseGeocodingSBS: + path += "/:coordinates" + + case .multiRetrieve: + path += "/retrieve/multi" + + case .categoryCafe: + path += "/category/:category" + } + + return path + } + + var httpMethod: MockWebServer.HTTPMethod { + switch self { + case .suggestAddressSanFrancisco, + .retrieveAddressSanFrancisco, + .forwardGeocoding, + .suggestMinsk, + .suggestSanFrancisco, + .suggestEmpty, + .suggestCategories, + .suggestWithCoordinates, + .suggestWithMixedCoordinates, + .suggestCategoryWithCoordinates, + .recursion, + .reverseGeocoding, + .reverseGeocodingSBS, + .categoryCafe: + return .get + + case .multiRetrieve, + .retrieveSanFrancisco, + .retrieveCategory, + .retrieveMinsk, + .retrievePoi: + return .post + } + } } diff --git a/Tests/MapboxSearchUITests/MockWebServer/MockWebServer.swift b/Tests/MapboxSearchUITests/MockWebServer/MockWebServer.swift index c2ea48815..0165b0e7d 100644 --- a/Tests/MapboxSearchUITests/MockWebServer/MockWebServer.swift +++ b/Tests/MapboxSearchUITests/MockWebServer/MockWebServer.swift @@ -1,14 +1,14 @@ import Foundation import Swifter -final class MockWebServer { +final class MockWebServer { let endpoint = "http://localhost:8080" private let server = HttpServer() - func setResponse(_ response: MockResponse, query: String? = nil, statusCode: Int = 200) throws { - let route = Self.path(for: response) - let method = Self.httpMethod(for: response) + func setResponse(_ response: Mock, query: String? = nil, statusCode: Int = 200) throws { + let route = response.path + let method = response.httpMethod let response = HttpResponse.raw(statusCode, "mocked response", nil) { writer in try writer.write( @@ -25,9 +25,9 @@ final class MockWebServer { } } - func setResponse(endpoint: MockResponse, query: String? = nil, body: String, statusCode: Int) { - let route = Self.path(for: endpoint) - let method = Self.httpMethod(for: endpoint) + func setResponse(endpoint: Mock, query: String? = nil, body: String, statusCode: Int) { + let route = endpoint.path + let method = endpoint.httpMethod let response = HttpResponse.raw(statusCode, "mocked response", nil) { writer in try writer.write(body.data(using: .utf8)!) @@ -51,86 +51,8 @@ final class MockWebServer { } } -// MARK: - private - extension MockWebServer { - fileprivate enum HTTPMethod { + enum HTTPMethod { case get, post } - - fileprivate static func httpMethod(for response: MockResponse) -> HTTPMethod { - switch response { - case .suggestAddressSanFrancisco, - .retrieveAddressSanFrancisco, - .forwardGeocoding, - .suggestMinsk, - .suggestSanFrancisco, - .suggestEmpty, - .suggestCategories, - .suggestWithCoordinates, - .suggestWithMixedCoordinates, - .suggestCategoryWithCoordinates, - .recursion, - .reverseGeocoding, - .reverseGeocodingSBS, - .categoryCafe: - return .get - - case .multiRetrieve, - .retrieveSanFrancisco, - .retrieveCategory, - .retrieveMinsk, - .retrievePoi: - return .post - } - } - - fileprivate static func path(for response: MockResponse) -> String { - var path = "/search/v1" - - switch response { - case .suggestAddressSanFrancisco: - path = "/autofill/v1/suggest/:query" - - case .retrieveAddressSanFrancisco: - path = "/autofill/v1/retrieve/:action.id" - - case .forwardGeocoding: - path = "/geocoding/v5/mapbox.places/:query" - - case .suggestMinsk: - path += "/suggest/Minsk" - - case .suggestSanFrancisco: - path += "/suggest/San Francisco" - - case .suggestEmpty, - .suggestCategories, - .suggestWithCoordinates, - .suggestWithMixedCoordinates, - .suggestCategoryWithCoordinates, - .recursion: - path += "/suggest/:query" - - case .retrieveSanFrancisco, - .retrieveCategory, - .retrieveMinsk, - .retrievePoi: - path += "/retrieve" - - case .reverseGeocoding: - path = "geocoding/v5/mapbox.places/:location" - - case .reverseGeocodingSBS: - path += "/:coordinates" - - case .multiRetrieve: - path += "/retrieve/multi" - - case .categoryCafe: - path += "/category/:category" - } - - return path - } } From b508e7190da871d9a29cb3d8c523b1515fc34e67 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 14 Feb 2024 11:21:27 -0500 Subject: [PATCH 03/17] Change MockServerIntegrationTestCase and MockWebServer to generics containing a MockResponse - Conform all integration tests to generics with LegacyResponse as the value for now - Next up: split LegacyResponse into specific enums for each API type --- .../AddressAutofillIntegrationTests.swift | 2 +- .../CategorySearchEngineIntegrationTests.swift | 2 +- .../MockServerIntegrationTestCase.swift | 6 +++--- .../OfflineIntegrationTests.swift | 2 +- .../PlaceAutocompleteIntegrationTests.swift | 2 +- .../SearchEngineGeocodingIntegrationTests.swift | 2 +- .../SearchEngineIntegrationTests.swift | 2 +- Tests/MapboxSearchUITests/MockServerUITestCase.swift | 2 +- Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift | 7 ++++--- .../MapboxSearchUITests/MockWebServer/MockWebServer.swift | 2 +- 10 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift index 6cc2d6962..941ec7c4b 100644 --- a/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift @@ -2,7 +2,7 @@ import CoreLocation @testable import MapboxSearch import XCTest -final class AddressAutofillIntegrationTests: MockServerIntegrationTestCase { +final class AddressAutofillIntegrationTests: MockServerIntegrationTestCase { private var addressAutofill: AddressAutofill! private let locationProvider = WrapperLocationProvider(wrapping: DefaultLocationProvider()) diff --git a/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift index 841b20f2f..5ea02448d 100644 --- a/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift @@ -2,7 +2,7 @@ import CoreLocation @testable import MapboxSearch import XCTest -final class CategorySearchEngineIntegrationTests: MockServerIntegrationTestCase { +final class CategorySearchEngineIntegrationTests: MockServerIntegrationTestCase { private var searchEngine: CategorySearchEngine! override func setUp() { diff --git a/Tests/MapboxSearchIntegrationTests/MockServerIntegrationTestCase.swift b/Tests/MapboxSearchIntegrationTests/MockServerIntegrationTestCase.swift index cb2401b33..3c7c1f596 100644 --- a/Tests/MapboxSearchIntegrationTests/MockServerIntegrationTestCase.swift +++ b/Tests/MapboxSearchIntegrationTests/MockServerIntegrationTestCase.swift @@ -2,10 +2,10 @@ import CoreLocation @testable import MapboxSearch import XCTest -class MockServerIntegrationTestCase: XCTestCase { - let server = MockWebServer() +class MockServerIntegrationTestCase: XCTestCase { + let server = MockWebServer() - func setServerResponse(_ response: LegacyResponse, query: String? = nil) throws { + func setServerResponse(_ response: Mock, query: String? = nil) throws { try server.setResponse(response, query: query) } diff --git a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index 4b649dbdf..d24be506c 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -6,7 +6,7 @@ import MapboxCommon @testable import MapboxSearch import XCTest -class OfflineIntegrationTests: MockServerIntegrationTestCase { +class OfflineIntegrationTests: MockServerIntegrationTestCase { let delegate = SearchEngineDelegateStub() let searchEngine = SearchEngine() diff --git a/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift index 8c2ae9b0a..5a21d541b 100644 --- a/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift @@ -2,7 +2,7 @@ import CoreLocation @testable import MapboxSearch import XCTest -final class PlaceAutocompleteIntegrationTests: MockServerIntegrationTestCase { +final class PlaceAutocompleteIntegrationTests: MockServerIntegrationTestCase { private var placeAutocomplete: PlaceAutocomplete! override func setUp() { diff --git a/Tests/MapboxSearchIntegrationTests/SearchEngineGeocodingIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/SearchEngineGeocodingIntegrationTests.swift index 6c5cbda1c..45dedddfa 100644 --- a/Tests/MapboxSearchIntegrationTests/SearchEngineGeocodingIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/SearchEngineGeocodingIntegrationTests.swift @@ -2,7 +2,7 @@ import CoreLocation @testable import MapboxSearch import XCTest -class SearchEngineGeocodingIntegrationTests: MockServerIntegrationTestCase { +class SearchEngineGeocodingIntegrationTests: MockServerIntegrationTestCase { let delegate = SearchEngineDelegateStub() var searchEngine: SearchEngine! diff --git a/Tests/MapboxSearchIntegrationTests/SearchEngineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/SearchEngineIntegrationTests.swift index 3fb4112f2..4b5b3607f 100644 --- a/Tests/MapboxSearchIntegrationTests/SearchEngineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/SearchEngineIntegrationTests.swift @@ -2,7 +2,7 @@ import CoreLocation @testable import MapboxSearch import XCTest -class SearchEngineIntegrationTests: MockServerIntegrationTestCase { +class SearchEngineIntegrationTests: MockServerIntegrationTestCase { let delegate = SearchEngineDelegateStub() var searchEngine: SearchEngine! diff --git a/Tests/MapboxSearchUITests/MockServerUITestCase.swift b/Tests/MapboxSearchUITests/MockServerUITestCase.swift index 4950a9ee8..3925af2e9 100644 --- a/Tests/MapboxSearchUITests/MockServerUITestCase.swift +++ b/Tests/MapboxSearchUITests/MockServerUITestCase.swift @@ -1,7 +1,7 @@ import Foundation class MockServerUITestCase: BaseTestCase { - let server = MockWebServer() + let server = MockWebServer() override func setUpWithError() throws { try super.setUpWithError() diff --git a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift index db2b0cb71..f1d5d9708 100644 --- a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift +++ b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift @@ -1,11 +1,12 @@ import Foundation +import Swifter protocol MockResponse { /// Resource from test bundle containing response JSON. var filepath: String { get } /// HTTP Method used for this request, "GET" or "POST". - var httpMethod: MockWebServer.HTTPMethod { get } + var httpMethod: HttpServer.HTTPMethod { get } /// URL path for this request. var path: String { get } @@ -35,7 +36,7 @@ enum LegacyResponse: MockResponse { case categoryCafe var filepath: String { - let bundle = Bundle(for: MockWebServer.self) + let bundle = Bundle(for: MockWebServer.self) switch self { case .suggestEmpty: return bundle.path(forResource: "suggestions-empty", ofType: "json")! @@ -127,7 +128,7 @@ enum LegacyResponse: MockResponse { return path } - var httpMethod: MockWebServer.HTTPMethod { + var httpMethod: HttpServer.HTTPMethod { switch self { case .suggestAddressSanFrancisco, .retrieveAddressSanFrancisco, diff --git a/Tests/MapboxSearchUITests/MockWebServer/MockWebServer.swift b/Tests/MapboxSearchUITests/MockWebServer/MockWebServer.swift index 0165b0e7d..29d646003 100644 --- a/Tests/MapboxSearchUITests/MockWebServer/MockWebServer.swift +++ b/Tests/MapboxSearchUITests/MockWebServer/MockWebServer.swift @@ -51,7 +51,7 @@ final class MockWebServer { } } -extension MockWebServer { +extension HttpServer { enum HTTPMethod { case get, post } From e992fa16f5175e7ac3e4dae7cb31058489059aad Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 14 Feb 2024 15:08:51 -0500 Subject: [PATCH 04/17] Start implementing AutofillMockResponse for integration tests with Autofill - Add static MockResponse.apiType and associated type Mock in MockServerIntegrationTestCase so that subclasses can query Mock.apiType when instantiating SearchEngines based on the generic. - Also provides the MockResponse parameter generic type - Add extension on CoreSearchEngine.ApiType to bridge to MapboxSearch.ApiType enum (does not contain Autofill or search-box) - Replace hard-coded apiType: .geocoding parameters with XCTUnwrap(apiType: Mock.coreApiType.toSDKType()) - Add AutofillMockResponse with only endpoints used by the Autofill engine and tests! --- MapboxSearch.xcodeproj/project.pbxproj | 8 +++ .../AddressAutofillIntegrationTests.swift | 4 +- ...CategorySearchEngineIntegrationTests.swift | 7 +-- .../MockServerIntegrationTestCase.swift | 1 + .../PlaceAutocompleteIntegrationTests.swift | 2 +- ...earchEngineGeocodingIntegrationTests.swift | 7 +-- .../SearchEngineIntegrationTests.swift | 7 +-- .../Extensions/CoreApiType+ToSDKType.swift | 17 ++++++ .../MockWebServer/MockResponse.swift | 52 +++++++++++++++++++ 9 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 Tests/MapboxSearchTests/Common/Extensions/CoreApiType+ToSDKType.swift diff --git a/MapboxSearch.xcodeproj/project.pbxproj b/MapboxSearch.xcodeproj/project.pbxproj index 55a8aeade..43d620582 100644 --- a/MapboxSearch.xcodeproj/project.pbxproj +++ b/MapboxSearch.xcodeproj/project.pbxproj @@ -12,6 +12,9 @@ 042477C62B72CCB000D870D5 /* geocoding-reverse-geocoding.json in Resources */ = {isa = PBXBuildFile; fileRef = 042477C42B72CCB000D870D5 /* geocoding-reverse-geocoding.json */; }; 042477C72B72CCB000D870D5 /* geocoding-reverse-geocoding.json in Resources */ = {isa = PBXBuildFile; fileRef = 042477C42B72CCB000D870D5 /* geocoding-reverse-geocoding.json */; }; 043A3D4D2B30F38300DB681B /* CoreAddress+AddressComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043A3D4C2B30F38300DB681B /* CoreAddress+AddressComponents.swift */; }; + 045514C22B7D4B58000D88B9 /* CoreApiType+ToSDKType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 045514C12B7D4B58000D88B9 /* CoreApiType+ToSDKType.swift */; }; + 045514C32B7D4B58000D88B9 /* CoreApiType+ToSDKType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 045514C12B7D4B58000D88B9 /* CoreApiType+ToSDKType.swift */; }; + 045514C42B7D4B58000D88B9 /* CoreApiType+ToSDKType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 045514C12B7D4B58000D88B9 /* CoreApiType+ToSDKType.swift */; }; 04970F8D2B7A97C900213763 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 04970F8C2B7A97C900213763 /* PrivacyInfo.xcprivacy */; }; 04AB0B4B2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B4A2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json */; }; 04AB0B4C2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B4A2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json */; }; @@ -494,6 +497,7 @@ 042477C12B7290E700D870D5 /* SearchEngineGeocodingIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchEngineGeocodingIntegrationTests.swift; sourceTree = ""; }; 042477C42B72CCB000D870D5 /* geocoding-reverse-geocoding.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "geocoding-reverse-geocoding.json"; sourceTree = ""; }; 043A3D4C2B30F38300DB681B /* CoreAddress+AddressComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CoreAddress+AddressComponents.swift"; sourceTree = ""; }; + 045514C12B7D4B58000D88B9 /* CoreApiType+ToSDKType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CoreApiType+ToSDKType.swift"; sourceTree = ""; }; 04970F8C2B7A97C900213763 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 04AB0B4A2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = mapbox.places.san.francisco.json; sourceTree = ""; }; 04BBC6332B61898F00E24E99 /* LocalhostMockServiceProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalhostMockServiceProvider.swift; sourceTree = ""; }; @@ -1451,6 +1455,7 @@ children = ( FEEDD3882508E24900DC0A98 /* LotLan+Extensions.swift */, F970FAD7252B14950000806B /* SearchResultType+Extensions.swift */, + 045514C12B7D4B58000D88B9 /* CoreApiType+ToSDKType.swift */, ); path = Extensions; sourceTree = ""; @@ -2604,6 +2609,7 @@ F953A49325ECEB60003A3681 /* SearchCategorySuggestion+Samples.swift in Sources */, F9F882962583779A00062A82 /* CoreImageInfoStub.swift in Sources */, FEA92E712564149100427965 /* CoreSuggestAction+Samples.swift in Sources */, + 045514C32B7D4B58000D88B9 /* CoreApiType+ToSDKType.swift in Sources */, 2CA1E22129F09CD200A533CF /* PlaceAutocomplete.Suggestion+Tests.swift in Sources */, FED7E1A825517C5100DA34D9 /* CoreBoundingBoxTests.swift in Sources */, F9D70E5C252740DD0019105F /* IndexableDataProviderTests.swift in Sources */, @@ -2652,6 +2658,7 @@ F9201ECA253EECE0002D141B /* CategorySuggestionsIntegrationTestCase.swift in Sources */, F907443B261B13F40091899C /* MockServerUITestCase.swift in Sources */, F9ACA6132642B66600F50CD4 /* MockWebServer.swift in Sources */, + 045514C42B7D4B58000D88B9 /* CoreApiType+ToSDKType.swift in Sources */, FEEDD3D22508E45B00DC0A98 /* VisibilityTestCase.swift in Sources */, F9AB03C3261DBD7F00EDF1E7 /* MockResponse.swift in Sources */, FEEDD3CE2508E45B00DC0A98 /* BaseTestCase.swift in Sources */, @@ -2667,6 +2674,7 @@ files = ( F9C557B62670CC4500BE8B94 /* SearchEngineDelegateStub.swift in Sources */, F9C9461B2743CB1700763F2C /* TestTileStore.swift in Sources */, + 045514C22B7D4B58000D88B9 /* CoreApiType+ToSDKType.swift in Sources */, F9C557C12670CD8C00BE8B94 /* CoreSearchOptions+Samples.swift in Sources */, 1420F31C29A2800300D4A511 /* CoreSearchResultStub+Samples.swift in Sources */, F9C557B72670CC5600BE8B94 /* CoreSearchResultStub.swift in Sources */, diff --git a/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift index 941ec7c4b..89dead51c 100644 --- a/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/AddressAutofillIntegrationTests.swift @@ -2,7 +2,7 @@ import CoreLocation @testable import MapboxSearch import XCTest -final class AddressAutofillIntegrationTests: MockServerIntegrationTestCase { +final class AddressAutofillIntegrationTests: MockServerIntegrationTestCase { private var addressAutofill: AddressAutofill! private let locationProvider = WrapperLocationProvider(wrapping: DefaultLocationProvider()) @@ -18,7 +18,7 @@ final class AddressAutofillIntegrationTests: MockServerIntegrationTestCase { private var searchEngine: CategorySearchEngine! - override func setUp() { - super.setUp() + override func setUpWithError() throws { + try super.setUpWithError() + let apiType = try XCTUnwrap(Mock.coreApiType.toSDKType()) searchEngine = CategorySearchEngine( accessToken: "access-token", serviceProvider: LocalhostMockServiceProvider.shared, - apiType: .SBS + apiType: apiType ) } diff --git a/Tests/MapboxSearchIntegrationTests/MockServerIntegrationTestCase.swift b/Tests/MapboxSearchIntegrationTests/MockServerIntegrationTestCase.swift index 3c7c1f596..98b5bae97 100644 --- a/Tests/MapboxSearchIntegrationTests/MockServerIntegrationTestCase.swift +++ b/Tests/MapboxSearchIntegrationTests/MockServerIntegrationTestCase.swift @@ -3,6 +3,7 @@ import CoreLocation import XCTest class MockServerIntegrationTestCase: XCTestCase { + typealias Mock = Mock let server = MockWebServer() func setServerResponse(_ response: Mock, query: String? = nil) throws { diff --git a/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift index 5a21d541b..f6d5fda51 100644 --- a/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift @@ -17,7 +17,7 @@ final class PlaceAutocompleteIntegrationTests: MockServerIntegrationTestCase ApiType? { + switch self { + case .geocoding: + return .geocoding + case .SBS: + return .SBS + case .autofill, + .searchBox: + return nil + @unknown default: + fatalError() + } + } +} diff --git a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift index f1d5d9708..eeace5e78 100644 --- a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift +++ b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift @@ -1,5 +1,8 @@ import Foundation +@_implementationOnly import MapboxCoreSearch +@testable import MapboxSearch import Swifter +import XCTest protocol MockResponse { /// Resource from test bundle containing response JSON. @@ -10,6 +13,10 @@ protocol MockResponse { /// URL path for this request. var path: String { get } + + /// The API type for this mock. + /// Uses Core types to support address autofill. + static var coreApiType: CoreSearchEngine.ApiType { get } } enum LegacyResponse: MockResponse { @@ -154,4 +161,49 @@ enum LegacyResponse: MockResponse { return .post } } + + static var coreApiType: CoreSearchEngine.ApiType { + .geocoding + } +} + +enum AutofillMockResponse: MockResponse { + case suggestAddressSanFrancisco + case retrieveAddressSanFrancisco + + var filepath: String { + let bundle = Bundle(for: MockWebServer.self) + switch self { + case .retrieveAddressSanFrancisco: + return bundle.path(forResource: "address-retrieve-san-francisco", ofType: "json")! + case .suggestAddressSanFrancisco: + return bundle.path(forResource: "address-suggestions-san-francisco", ofType: "json")! + } + } + + var path: String { + var path = "/search/v1" + + switch self { + case .suggestAddressSanFrancisco: + path = "/autofill/v1/suggest/:query" + + case .retrieveAddressSanFrancisco: + path = "/autofill/v1/retrieve/:action.id" + } + + return path + } + + var httpMethod: HttpServer.HTTPMethod { + switch self { + case .suggestAddressSanFrancisco, + .retrieveAddressSanFrancisco: + return .get + } + } + + static var coreApiType: CoreSearchEngine.ApiType { + .autofill + } } From 70bd1bedb58a5486189fe69c4591ff1fc486d376 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 14 Feb 2024 15:47:46 -0500 Subject: [PATCH 05/17] Add SBSMockResponse --- ...CategorySearchEngineIntegrationTests.swift | 2 +- .../PlaceAutocompleteIntegrationTests.swift | 2 +- .../SearchEngineIntegrationTests.swift | 2 +- .../MockWebServer/MockResponse.swift | 148 ++++++++++++++++++ 4 files changed, 151 insertions(+), 3 deletions(-) diff --git a/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift index e11a0a8d8..eb7bb7f71 100644 --- a/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift @@ -2,7 +2,7 @@ import CoreLocation @testable import MapboxSearch import XCTest -final class CategorySearchEngineIntegrationTests: MockServerIntegrationTestCase { +final class CategorySearchEngineIntegrationTests: MockServerIntegrationTestCase { private var searchEngine: CategorySearchEngine! override func setUpWithError() throws { diff --git a/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift index f6d5fda51..895402f3c 100644 --- a/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/PlaceAutocompleteIntegrationTests.swift @@ -2,7 +2,7 @@ import CoreLocation @testable import MapboxSearch import XCTest -final class PlaceAutocompleteIntegrationTests: MockServerIntegrationTestCase { +final class PlaceAutocompleteIntegrationTests: MockServerIntegrationTestCase { private var placeAutocomplete: PlaceAutocomplete! override func setUp() { diff --git a/Tests/MapboxSearchIntegrationTests/SearchEngineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/SearchEngineIntegrationTests.swift index 1bb181294..4de4971b4 100644 --- a/Tests/MapboxSearchIntegrationTests/SearchEngineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/SearchEngineIntegrationTests.swift @@ -2,7 +2,7 @@ import CoreLocation @testable import MapboxSearch import XCTest -class SearchEngineIntegrationTests: MockServerIntegrationTestCase { +class SearchEngineIntegrationTests: MockServerIntegrationTestCase { let delegate = SearchEngineDelegateStub() var searchEngine: SearchEngine! diff --git a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift index eeace5e78..1ad163ccb 100644 --- a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift +++ b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift @@ -167,6 +167,154 @@ enum LegacyResponse: MockResponse { } } +enum SBSMockResponse: MockResponse { + case suggestEmpty + case suggestMinsk + case suggestSanFrancisco + case suggestCategories + case suggestWithCoordinates + case suggestWithMixedCoordinates + case suggestCategoryWithCoordinates + case suggestAddressSanFrancisco + + case retrieveSanFrancisco + case retrieveMinsk + case retrieveCategory + case retrievePoi + case multiRetrieve + case retrieveAddressSanFrancisco + + case recursion + case forwardGeocoding + case reverseGeocoding + case reverseGeocodingSBS + case categoryCafe + + var filepath: String { + let bundle = Bundle(for: MockWebServer.self) + switch self { + case .suggestEmpty: + return bundle.path(forResource: "suggestions-empty", ofType: "json")! + case .suggestMinsk: + return bundle.path(forResource: "suggestions-minsk", ofType: "json")! + case .suggestSanFrancisco: + return bundle.path(forResource: "suggestions-san-francisco", ofType: "json")! + case .suggestCategories: + return bundle.path(forResource: "suggestions-categories", ofType: "json")! + case .suggestWithCoordinates: + return bundle.path(forResource: "suggestions-with-coordinates", ofType: "json")! + case .suggestWithMixedCoordinates: + return bundle.path(forResource: "suggestions-with-mixed-coordinates", ofType: "json")! + case .suggestCategoryWithCoordinates: + return bundle.path(forResource: "suggestions-category-with-coordinates", ofType: "json")! + case .retrieveSanFrancisco: + return bundle.path(forResource: "retrieve-san-francisco", ofType: "json")! + case .retrieveMinsk: + return bundle.path(forResource: "retrieve-minsk", ofType: "json")! + case .retrieveCategory: + return bundle.path(forResource: "retrieve-category", ofType: "json")! + case .retrievePoi: + return bundle.path(forResource: "retrieve-poi", ofType: "json")! + case .recursion: + return bundle.path(forResource: "recursion", ofType: "json")! + case .reverseGeocodingSBS: + return bundle.path(forResource: "reverse-geocoding-sbs", ofType: "json")! + case .reverseGeocoding: + return bundle.path(forResource: "geocoding-reverse-geocoding", ofType: "json")! + case .forwardGeocoding: + return bundle.path(forResource: "mapbox.places.san.francisco", ofType: "json")! + case .multiRetrieve: + return bundle.path(forResource: "retrieve-multi", ofType: "json")! + case .categoryCafe: + return bundle.path(forResource: "category-cafe", ofType: "json")! + case .suggestAddressSanFrancisco: + return bundle.path(forResource: "address-suggestions-san-francisco", ofType: "json")! + case .retrieveAddressSanFrancisco: + return bundle.path(forResource: "address-retrieve-san-francisco", ofType: "json")! + } + } + + var path: String { + var path = "/search/v1" + + switch self { + case .suggestAddressSanFrancisco: + path = "/autofill/v1/suggest/:query" + + case .retrieveAddressSanFrancisco: + path = "/autofill/v1/retrieve/:action.id" + + case .forwardGeocoding: + path = "/geocoding/v5/mapbox.places/:query" + + case .suggestMinsk: + path += "/suggest/Minsk" + + case .suggestSanFrancisco: + path += "/suggest/San Francisco" + + case .suggestEmpty, + .suggestCategories, + .suggestWithCoordinates, + .suggestWithMixedCoordinates, + .suggestCategoryWithCoordinates, + .recursion: + path += "/suggest/:query" + + case .retrieveSanFrancisco, + .retrieveCategory, + .retrieveMinsk, + .retrievePoi: + path += "/retrieve" + + case .reverseGeocoding: + path = "geocoding/v5/mapbox.places/:location" + + case .reverseGeocodingSBS: + path += "/:coordinates" + + case .multiRetrieve: + path += "/retrieve/multi" + + case .categoryCafe: + path += "/category/:category" + } + + return path + } + + var httpMethod: HttpServer.HTTPMethod { + switch self { + case .suggestAddressSanFrancisco, + .retrieveAddressSanFrancisco, + .forwardGeocoding, + .suggestMinsk, + .suggestSanFrancisco, + .suggestEmpty, + .suggestCategories, + .suggestWithCoordinates, + .suggestWithMixedCoordinates, + .suggestCategoryWithCoordinates, + .recursion, + .reverseGeocoding, + .reverseGeocodingSBS, + .categoryCafe: + return .get + + case .multiRetrieve, + .retrieveSanFrancisco, + .retrieveCategory, + .retrieveMinsk, + .retrievePoi: + return .post + } + } + + static var coreApiType: CoreSearchEngine.ApiType { + .SBS + } +} + enum AutofillMockResponse: MockResponse { case suggestAddressSanFrancisco case retrieveAddressSanFrancisco From 3b246c97757c48359f0f00b93d349f996b4fa168 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 14 Feb 2024 17:53:51 -0500 Subject: [PATCH 06/17] Rename LegacyResponse to GeocodingMockResponse --- .../OfflineIntegrationTests.swift | 2 +- .../SearchEngineGeocodingIntegrationTests.swift | 2 +- .../CategorySuggestionsIntegrationTestCase.swift | 6 +++--- .../CategorySuggestionsNavigationIntegrationTestCase.swift | 4 ++-- .../Integration/FeedbackIntegrationTestCase.swift | 4 ++-- Tests/MapboxSearchUITests/MockServerUITestCase.swift | 2 +- Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index d24be506c..1ab179677 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -6,7 +6,7 @@ import MapboxCommon @testable import MapboxSearch import XCTest -class OfflineIntegrationTests: MockServerIntegrationTestCase { +class OfflineIntegrationTests: MockServerIntegrationTestCase { let delegate = SearchEngineDelegateStub() let searchEngine = SearchEngine() diff --git a/Tests/MapboxSearchIntegrationTests/SearchEngineGeocodingIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/SearchEngineGeocodingIntegrationTests.swift index 1ee76273c..657aa411a 100644 --- a/Tests/MapboxSearchIntegrationTests/SearchEngineGeocodingIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/SearchEngineGeocodingIntegrationTests.swift @@ -2,7 +2,7 @@ import CoreLocation @testable import MapboxSearch import XCTest -class SearchEngineGeocodingIntegrationTests: MockServerIntegrationTestCase { +class SearchEngineGeocodingIntegrationTests: MockServerIntegrationTestCase { let delegate = SearchEngineDelegateStub() var searchEngine: SearchEngine! diff --git a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift index bd2cb4712..cfa4a3c80 100644 --- a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift @@ -1,13 +1,13 @@ import XCTest -class CategorySuggestionsIntegrationTestCase: MockServerUITestCase { +class CategorySuggestionsIntegrationTestCase: MockServerUITestCase { override func setUpWithError() throws { try super.setUpWithError() app.launch() - try server.setResponse(LegacyResponse.suggestCategories) - try server.setResponse(LegacyResponse.retrieveCategory) + try server.setResponse(SBSMockResponse.suggestCategories) + try server.setResponse(SBSMockResponse.retrieveCategory) } func testCafeCategorySuggestions() throws { diff --git a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsNavigationIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsNavigationIntegrationTestCase.swift index 47fb77072..a1d6c5d82 100644 --- a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsNavigationIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsNavigationIntegrationTestCase.swift @@ -5,8 +5,8 @@ class CategorySuggestionsNavigationIntegrationTestCase: MockServerUITestCase { try super.setUpWithError() app.launch() - try server.setResponse(LegacyResponse.suggestCategories) - try server.setResponse(LegacyResponse.retrieveCategory) + try server.setResponse(GeocodingMockResponse.suggestCategories) + try server.setResponse(GeocodingMockResponse.retrieveCategory) } func testCancelCategorySuggestionsSearch() { diff --git a/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift index ca31af53c..a0e975ddb 100644 --- a/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift @@ -6,8 +6,8 @@ class FeedbackIntegrationTestCase: MockServerUITestCase { override func setUpWithError() throws { try super.setUpWithError() - try server.setResponse(LegacyResponse.suggestSanFrancisco) - try server.setResponse(LegacyResponse.retrieveSanFrancisco) + try server.setResponse(GeocodingMockResponse.suggestSanFrancisco) + try server.setResponse(GeocodingMockResponse.retrieveSanFrancisco) } func testSendFeedback() throws { diff --git a/Tests/MapboxSearchUITests/MockServerUITestCase.swift b/Tests/MapboxSearchUITests/MockServerUITestCase.swift index 3925af2e9..a08b71471 100644 --- a/Tests/MapboxSearchUITests/MockServerUITestCase.swift +++ b/Tests/MapboxSearchUITests/MockServerUITestCase.swift @@ -1,7 +1,7 @@ import Foundation class MockServerUITestCase: BaseTestCase { - let server = MockWebServer() + let server = MockWebServer() override func setUpWithError() throws { try super.setUpWithError() diff --git a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift index 1ad163ccb..14c222c03 100644 --- a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift +++ b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift @@ -19,7 +19,7 @@ protocol MockResponse { static var coreApiType: CoreSearchEngine.ApiType { get } } -enum LegacyResponse: MockResponse { +enum GeocodingMockResponse: MockResponse { case suggestEmpty case suggestMinsk case suggestSanFrancisco From 59fa6aad7943b5ab1837bc94d0b6a76f3e86aa3a Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 14 Feb 2024 18:03:08 -0500 Subject: [PATCH 07/17] Add MockResponse generic to MockServerUITestCase --- .../CategorySuggestionsIntegrationTestCase.swift | 5 ++--- .../CategorySuggestionsNavigationIntegrationTestCase.swift | 6 +++--- .../Integration/FavoritesIntegrationTestCase.swift | 2 +- .../Integration/FeedbackIntegrationTestCase.swift | 6 +++--- .../Integration/SearchIntegrationTestCase.swift | 2 +- Tests/MapboxSearchUITests/MockServerUITestCase.swift | 5 +++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift index cfa4a3c80..2f7371603 100644 --- a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift @@ -1,4 +1,3 @@ - import XCTest class CategorySuggestionsIntegrationTestCase: MockServerUITestCase { @@ -6,8 +5,8 @@ class CategorySuggestionsIntegrationTestCase: MockServerUITestCase { override func setUpWithError() throws { try super.setUpWithError() app.launch() - try server.setResponse(GeocodingMockResponse.suggestCategories) - try server.setResponse(GeocodingMockResponse.retrieveCategory) + try server.setResponse(.suggestCategories) + try server.setResponse(.retrieveCategory) } func testCancelCategorySuggestionsSearch() { diff --git a/Tests/MapboxSearchUITests/Integration/FavoritesIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/FavoritesIntegrationTestCase.swift index 32def32d3..5ab8fbebf 100644 --- a/Tests/MapboxSearchUITests/Integration/FavoritesIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/FavoritesIntegrationTestCase.swift @@ -1,6 +1,6 @@ import XCTest -class FavoritesIntegrationTestCase: MockServerUITestCase { +class FavoritesIntegrationTestCase: MockServerUITestCase { func testAddRemoveFavorite() throws { try server.setResponse(.suggestMinsk) try server.setResponse(.retrieveMinsk) diff --git a/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift index a0e975ddb..f022d3939 100644 --- a/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift @@ -2,12 +2,12 @@ import XCTest // TODO: Analytics -class FeedbackIntegrationTestCase: MockServerUITestCase { +class FeedbackIntegrationTestCase: MockServerUITestCase { override func setUpWithError() throws { try super.setUpWithError() - try server.setResponse(GeocodingMockResponse.suggestSanFrancisco) - try server.setResponse(GeocodingMockResponse.retrieveSanFrancisco) + try server.setResponse(.suggestSanFrancisco) + try server.setResponse(.retrieveSanFrancisco) } func testSendFeedback() throws { diff --git a/Tests/MapboxSearchUITests/Integration/SearchIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/SearchIntegrationTestCase.swift index e1c9f1593..4e595c9d9 100644 --- a/Tests/MapboxSearchUITests/Integration/SearchIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/SearchIntegrationTestCase.swift @@ -1,6 +1,6 @@ import XCTest -class SearchIntegrationTestCase: MockServerUITestCase { +class SearchIntegrationTestCase: MockServerUITestCase { func testRecentSearchRemove() throws { try server.setResponse(.suggestSanFrancisco) try server.setResponse(.retrieveSanFrancisco) diff --git a/Tests/MapboxSearchUITests/MockServerUITestCase.swift b/Tests/MapboxSearchUITests/MockServerUITestCase.swift index a08b71471..8ccaa293a 100644 --- a/Tests/MapboxSearchUITests/MockServerUITestCase.swift +++ b/Tests/MapboxSearchUITests/MockServerUITestCase.swift @@ -1,7 +1,8 @@ import Foundation -class MockServerUITestCase: BaseTestCase { - let server = MockWebServer() +class MockServerUITestCase: BaseTestCase { + typealias Mock = Mock + let server = MockWebServer() override func setUpWithError() throws { try super.setUpWithError() From 5a5991012f2ad2ffac6b29eef6f37d1663d9aa68 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 14 Feb 2024 18:05:39 -0500 Subject: [PATCH 08/17] Disable OfflineIntegrationTests until later --- Tests/Demo.xctestplan | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/Demo.xctestplan b/Tests/Demo.xctestplan index 7dcacae8b..4adbfc008 100644 --- a/Tests/Demo.xctestplan +++ b/Tests/Demo.xctestplan @@ -35,7 +35,8 @@ "testTargets" : [ { "skippedTests" : [ - "MockServerIntegrationTestCase" + "MockServerIntegrationTestCase", + "OfflineIntegrationTests" ], "target" : { "containerPath" : "container:MapboxSearch.xcodeproj", From fdb0d19f2affcd71db630a0d284525cc37405e6e Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 14 Feb 2024 18:17:19 -0500 Subject: [PATCH 09/17] Change CI test frameworks step to ci-full-test which adds UI tests - ci-dev-test (previous) does not run UI tests --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fa6248adf..f9c9aadf1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -106,7 +106,7 @@ jobs: command: make dependencies - run: name: Test frameworks - command: make ci-dev-test + command: make ci-full-test - run: make codecov - run: name: Prepare artifacts From 00b747411fb7da02e822ff4ae9e00d0ed8eb38a7 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 14 Feb 2024 18:27:25 -0500 Subject: [PATCH 10/17] Pare down GeocodingMockResponse, remove mocks that are not geocoding ApiType --- .../MockWebServer/MockResponse.swift | 108 +----------------- 1 file changed, 3 insertions(+), 105 deletions(-) diff --git a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift index 14c222c03..9050fa0cb 100644 --- a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift +++ b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift @@ -20,116 +20,32 @@ protocol MockResponse { } enum GeocodingMockResponse: MockResponse { - case suggestEmpty - case suggestMinsk - case suggestSanFrancisco - case suggestCategories - case suggestWithCoordinates - case suggestWithMixedCoordinates - case suggestCategoryWithCoordinates - case suggestAddressSanFrancisco - - case retrieveSanFrancisco - case retrieveMinsk - case retrieveCategory - case retrievePoi - case multiRetrieve - case retrieveAddressSanFrancisco - - case recursion case forwardGeocoding case reverseGeocoding case reverseGeocodingSBS - case categoryCafe var filepath: String { let bundle = Bundle(for: MockWebServer.self) switch self { - case .suggestEmpty: - return bundle.path(forResource: "suggestions-empty", ofType: "json")! - case .suggestMinsk: - return bundle.path(forResource: "suggestions-minsk", ofType: "json")! - case .suggestSanFrancisco: - return bundle.path(forResource: "suggestions-san-francisco", ofType: "json")! - case .suggestCategories: - return bundle.path(forResource: "suggestions-categories", ofType: "json")! - case .suggestWithCoordinates: - return bundle.path(forResource: "suggestions-with-coordinates", ofType: "json")! - case .suggestWithMixedCoordinates: - return bundle.path(forResource: "suggestions-with-mixed-coordinates", ofType: "json")! - case .suggestCategoryWithCoordinates: - return bundle.path(forResource: "suggestions-category-with-coordinates", ofType: "json")! - case .retrieveSanFrancisco: - return bundle.path(forResource: "retrieve-san-francisco", ofType: "json")! - case .retrieveMinsk: - return bundle.path(forResource: "retrieve-minsk", ofType: "json")! - case .retrieveCategory: - return bundle.path(forResource: "retrieve-category", ofType: "json")! - case .retrievePoi: - return bundle.path(forResource: "retrieve-poi", ofType: "json")! - case .recursion: - return bundle.path(forResource: "recursion", ofType: "json")! case .reverseGeocodingSBS: return bundle.path(forResource: "reverse-geocoding-sbs", ofType: "json")! case .reverseGeocoding: return bundle.path(forResource: "geocoding-reverse-geocoding", ofType: "json")! case .forwardGeocoding: return bundle.path(forResource: "mapbox.places.san.francisco", ofType: "json")! - case .multiRetrieve: - return bundle.path(forResource: "retrieve-multi", ofType: "json")! - case .categoryCafe: - return bundle.path(forResource: "category-cafe", ofType: "json")! - case .suggestAddressSanFrancisco: - return bundle.path(forResource: "address-suggestions-san-francisco", ofType: "json")! - case .retrieveAddressSanFrancisco: - return bundle.path(forResource: "address-retrieve-san-francisco", ofType: "json")! } } var path: String { var path = "/search/v1" - switch self { - case .suggestAddressSanFrancisco: - path = "/autofill/v1/suggest/:query" - - case .retrieveAddressSanFrancisco: - path = "/autofill/v1/retrieve/:action.id" - case .forwardGeocoding: path = "/geocoding/v5/mapbox.places/:query" - - case .suggestMinsk: - path += "/suggest/Minsk" - - case .suggestSanFrancisco: - path += "/suggest/San Francisco" - - case .suggestEmpty, - .suggestCategories, - .suggestWithCoordinates, - .suggestWithMixedCoordinates, - .suggestCategoryWithCoordinates, - .recursion: - path += "/suggest/:query" - - case .retrieveSanFrancisco, - .retrieveCategory, - .retrieveMinsk, - .retrievePoi: - path += "/retrieve" - case .reverseGeocoding: - path = "geocoding/v5/mapbox.places/:location" + path = "/geocoding/v5/mapbox.places/:location" case .reverseGeocodingSBS: path += "/:coordinates" - - case .multiRetrieve: - path += "/retrieve/multi" - - case .categoryCafe: - path += "/category/:category" } return path @@ -137,28 +53,10 @@ enum GeocodingMockResponse: MockResponse { var httpMethod: HttpServer.HTTPMethod { switch self { - case .suggestAddressSanFrancisco, - .retrieveAddressSanFrancisco, - .forwardGeocoding, - .suggestMinsk, - .suggestSanFrancisco, - .suggestEmpty, - .suggestCategories, - .suggestWithCoordinates, - .suggestWithMixedCoordinates, - .suggestCategoryWithCoordinates, - .recursion, + case .forwardGeocoding, .reverseGeocoding, - .reverseGeocodingSBS, - .categoryCafe: + .reverseGeocodingSBS: return .get - - case .multiRetrieve, - .retrieveSanFrancisco, - .retrieveCategory, - .retrieveMinsk, - .retrievePoi: - return .post } } From 2fe6b2547085440996451df43722e65e45093773 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 14 Feb 2024 18:29:22 -0500 Subject: [PATCH 11/17] Add mark declarations to MockResponse file --- Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift index 9050fa0cb..a14a987bd 100644 --- a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift +++ b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift @@ -19,6 +19,8 @@ protocol MockResponse { static var coreApiType: CoreSearchEngine.ApiType { get } } +// MARK: - Geocoding + enum GeocodingMockResponse: MockResponse { case forwardGeocoding case reverseGeocoding @@ -65,6 +67,8 @@ enum GeocodingMockResponse: MockResponse { } } +// MARK: - SBS + enum SBSMockResponse: MockResponse { case suggestEmpty case suggestMinsk @@ -213,6 +217,8 @@ enum SBSMockResponse: MockResponse { } } +// MARK: - Autofill + enum AutofillMockResponse: MockResponse { case suggestAddressSanFrancisco case retrieveAddressSanFrancisco From 906a214c50b729c557c29ea666e04958cec67938 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 14 Feb 2024 18:40:15 -0500 Subject: [PATCH 12/17] Pare down SBSMockResponse to remove unused mocks --- .../MockWebServer/MockResponse.swift | 41 ++----------------- 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift index a14a987bd..347c3591f 100644 --- a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift +++ b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift @@ -77,19 +77,14 @@ enum SBSMockResponse: MockResponse { case suggestWithCoordinates case suggestWithMixedCoordinates case suggestCategoryWithCoordinates - case suggestAddressSanFrancisco case retrieveSanFrancisco case retrieveMinsk case retrieveCategory case retrievePoi case multiRetrieve - case retrieveAddressSanFrancisco case recursion - case forwardGeocoding - case reverseGeocoding - case reverseGeocodingSBS case categoryCafe var filepath: String { @@ -119,20 +114,10 @@ enum SBSMockResponse: MockResponse { return bundle.path(forResource: "retrieve-poi", ofType: "json")! case .recursion: return bundle.path(forResource: "recursion", ofType: "json")! - case .reverseGeocodingSBS: - return bundle.path(forResource: "reverse-geocoding-sbs", ofType: "json")! - case .reverseGeocoding: - return bundle.path(forResource: "geocoding-reverse-geocoding", ofType: "json")! - case .forwardGeocoding: - return bundle.path(forResource: "mapbox.places.san.francisco", ofType: "json")! case .multiRetrieve: return bundle.path(forResource: "retrieve-multi", ofType: "json")! case .categoryCafe: return bundle.path(forResource: "category-cafe", ofType: "json")! - case .suggestAddressSanFrancisco: - return bundle.path(forResource: "address-suggestions-san-francisco", ofType: "json")! - case .retrieveAddressSanFrancisco: - return bundle.path(forResource: "address-retrieve-san-francisco", ofType: "json")! } } @@ -140,15 +125,6 @@ enum SBSMockResponse: MockResponse { var path = "/search/v1" switch self { - case .suggestAddressSanFrancisco: - path = "/autofill/v1/suggest/:query" - - case .retrieveAddressSanFrancisco: - path = "/autofill/v1/retrieve/:action.id" - - case .forwardGeocoding: - path = "/geocoding/v5/mapbox.places/:query" - case .suggestMinsk: path += "/suggest/Minsk" @@ -159,8 +135,8 @@ enum SBSMockResponse: MockResponse { .suggestCategories, .suggestWithCoordinates, .suggestWithMixedCoordinates, - .suggestCategoryWithCoordinates, - .recursion: + .recursion, + .suggestCategoryWithCoordinates: path += "/suggest/:query" case .retrieveSanFrancisco, @@ -169,12 +145,6 @@ enum SBSMockResponse: MockResponse { .retrievePoi: path += "/retrieve" - case .reverseGeocoding: - path = "geocoding/v5/mapbox.places/:location" - - case .reverseGeocodingSBS: - path += "/:coordinates" - case .multiRetrieve: path += "/retrieve/multi" @@ -187,10 +157,7 @@ enum SBSMockResponse: MockResponse { var httpMethod: HttpServer.HTTPMethod { switch self { - case .suggestAddressSanFrancisco, - .retrieveAddressSanFrancisco, - .forwardGeocoding, - .suggestMinsk, + case .suggestMinsk, .suggestSanFrancisco, .suggestEmpty, .suggestCategories, @@ -198,8 +165,6 @@ enum SBSMockResponse: MockResponse { .suggestWithMixedCoordinates, .suggestCategoryWithCoordinates, .recursion, - .reverseGeocoding, - .reverseGeocodingSBS, .categoryCafe: return .get From c83e0a5aa40084c07f06aff2cc2e41be6f27ecf5 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 14 Feb 2024 19:34:02 -0500 Subject: [PATCH 13/17] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e20e5374e..4170fdf50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ Guide: https://keepachangelog.com/en/1.0.0/ +- [Tests] Change MockResponse into a protocol, create separate enums conforming to MockResponse for each API type (geocoding, sbs, autofill), add MockResponse as generic to each test base class and MockWebServer. + - [SearchUI] Add `distanceFormatter` field to Configuration to support changing the search suggestions distance format. Nil values will use the default behavior. - [Core] Add xcprivacy for MapboxSearch and MapboxSearchUI From 35114142b3b164df0718f5599e29dbb421cde2ae Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Thu, 15 Feb 2024 13:15:10 -0500 Subject: [PATCH 14/17] Update visibility UI tests to use network Mocks --- Tests/MapboxSearchUITests/VisibilityTestCase.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Tests/MapboxSearchUITests/VisibilityTestCase.swift b/Tests/MapboxSearchUITests/VisibilityTestCase.swift index d3cd54d4d..7a0d180ed 100644 --- a/Tests/MapboxSearchUITests/VisibilityTestCase.swift +++ b/Tests/MapboxSearchUITests/VisibilityTestCase.swift @@ -1,11 +1,13 @@ import XCTest -class VisibilityTestCase: BaseTestCase { +class VisibilityTestCase: MockServerUITestCase { override func setUpWithError() throws { try super.setUpWithError() - app.launch() XCUIDevice.shared.orientation = .portrait + + try server.setResponse(.suggestCategories) + try server.setResponse(.retrieveCategory) } func testSearchBarVisibility() throws { From 5aa4242bf8bca935e666bb68fe8fe63cca348c93 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Thu, 15 Feb 2024 14:45:52 -0500 Subject: [PATCH 15/17] Restore Package.resolved file --- .../xcshareddata/swiftpm/Package.resolved | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 MapboxSearch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved diff --git a/MapboxSearch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/MapboxSearch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 000000000..c3e68929e --- /dev/null +++ b/MapboxSearch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,32 @@ +{ + "pins" : [ + { + "identity" : "cwlcatchexception", + "kind" : "remoteSourceControl", + "location" : "https://github.com/mattgallagher/CwlCatchException.git", + "state" : { + "revision" : "3b123999de19bf04905bc1dfdb76f817b0f2cc00", + "version" : "2.1.2" + } + }, + { + "identity" : "cwlpreconditiontesting", + "kind" : "remoteSourceControl", + "location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git", + "state" : { + "revision" : "a23ded2c91df9156628a6996ab4f347526f17b6b", + "version" : "2.1.2" + } + }, + { + "identity" : "swifter", + "kind" : "remoteSourceControl", + "location" : "https://github.com/httpswift/swifter", + "state" : { + "revision" : "9483a5d459b45c3ffd059f7b55f9638e268632fd", + "version" : "1.5.0" + } + } + ], + "version" : 2 +} From 051ef74e618b4b60dd7d11f94ee78d32cba375f1 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Thu, 15 Feb 2024 15:02:15 -0500 Subject: [PATCH 16/17] Update docs for CoreSearchEngine.ApiType.toSDKType (tests only) --- .../Common/Extensions/CoreApiType+ToSDKType.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Tests/MapboxSearchTests/Common/Extensions/CoreApiType+ToSDKType.swift b/Tests/MapboxSearchTests/Common/Extensions/CoreApiType+ToSDKType.swift index 408f11f67..e57f013db 100644 --- a/Tests/MapboxSearchTests/Common/Extensions/CoreApiType+ToSDKType.swift +++ b/Tests/MapboxSearchTests/Common/Extensions/CoreApiType+ToSDKType.swift @@ -1,6 +1,15 @@ @testable import MapboxSearch extension CoreSearchEngine.ApiType { + /// Available only for tests. + /// This is necessary for tests using subclasses and usages of ``AbstractSearchEngine`` to dynamically instantiate + /// an engine with the appropriate ApiType for their test case mocks. + /// ``AbstractSearchEngine`` and subclasses use a ``MapboxSearch.ApiType`` enum which is a **subset** of the Core + /// ApiType. + /// For all other ApiTypes specialized classes are provided that use the Core ApiType directly (such as + /// AddressAutofill) or support is not yet fully implemented (such as search-box). + /// Tests that attempt to use an Autofill or Search-box API type with a custom SearchEngine (instead of a provided + /// specialized class) should encounter a runtime error. func toSDKType() -> ApiType? { switch self { case .geocoding: @@ -9,7 +18,7 @@ extension CoreSearchEngine.ApiType { return .SBS case .autofill, .searchBox: - return nil + fallthrough @unknown default: fatalError() } From 71b0fd50f67b44b809bb119fc3a1edd6ccba48e5 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Fri, 16 Feb 2024 08:51:04 -0500 Subject: [PATCH 17/17] Update for PR feedback: add typealias for MockSBSServerUITestCase, remove typealias for Mock in UITestCase --- Tests/MapboxSearchUITests/BaseTestCase.swift | 3 ++- .../CategorySuggestionsIntegrationTestCase.swift | 2 +- .../CategorySuggestionsNavigationIntegrationTestCase.swift | 2 +- .../Integration/FavoritesIntegrationTestCase.swift | 2 +- .../Integration/FeedbackIntegrationTestCase.swift | 2 +- .../Integration/SearchIntegrationTestCase.swift | 2 +- Tests/MapboxSearchUITests/MockServerUITestCase.swift | 7 ++++++- Tests/MapboxSearchUITests/VisibilityTestCase.swift | 2 +- 8 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Tests/MapboxSearchUITests/BaseTestCase.swift b/Tests/MapboxSearchUITests/BaseTestCase.swift index 6ad969531..85295c824 100644 --- a/Tests/MapboxSearchUITests/BaseTestCase.swift +++ b/Tests/MapboxSearchUITests/BaseTestCase.swift @@ -1,6 +1,7 @@ import XCTest -/// UI tests will always use the recommended API engine type for each provided SearchEngine and SearchEngine samples. +/// Base XCTestCase class that provides testable application behavior. +/// Please use subclass ``MockServerUITestCase`` for tests. class BaseTestCase: XCTestCase { static let defaultTimeout: TimeInterval = 10.0 diff --git a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift index 2f7371603..be6565e4b 100644 --- a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsIntegrationTestCase.swift @@ -1,6 +1,6 @@ import XCTest -class CategorySuggestionsIntegrationTestCase: MockServerUITestCase { +class CategorySuggestionsIntegrationTestCase: MockSBSServerUITestCase { override func setUpWithError() throws { try super.setUpWithError() app.launch() diff --git a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsNavigationIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsNavigationIntegrationTestCase.swift index 2c9051894..128676a7b 100644 --- a/Tests/MapboxSearchUITests/Integration/CategorySuggestionsNavigationIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/CategorySuggestionsNavigationIntegrationTestCase.swift @@ -1,6 +1,6 @@ import XCTest -class CategorySuggestionsNavigationIntegrationTestCase: MockServerUITestCase { +class CategorySuggestionsNavigationIntegrationTestCase: MockSBSServerUITestCase { override func setUpWithError() throws { try super.setUpWithError() app.launch() diff --git a/Tests/MapboxSearchUITests/Integration/FavoritesIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/FavoritesIntegrationTestCase.swift index 5ab8fbebf..b0cdd0a39 100644 --- a/Tests/MapboxSearchUITests/Integration/FavoritesIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/FavoritesIntegrationTestCase.swift @@ -1,6 +1,6 @@ import XCTest -class FavoritesIntegrationTestCase: MockServerUITestCase { +class FavoritesIntegrationTestCase: MockSBSServerUITestCase { func testAddRemoveFavorite() throws { try server.setResponse(.suggestMinsk) try server.setResponse(.retrieveMinsk) diff --git a/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift index f022d3939..43774b1e9 100644 --- a/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/FeedbackIntegrationTestCase.swift @@ -2,7 +2,7 @@ import XCTest // TODO: Analytics -class FeedbackIntegrationTestCase: MockServerUITestCase { +class FeedbackIntegrationTestCase: MockSBSServerUITestCase { override func setUpWithError() throws { try super.setUpWithError() diff --git a/Tests/MapboxSearchUITests/Integration/SearchIntegrationTestCase.swift b/Tests/MapboxSearchUITests/Integration/SearchIntegrationTestCase.swift index 4e595c9d9..3b8666eb7 100644 --- a/Tests/MapboxSearchUITests/Integration/SearchIntegrationTestCase.swift +++ b/Tests/MapboxSearchUITests/Integration/SearchIntegrationTestCase.swift @@ -1,6 +1,6 @@ import XCTest -class SearchIntegrationTestCase: MockServerUITestCase { +class SearchIntegrationTestCase: MockSBSServerUITestCase { func testRecentSearchRemove() throws { try server.setResponse(.suggestSanFrancisco) try server.setResponse(.retrieveSanFrancisco) diff --git a/Tests/MapboxSearchUITests/MockServerUITestCase.swift b/Tests/MapboxSearchUITests/MockServerUITestCase.swift index 8ccaa293a..4d0a3ed1e 100644 --- a/Tests/MapboxSearchUITests/MockServerUITestCase.swift +++ b/Tests/MapboxSearchUITests/MockServerUITestCase.swift @@ -1,7 +1,8 @@ import Foundation +/// Base UI test case that uses mocked network responses extended on default testable app behavior. +/// Provide a type conforming to MockResponse and then make use of it when using `server` functions and properties. class MockServerUITestCase: BaseTestCase { - typealias Mock = Mock let server = MockWebServer() override func setUpWithError() throws { @@ -18,3 +19,7 @@ class MockServerUITestCase: BaseTestCase { server.stop() } } + +/// Specialized default test case that uses SBSMockResponse. +/// SBS is the recommended API engine type and default for the Demo app and UI test cases in the 2.0.0 release series. +typealias MockSBSServerUITestCase = MockServerUITestCase diff --git a/Tests/MapboxSearchUITests/VisibilityTestCase.swift b/Tests/MapboxSearchUITests/VisibilityTestCase.swift index 7a0d180ed..6b4b61587 100644 --- a/Tests/MapboxSearchUITests/VisibilityTestCase.swift +++ b/Tests/MapboxSearchUITests/VisibilityTestCase.swift @@ -1,6 +1,6 @@ import XCTest -class VisibilityTestCase: MockServerUITestCase { +class VisibilityTestCase: MockSBSServerUITestCase { override func setUpWithError() throws { try super.setUpWithError() app.launch()