Skip to content

Commit

Permalink
Add test to ensure Discover with Search-along-route works correctly -…
Browse files Browse the repository at this point in the history
… SSDK-399
  • Loading branch information
aokj4ck committed Jan 31, 2024
1 parent 949a0d8 commit bab5844
Show file tree
Hide file tree
Showing 5 changed files with 759 additions and 6 deletions.
12 changes: 12 additions & 0 deletions MapboxSearch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

/* Begin PBXBuildFile section */
043A3D4D2B30F38300DB681B /* CoreAddress+AddressComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043A3D4C2B30F38300DB681B /* CoreAddress+AddressComponents.swift */; };
048823482B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; };
048823492B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; };
0488234A2B6B0A9E00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; };
04AB0B7B2B6AF43E00FDE7D5 /* DiscoverIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04AB0B792B6AF37800FDE7D5 /* DiscoverIntegrationTests.swift */; };
04C0848D2B4C82F3002F9C69 /* SdkInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04C0848C2B4C82F3002F9C69 /* SdkInformation.swift */; };
04E5FF962B48828500DADC18 /* SearchAddressCountry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04E5FF952B48828500DADC18 /* SearchAddressCountry.swift */; };
04E5FF992B48829200DADC18 /* SearchAddressRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04E5FF982B48829200DADC18 /* SearchAddressRegion.swift */; };
Expand Down Expand Up @@ -480,6 +484,8 @@

/* Begin PBXFileReference section */
043A3D4C2B30F38300DB681B /* CoreAddress+AddressComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CoreAddress+AddressComponents.swift"; sourceTree = "<group>"; };
04AB0B792B6AF37800FDE7D5 /* DiscoverIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscoverIntegrationTests.swift; sourceTree = "<group>"; };
04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */ = {isa = PBXFileReference; explicitFileType = text.json; path = "category-hotel-search-along-route-jp.json"; sourceTree = "<group>"; };
04C0848C2B4C82F3002F9C69 /* SdkInformation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SdkInformation.swift; sourceTree = "<group>"; };
04E5FF952B48828500DADC18 /* SearchAddressCountry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchAddressCountry.swift; sourceTree = "<group>"; };
04E5FF982B48829200DADC18 /* SearchAddressRegion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchAddressRegion.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1340,6 +1346,7 @@
2CE1B9FA2A13D412005B043F /* address-retrieve-san-francisco.json */,
2CE1B9F92A13D412005B043F /* address-suggestions-san-francisco.json */,
2CD8AC5129F28D6900C47BE4 /* retrieve-poi.json */,
04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */,
2CD8AC4029F1D38800C47BE4 /* suggestions-category-with-coordinates.json */,
2CD8AC4129F1D38800C47BE4 /* suggestions-with-coordinates.json */,
2CD8AC4229F1D38800C47BE4 /* suggestions-with-mixed-coordinates.json */,
Expand Down Expand Up @@ -1456,6 +1463,7 @@
F9274FF3273AA72800708F37 /* OfflineIntegrationTests.swift */,
F9ACA6162642C18200F50CD4 /* SearchEngineIntegrationTests.swift */,
F99190422645ABE6009927A6 /* CategorySearchEngineIntegrationTests.swift */,
04AB0B792B6AF37800FDE7D5 /* DiscoverIntegrationTests.swift */,
F9C5572C2670C88E00BE8B94 /* Info.plist */,
);
path = MapboxSearchIntegrationTests;
Expand Down Expand Up @@ -2033,6 +2041,7 @@
F94FFA4A264547CD0019ED9B /* retrieve-multi.json in Resources */,
2CD8AC4429F1D38800C47BE4 /* suggestions-category-with-coordinates.json in Resources */,
F9B62CCB264BCC2600492999 /* suggestions-empty.json in Resources */,
048823492B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */,
F9ACA6182642C48C00F50CD4 /* recursion.json in Resources */,
F9B62CC8264BC61600492999 /* category-cafe.json in Resources */,
F9ACA6192642C49000F50CD4 /* retrieve-category.json in Resources */,
Expand Down Expand Up @@ -2061,6 +2070,7 @@
F907440F261B00000091899C /* suggestions-san-francisco.json in Resources */,
F94FFA4826453D410019ED9B /* reverse-geocoding.json in Resources */,
2CD8AC4B29F1D38800C47BE4 /* suggestions-with-mixed-coordinates.json in Resources */,
0488234A2B6B0A9E00C770AA /* category-hotel-search-along-route-jp.json in Resources */,
2CD8AC5429F28D6900C47BE4 /* retrieve-poi.json in Resources */,
F9074425261B0DF70091899C /* retrieve-san-francisco.json in Resources */,
2CD8AC4829F1D38800C47BE4 /* suggestions-with-coordinates.json in Resources */,
Expand All @@ -2079,6 +2089,7 @@
F9C557A42670CB0400BE8B94 /* retrieve-multi.json in Resources */,
2CD8AC4329F1D38800C47BE4 /* suggestions-category-with-coordinates.json in Resources */,
F9C557A52670CB0400BE8B94 /* suggestions-empty.json in Resources */,
048823482B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */,
F9C557A62670CB0400BE8B94 /* recursion.json in Resources */,
F9C557A72670CB0400BE8B94 /* category-cafe.json in Resources */,
F9C557A82670CB0400BE8B94 /* retrieve-category.json in Resources */,
Expand Down Expand Up @@ -2589,6 +2600,7 @@
F9C557C12670CD8C00BE8B94 /* CoreSearchOptions+Samples.swift in Sources */,
1420F31C29A2800300D4A511 /* CoreSearchResultStub+Samples.swift in Sources */,
F9C557B72670CC5600BE8B94 /* CoreSearchResultStub.swift in Sources */,
04AB0B7B2B6AF43E00FDE7D5 /* DiscoverIntegrationTests.swift in Sources */,
F9C557BF2670CD4300BE8B94 /* CoreRequestOptions+Samples.swift in Sources */,
F9C557BB2670CCC000BE8B94 /* SearchResultType+Extensions.swift in Sources */,
F9C557BA2670CCAB00BE8B94 /* TestDataProviderRecord.swift in Sources */,
Expand Down
46 changes: 46 additions & 0 deletions Tests/MapboxSearchIntegrationTests/DiscoverIntegrationTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import CoreLocation
@testable import MapboxSearch
import XCTest

