Skip to content

Commit

Permalink
Add SBSMockResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
aokj4ck committed Feb 14, 2024
1 parent e992fa1 commit 70bd1be
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import CoreLocation
@testable import MapboxSearch
import XCTest

final class CategorySearchEngineIntegrationTests: MockServerIntegrationTestCase<LegacyResponse> {
final class CategorySearchEngineIntegrationTests: MockServerIntegrationTestCase<SBSMockResponse> {
private var searchEngine: CategorySearchEngine!

override func setUpWithError() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import CoreLocation
@testable import MapboxSearch
import XCTest

final class PlaceAutocompleteIntegrationTests: MockServerIntegrationTestCase<LegacyResponse> {
final class PlaceAutocompleteIntegrationTests: MockServerIntegrationTestCase<SBSMockResponse> {
private var placeAutocomplete: PlaceAutocomplete!

override func setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import CoreLocation
@testable import MapboxSearch
import XCTest

class SearchEngineIntegrationTests: MockServerIntegrationTestCase<LegacyResponse> {
class SearchEngineIntegrationTests: MockServerIntegrationTestCase<SBSMockResponse> {
let delegate = SearchEngineDelegateStub()
var searchEngine: SearchEngine!

Expand Down
148 changes: 148 additions & 0 deletions Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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>.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
Expand Down

0 comments on commit 70bd1be

Please sign in to comment.