Skip to content
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

Merged
merged 23 commits into from
Feb 28, 2024

Conversation

aokj4ck
Copy link
Contributor

@aokj4ck aokj4ck commented Jan 30, 2024

Description

  • Fixes SSDK-541
  • Start adding search-box API validation

Checklist

  • Update CHANGELOG

…541-add-searchbox-validation

Conflicts:
	Sources/MapboxSearch/InternalAPI/Engine/ApiType+Core.swift
	Sources/MapboxSearch/PublicAPI/Engine/ApiType.swift
	Sources/MapboxSearch/PublicAPI/MapboxSearchVersion.swift
	Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift
…sts - SSDK-541

- Test mocking needs to support different API engine types to make this easier
@aokj4ck
Copy link
Contributor Author

aokj4ck commented Feb 14, 2024

Depends on #179 which generalizes tests and associates mock data with the API type so that it is clear and easy to understand which API type a test should use (geocoding, SBS, autofill, search-box).

aokj4ck and others added 4 commits February 15, 2024 09:19
- 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.
@aokj4ck
Copy link
Contributor Author

aokj4ck commented Feb 26, 2024

  • SearchBox_SearchEngineIntegrationTests.testResolvedSearchResult()
  • SearchBox_SearchEngineIntegrationTests.testResolvedSearchResultWhenQueryChanged()

will be fixed in SAPI-1176

@@ -1,16 +1,18 @@
import XCTest

class CategorySuggestionsIntegrationTestCase: MockSBSServerUITestCase {
// Rename to UITestCase
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the UI test cases have "Integration" in the name rather than "UI" and this conflicts with the actual integration tests which also have "integration" in their names.

This rename operation and other clean-up changes (split MockResponse enum instances into separate files, rename MockResponse cases) can occur in a separate PR to reduce noise.

@@ -1,6 +1,7 @@
import XCTest

class FavoritesIntegrationTestCase: MockSBSServerUITestCase {
// Rename to UITestCase
class FavoritesIntegrationTestCase: MockSearchBoxUITestCase {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Favorites UI tests are failing on Minsk name in results and this will be fixed in SAPI-1176

@aokj4ck aokj4ck marked this pull request as ready for review February 26, 2024 18:41
@aokj4ck aokj4ck requested review from a team as code owners February 26, 2024 18:53
@aokj4ck aokj4ck requested review from azarovalex and a user February 26, 2024 18:53
Comment on lines 180 to 195
func testSuggestionTypeQuery() throws {
try server.setResponse(.recursion)

let updateExpectation = delegate.updateExpectation
searchEngine.query = "Recursion"
wait(for: [updateExpectation], timeout: 10)

let firstSuggestion = try XCTUnwrap(searchEngine.suggestions.first)
searchEngine.select(suggestion: firstSuggestion)

/// Mock that a subsequent retrieve call has been made and succeeds.
/// This is not implemented in the stub delegate (it reports success).
/// We have validated that the chained operations are connected.
let nextUpdateExpectation = delegate.updateExpectation
wait(for: [nextUpdateExpectation], timeout: 10)
XCTAssertFalse(searchEngine.suggestions.isEmpty)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@azarovalex this test function is passing locally but failing on CircleCI, does anything stand-out as wrong?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I've just tried running these tests in Xcode as well as make ci-full-test and it failed both times.
Could it be that we can't wait for an expectation that was already fulfilled before? Or maybe expectedFulfillmentCount to 2.

Also some other tests from this file fail for me on aa1b605
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those other tests will be fixed in SAPI-1176

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I found that, oddly, the CircleCI tests were hitting the subsequent retrieve request but local tests were jumping right to the fulfilled expectation.

On CircleCI I ran modifications of just this test to triage and captured that in commit b370ae3

MapboxSearchIntegrationTests.SearchBox_SearchEngineIntegrationTests
  testSuggestionTypeQuery, XCTAssertEqual failed: ("Optional("Search Result resolution failed, Layer:[MapboxServerAPIDataProvider], Name:[Recursion Software]")") is not equal to ("Optional("")")
  /Users/distiller/project/Tests/MapboxSearchIntegrationTests/search-box/SearchBox_SearchEngineIntegrationTests.swift:193
 
        wait(for: [nextExpect], timeout: 10)
	XCTAssertEqual(delegate.error?.localizedDescription, "")
        XCTAssertFalse(searchEngine.suggestions.isEmpty)

Please review when you can!

CircleCI is failing with an error object, narrowing this down

```
MapboxSearchIntegrationTests.SearchBox_SearchEngineIntegrationTests
  testSuggestionTypeQuery, XCTAssertEqual failed: ("Optional("Search Result resolution failed, Layer:[MapboxServerAPIDataProvider], Name:[Recursion Software]")") is not equal to ("Optional("")")
  /Users/distiller/project/Tests/MapboxSearchIntegrationTests/search-box/SearchBox_SearchEngineIntegrationTests.swift:193
  ```
        wait(for: [nextExpect], timeout: 10)
	XCTAssertEqual(delegate.error?.localizedDescription, "")
        XCTAssertFalse(searchEngine.suggestions.isEmpty)
  ```
```

if !timeRange.contains(value) {
info(
"search-box API time_deviation must be within 1 minute and 30 minutes (found \(value.value) seconds)"
Copy link
Contributor

@azarovalex azarovalex Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just my thoughts)
so if the argument is out of bounds we just silently log and do nothing?
maybe we should force change deviation to be in bounds or log with higher log level, like warning
or maybe fail the request alltogether

unit: UnitDuration.minutes
)
.converted(to: .seconds)
let timeRange = (minimumTime...maximumTime)
Copy link
Contributor

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

@aokj4ck aokj4ck merged commit f72f8f8 into main Feb 28, 2024
4 checks passed
@aokj4ck aokj4ck deleted the SSDK-541-add-searchbox-validation branch February 28, 2024 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants