feat(mock): alias __name__ to id in mocked _orderBy - #420
Merged
Conversation
Firestore addresses document IDs via the reserved `__name__` field (both in query orderBy and in cursor construction). Yust stores document IDs in the `id` field on every YustDoc, and every YustDatabaseService method that touches Firestore's `__name__` already handles the alias internally (see the Cursor construction in yust_database_service_dart.dart:1330-1355 and the orderBy augmentation in _getListLazyChunked). The mocked database is the only impl that didn't recognize `__name__`: `_orderBy` reads the field value via `_readValueInJsonDoc`, which returns null for `__name__` (no such field on a JSON doc) and blows up the `.compareTo` call. Alias `__name__` → `id` in `_orderBy` so mock and REST behave consistently. This makes it safe for callers of `getListFromDB` to append `__name__` as a stable pagination tiebreaker (mirroring what `_getListLazyChunked` already does internally) without breaking mock-backed tests. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
The mocked
YustDatabaseService._orderByreads the field value via_readValueInJsonDoc, which returnsnullfor the reserved__name__field name — sorting by__name__then blows up on the.compareTocall.Aliases
__name__→idin the mock so tests can freely add__name__as a stable pagination tiebreaker (the same pattern_getListLazyChunkedalready uses internally, and the same alias the REST impl does viaCursorconstruction atyust_database_service_dart.dart:1330-1355).Why now
Univelop's Records API v2 pagination fix appends
__name__as a tiebreaker to the orderBy sent togetListFromDB, mirroring the chunked-path pattern. That change makes uni_api pagination correct against real Firestore but breaks against the mocked DB — this small alias closes the parity gap.Isolated from #419 (the paired
getListFromDBcursor fix) — this one only touches the mock, so it can land and release independently.Test plan
dart analyzeclean🤖 Generated with Claude Code