class DiscoverIntegrationTests: MockServerTestCase {
lazy var searchEngine = Discover(locationProvider: DefaultLocationProvider())

func testCategorySearchAlongRouteWithCountryProximityOrigin() throws {
try server.setResponse(.categoryHotelSearchAlongRoute_JP)
let expectation = XCTestExpectation(description: "Expecting results")

let coordinate1 = CLLocationCoordinate2D(latitude: 35.655614, longitude: 139.7081684)
let coordinate2 = CLLocationCoordinate2D(latitude: 35.6881616, longitude: 139.6994339)
let coordinates = [coordinate1, coordinate2]

let mapboxSearchRoute = MapboxSearch.Route(coordinates: coordinates)
let rOptions: MapboxSearch.RouteOptions = RouteOptions(route: mapboxSearchRoute, time: 1000)

let discoverOptions = Discover.Options(
limit: 10,
language: nil,
country: Country(countryCode: "jp"),
proximity: CLLocationCoordinate2D(
latitude: 35.6634363,
longitude: 139.7394536
),
origin: CLLocationCoordinate2D(latitude: 35.66580, longitude: 139.74609)
)

searchEngine.search(
for: Discover.Query.Category.canonicalName("hotel"),
route: rOptions,
options: discoverOptions
) { result in
switch result {
case .success(let searchResults):
XCTAssertFalse(searchResults.isEmpty)
expectation.fulfill()
case .failure:
XCTFail("Error not expected")
}
expectation.fulfill()
}
wait(for: [expectation], timeout: 10)
}
}
11 changes: 9 additions & 2 deletions Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ enum MockResponse {
case retrieve
case reverse
case multiRetrieve = "retrieve/multi"
case category
case categoryCafe = "cafe"
case categoryHotel = "hotel"
case addressSuggest = "autofill/suggest"
case addressRetrieve = "autofill/retrieve"
}
Expand All @@ -30,6 +31,7 @@ enum MockResponse {
case recursion
case reverseGeocoding
case categoryCafe
case categoryHotelSearchAlongRoute_JP

var path: String {
let bundle = Bundle(for: MockWebServer.self)
Expand Down Expand Up @@ -64,6 +66,8 @@ enum MockResponse {
return bundle.path(forResource: "retrieve-multi", ofType: "json")!
case .categoryCafe:
return bundle.path(forResource: "category-cafe", ofType: "json")!
case .categoryHotelSearchAlongRoute_JP:
return bundle.path(forResource: "category-hotel-search-along-route-jp", ofType: "json")!
case .suggestAddressSanFrancisco:
return bundle.path(forResource: "address-suggestions-san-francisco", ofType: "json")!
case .retrieveAddressSanFrancisco:
Expand Down Expand Up @@ -102,7 +106,10 @@ enum MockResponse {
return .multiRetrieve

case .categoryCafe:
return .category
return .categoryCafe

case .categoryHotelSearchAlongRoute_JP:
return .categoryHotel
}
}
}
9 changes: 5 additions & 4 deletions Tests/MapboxSearchUITests/MockWebServer/MockWebServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ extension MockWebServer {

fileprivate static func httpMethod(for endpoint: MockResponse.Endpoint) -> HTTPMethod {
switch endpoint {
case .suggest, .category, .reverse, .addressSuggest, .addressRetrieve:
case .suggest, .categoryCafe, .reverse, .addressSuggest, .addressRetrieve:
return .get

case .retrieve, .multiRetrieve:
case .retrieve, .multiRetrieve, .categoryHotel:
return .post
}
}
Expand All @@ -75,8 +75,9 @@ extension MockWebServer {
case .suggest:
path += "/:query"

case .category:
path += "/:category"
case .categoryCafe,
.categoryHotel:
path = "search/v1/category/\(endpoint.rawValue)"

case .multiRetrieve:
break
Expand Down
Loading

0 comments on commit bab5844

Please sign in to comment.