fix(search): resolve null entrances in cave search results#1711
Merged
Conversation
- Handle both Waterline objects and plain IDs in toSimpleCave converter - Add regression tests for entrance ID extraction
Paul-AUB
previously approved these changes
Jun 28, 2026
Paul-AUB
left a comment
Contributor
There was a problem hiding this comment.
Suggestions (Should Consider)
- [test/integration/1_services/Converters.test.js] The
null-in-array edge case is not covered. Withe?.id ?? e, anullentry evaluates asnull?.id → undefined, thenundefined ?? null → null, so nulls pass through silently. This matches the old broken behavior and could mask corrupt Typesense documents. Consider adding a test that documents the current behavior (or asserts that nulls are filtered out, if that's the desired outcome).
Nitpicks (Optional)
- [test/integration/1_services/Converters.test.js] Consider adding a test for
entrances: [](empty array). It's trivially handled by the current code, but it documents the contract and prevents future regressions if anyone refactors the optional-chaining logic.
- Add .filter() to remove null/undefined from toSimpleCave entrances - Add test for null-in-array edge case - Add test for empty entrances array
Contributor
Author
|
Both review items addressed in 6c950a2:
All 3107 tests pass, lint clean. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 What
entrancesfield in cave search results returning[null, null, ...]instead of actual entrance IDstoSimpleCaveentrance ID extraction🤷♂️ Why
The quick-search endpoint (
POST /api/v1/search) returnsnullvalues in theentrancesarray for cave results. This happens because the production Typesense index stores entrance IDs as plain integers (e.g.,[20, 21, 25877]), but thetoSimpleCaveconverter assumed they would always be Waterline objects with an.idproperty. Calling.idon a number yieldsundefined, which JSON serializes asnull.🔍 How
Changed
source.entrances?.map((e) => e.id)tosource.entrances?.map((e) => e?.id ?? e)intoSimpleCave. This handles both formats:.populate()) → extracts.id🧪 Testing
Four new test cases cover:
entrancesfield → returnsundefined