-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update unit tests for search-box API type, add mock data
- Add name prefixes for SBS_ and SearchBox_. - To display in the Xcode UI test classes must coexist in the global namespace so we have to use old-fashioned prefixes. - Add note to reorganize SBS mock data in the future. - Add SearchBoxMockResponse, initially based on SBS, to provide data for search-box API tests. - Fix namespace collision within MockWebServer.setResponse function clobbering response function argument.
- Loading branch information
Showing
13 changed files
with
1,800 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...boxSearchIntegrationTests/search-box/SearchBox_CategorySearchEngineIntegrationTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.