-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SSDK-541] Add searchbox validation, change Demo to searchbox #164
Changes from 21 commits
68be932
d61124e
03f62f5
44daef9
459a898
3dad1be
90c9aa2
77cca06
b485654
445445f
2323ce2
b9cfadb
cf7f975
6e2a824
385d69d
fc2948c
6992770
27b8483
fa75ab1
1101633
aa1b605
80585cd
b370ae3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ extension ApiType { | |
return .geocoding | ||
case .SBS: | ||
return .SBS | ||
case .searchBox: | ||
return .searchBox | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -309,6 +309,26 @@ public struct SearchOptions { | |
info("SBS API doesn't support multiple languages at once. Search SDK will use the first") | ||
} | ||
|
||
if case .time(let value, _) = validSearchOptions.routeOptions?.deviation { | ||
let minimumTime = Measurement( | ||
value: 1, | ||
unit: UnitDuration.minutes | ||
) | ||
.converted(to: .seconds) | ||
let maximumTime = Measurement( | ||
value: 30, | ||
unit: UnitDuration.minutes | ||
) | ||
.converted(to: .seconds) | ||
let timeRange = (minimumTime...maximumTime) | ||
|
||
if !timeRange.contains(value) { | ||
info( | ||
"SBS API time_deviation must be within 1 minute and 30 minutes (found \(value.value) seconds)" | ||
) | ||
} | ||
} | ||
|
||
case .autofill: | ||
let unsupportedFilterTypes: [SearchQueryType] = [.category] | ||
|
||
|
@@ -318,7 +338,39 @@ public struct SearchOptions { | |
} | ||
|
||
case .searchBox: | ||
_Logger.searchSDK.warning("SearchBox API is not supported yet.") | ||
let topLimit = 10 | ||
|
||
validSearchOptions.limit = limit.map { min($0, topLimit) } | ||
if validSearchOptions.limit != limit { | ||
info("search-box API supports as maximum as \(topLimit) limit.") | ||
} | ||
|
||
if languages.count > 1, let first = languages.first { | ||
validSearchOptions.languages = [first] | ||
info( | ||
"search-box API doesn't support multiple languages at once. Search SDK will use the first ('\(first)')" | ||
) | ||
} | ||
|
||
if case .time(let value, _) = validSearchOptions.routeOptions?.deviation { | ||
let minimumTime = Measurement( | ||
value: 1, | ||
unit: UnitDuration.minutes | ||
) | ||
.converted(to: .seconds) | ||
let maximumTime = Measurement( | ||
value: 30, | ||
unit: UnitDuration.minutes | ||
) | ||
.converted(to: .seconds) | ||
let timeRange = (minimumTime...maximumTime) | ||
|
||
if !timeRange.contains(value) { | ||
info( | ||
"search-box API time_deviation must be within 1 minute and 30 minutes (found \(value.value) seconds)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (just my thoughts) |
||
) | ||
} | ||
} | ||
|
||
@unknown default: | ||
_Logger.searchSDK.warning("Unexpected engine API Type: \(apiType)") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import CoreLocation | ||
@testable import MapboxSearch | ||
import XCTest | ||
|
||
final class SearchBox_CategorySearchEngineIntegrationTests: MockServerIntegrationTestCase<SearchBoxMockResponse> { | ||
private var searchEngine: CategorySearchEngine! | ||
|
||
override func setUpWithError() throws { | ||
try super.setUpWithError() | ||
|
||
let apiType = try XCTUnwrap(Mock.coreApiType.toSDKType()) | ||
searchEngine = CategorySearchEngine( | ||
accessToken: "access-token", | ||
serviceProvider: LocalhostMockServiceProvider.shared, | ||
apiType: apiType | ||
) | ||
} | ||
|
||
func testCategorySearch() throws { | ||
try server.setResponse(.categoryCafe) | ||
|
||
let expectation = XCTestExpectation(description: "Expecting results") | ||
searchEngine.search(categoryName: "cafe") { 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) | ||
} | ||
|
||
func testCategorySearchFailed() throws { | ||
try server.setResponse(.categoryCafe, statusCode: 500) | ||
|
||
let expectation = XCTestExpectation(description: "Expecting failure") | ||
searchEngine.search(categoryName: "cafe") { result in | ||
switch result { | ||
case .success: | ||
XCTFail("Not expected") | ||
case .failure(let searchError): | ||
if case .generic(let code, _, _) = searchError { | ||
XCTAssert(code == 500) | ||
} else { | ||
XCTFail("Not expected") | ||
} | ||
} | ||
expectation.fulfill() | ||
} | ||
wait(for: [expectation], timeout: 10) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can extract some logic here in a function to reuse it down below