Skip to content

Commit 84b7ac0

Browse files
committed
rewrite decode limitToLast query
1 parent efa84a5 commit 84b7ac0

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

firebase-firestore/src/test/java/com/google/firebase/firestore/bundle/BundleSerializerTest.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,34 @@ public void testDecodesLimitQuery() throws JSONException {
570570

571571
@Test
572572
public void testDecodesLimitToLastQuery() throws JSONException {
573-
String json = "{ from: [ { collectionId: 'coll' } ], limit: {value: 5 } }";
574-
Query query = TestUtil.query("coll").orderBy(orderBy("__name__", "desc")).limitToLast(5);
575-
assertDecodesNamedQuery(json, query);
573+
String queryJson =
574+
"{\n"
575+
+ " name: 'query-1',\n"
576+
+ " bundledQuery: {\n"
577+
+ " parent: '"
578+
+ TEST_PROJECT
579+
+ "',\n"
580+
+ " structuredQuery:\n"
581+
+ "{ from: [ { collectionId: 'coll' } ], limit: {value: 5 } }"
582+
+ ",\n"
583+
+ " limitType: 'LAST'\n"
584+
+ " },\n"
585+
+ " readTime: '2020-01-01T00:00:01.000000001Z'\n"
586+
+ "}";
587+
NamedQuery actualNamedQuery = serializer.decodeNamedQuery(new JSONObject(queryJson));
588+
589+
// Note we use limitToFirst instead of limitToLast to avoid order reverse.
590+
// Because this is what is saved in bundle files.
591+
Query query = TestUtil.query("coll").limitToFirst(5);
592+
Target target = query.toTarget();
593+
BundledQuery bundledQuery = new BundledQuery(target, Query.LimitType.LIMIT_TO_LAST);
594+
NamedQuery expectedNamedQuery =
595+
new NamedQuery(
596+
"query-1",
597+
bundledQuery,
598+
new SnapshotVersion(new com.google.firebase.Timestamp(1577836801, 1)));
599+
600+
assertEquals(expectedNamedQuery, actualNamedQuery);
576601
}
577602

578603
@Test

0 commit comments

Comments
 (0)