|
21 | 21 | #include "Firestore/Protos/cpp/google/firestore/v1/document.pb.h"
|
22 | 22 | #include "Firestore/core/src/core/field_filter.h"
|
23 | 23 | #include "Firestore/core/src/core/query.h"
|
| 24 | +#include "Firestore/core/src/core/target.h" |
24 | 25 | #include "Firestore/core/src/local/local_serializer.h"
|
25 | 26 | #include "Firestore/core/src/model/database_id.h"
|
26 | 27 | #include "Firestore/core/src/nanopb/byte_string.h"
|
@@ -49,6 +50,7 @@ using ProtoMaybeDocument = ::firestore::client::MaybeDocument;
|
49 | 50 | using ProtoNamedQuery = ::firestore::NamedQuery;
|
50 | 51 | using ProtoValue = ::google::firestore::v1::Value;
|
51 | 52 | using core::Query;
|
| 53 | +using core::Target; |
52 | 54 | using local::LocalSerializer;
|
53 | 55 | using model::DatabaseId;
|
54 | 56 | using nanopb::ByteString;
|
@@ -924,6 +926,39 @@ TEST_F(BundleSerializerTest, DecodesOrderBys) {
|
924 | 926 | VerifyNamedQueryRoundtrip(original);
|
925 | 927 | }
|
926 | 928 |
|
| 929 | +// By default, the queries used for testing in this file always have default |
| 930 | +// OrderBy ("__name__") generated. We need to explicitly remove that for this |
| 931 | +// test. |
| 932 | +TEST_F(BundleSerializerTest, DecodeMissingOrderBysWorks) { |
| 933 | + // This is `NamedQueryToJson(testutil::Query("bundles/docs/colls"))` with |
| 934 | + // orderBy field manually removed. |
| 935 | + auto json_string = R"|( |
| 936 | +{ |
| 937 | + "name":"query-1", |
| 938 | + "bundledQuery":{ |
| 939 | + "parent":"projects/p/databases/default/documents/bundles/docs", |
| 940 | + "structuredQuery":{"from":[{"collectionId":"colls"}]} |
| 941 | + }, |
| 942 | + "readTime":"2021-03-17T14:04:20.166729927Z" |
| 943 | +} |
| 944 | +)|"; |
| 945 | + JsonReader reader; |
| 946 | + auto named_query = |
| 947 | + bundle_serializer.DecodeNamedQuery(reader, Parse(json_string)); |
| 948 | + |
| 949 | + EXPECT_OK(reader.status()); |
| 950 | + EXPECT_EQ(named_query.query_name(), "query-1"); |
| 951 | + |
| 952 | + // Reconstruct a core::Query from the deserialized target, this is how |
| 953 | + // eventually the named query is used. |
| 954 | + const Target& target = named_query.bundled_query().target(); |
| 955 | + Query query(target.path(), target.collection_group(), target.filters(), |
| 956 | + target.order_bys(), target.limit(), |
| 957 | + named_query.bundled_query().limit_type(), target.start_at(), |
| 958 | + target.end_at()); |
| 959 | + EXPECT_EQ(query.ToTarget(), testutil::Query("bundles/docs/colls").ToTarget()); |
| 960 | +} |
| 961 | + |
927 | 962 | TEST_F(BundleSerializerTest, DecodeInvalidOrderBysFails) {
|
928 | 963 | std::string json_string =
|
929 | 964 | NamedQueryJsonString(testutil::Query("colls")
|
|
0 commit comments