|
51 | 51 | @RunWith(RobolectricTestRunner.class)
|
52 | 52 | @Config(manifest = Config.NONE)
|
53 | 53 | public class BundleSerializerTest {
|
54 |
| - // Note: This tests uses single-quoted JSON strings, which are accepted by org.json.JSONObject. |
55 |
| - // While they are invalid JSON, they allow us to no use non-escaped quotes in the test file. |
| 54 | + // Note: This tests uses single-quoted JSON strings, which are accepted by |
| 55 | + // org.json.JSONObject. |
| 56 | + // While they are invalid JSON, they allow us to no use non-escaped quotes in |
| 57 | + // the test file. |
56 | 58 |
|
57 | 59 | private static String TEST_PROJECT = "projects/project/databases/(default)/documents";
|
58 | 60 | private static String TEST_DOCUMENT = TEST_PROJECT + "/coll/doc";
|
@@ -672,6 +674,32 @@ public void testDecodesBundledDocumentMetadata() throws JSONException {
|
672 | 674 | assertEquals(expectedMetadata, actualMetadata);
|
673 | 675 | }
|
674 | 676 |
|
| 677 | + @Test |
| 678 | + public void testDecodesTargetWithoutImplicitOrderByOnName() throws JSONException { |
| 679 | + String json = |
| 680 | + "{\"name\":\"myNamedQuery\",\"bundledQuery\":{\"parent\":\"projects/project/databases" |
| 681 | + + "/(default)/documents\",\"structuredQuery\":{\"from\":[{\"collectionId\":\"foo\"}]," |
| 682 | + + "\"limit\":{\"value\":10}},\"limitType\":\"FIRST\"}," |
| 683 | + + "\"readTime\":{\"seconds\":\"1679674432\",\"nanos\":579934000}}"; |
| 684 | + NamedQuery query = serializer.decodeNamedQuery(new JSONObject(json)); |
| 685 | + assertEquals( |
| 686 | + TestUtil.query("foo").limitToFirst(10).toTarget(), query.getBundledQuery().getTarget()); |
| 687 | + assertEquals(Query.LimitType.LIMIT_TO_FIRST, query.getBundledQuery().getLimitType()); |
| 688 | + } |
| 689 | + |
| 690 | + @Test |
| 691 | + public void testDecodesLimitToLastTargetWithoutImplicitOrderByOnName() throws JSONException { |
| 692 | + String json = |
| 693 | + "{\"name\":\"myNamedQuery\",\"bundledQuery\":{\"parent\":\"projects/project/databases" |
| 694 | + + "/(default)/documents\",\"structuredQuery\":{\"from\":[{\"collectionId\":\"foo\"}]," |
| 695 | + + "\"limit\":{\"value\":10}},\"limitType\":\"LAST\"}," |
| 696 | + + "\"readTime\":{\"seconds\":\"1679674432\",\"nanos\":579934000}}"; |
| 697 | + NamedQuery query = serializer.decodeNamedQuery(new JSONObject(json)); |
| 698 | + assertEquals( |
| 699 | + TestUtil.query("foo").limitToLast(10).toTarget(), query.getBundledQuery().getTarget()); |
| 700 | + assertEquals(Query.LimitType.LIMIT_TO_LAST, query.getBundledQuery().getLimitType()); |
| 701 | + } |
| 702 | + |
675 | 703 | private void assertDecodesValue(String json, Value proto) throws JSONException {
|
676 | 704 | String documentJson =
|
677 | 705 | "{\n"
|
@@ -719,15 +747,7 @@ private void assertDecodesNamedQuery(String json, Query query) throws JSONExcept
|
719 | 747 | + "}";
|
720 | 748 | NamedQuery actualNamedQuery = serializer.decodeNamedQuery(new JSONObject(queryJson));
|
721 | 749 |
|
722 |
| - Target target = |
723 |
| - new Target( |
724 |
| - query.getPath(), |
725 |
| - query.getCollectionGroup(), |
726 |
| - query.getFilters(), |
727 |
| - query.getExplicitOrderBy(), |
728 |
| - query.getLimit(), |
729 |
| - query.getStartAt(), |
730 |
| - query.getEndAt()); |
| 750 | + Target target = query.toTarget(); |
731 | 751 | BundledQuery bundledQuery =
|
732 | 752 | new BundledQuery(
|
733 | 753 | target,
|
|
0 commit comments