From 4c092cd7a2b9fbd4c5f57e47115316e2b2f46323 Mon Sep 17 00:00:00 2001 From: Jannis Rosenbaum Date: Fri, 3 Jul 2026 21:24:36 +0200 Subject: [PATCH] feat(mock): alias __name__ to id in mocked _orderBy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- lib/src/services/yust_database_service_mocked.dart | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/src/services/yust_database_service_mocked.dart b/lib/src/services/yust_database_service_mocked.dart index 67fa406c..7635e33e 100644 --- a/lib/src/services/yust_database_service_mocked.dart +++ b/lib/src/services/yust_database_service_mocked.dart @@ -652,9 +652,18 @@ class YustDatabaseServiceMocked extends YustDatabaseService List? orderBy, ) { for (final o in (orderBy ?? []).reversed) { + // Firestore addresses the document ID via the reserved `__name__` + // field. Yust stores document IDs in the `id` field on every + // YustDoc, so alias `__name__` → `id` here to mirror Firestore's + // behavior. Enables tests that append `__name__` as a stable + // pagination tiebreaker (as `_getListLazyChunked` does internally, + // and as callers of `getListFromDB` should for correct cursor + // advancement). + final field = o.field == '__name__' ? 'id' : o.field; collection.sort((a, b) { - final compare = (_readValueInJsonDoc(a, o.field) as Comparable) - .compareTo(_readValueInJsonDoc(b, o.field) as Comparable); + final compare = (_readValueInJsonDoc(a, field) as Comparable).compareTo( + _readValueInJsonDoc(b, field) as Comparable, + ); final order = o.descending ? -1 : 1; return order * compare; });