20
20
21
21
#include " Firestore/core/src/firebase/firestore/model/document.h"
22
22
#include " Firestore/core/src/firebase/firestore/model/field_value.h"
23
+ #include " Firestore/core/src/firebase/firestore/model/maybe_document.h"
23
24
#include " Firestore/core/test/firebase/firestore/testutil/testutil.h"
24
25
#include " gtest/gtest.h"
25
26
@@ -35,45 +36,45 @@ using testutil::PatchMutation;
35
36
using testutil::SetMutation;
36
37
37
38
TEST (Mutation, AppliesSetsToDocuments) {
38
- auto base_doc = std::make_shared<Document>(
39
+ MaybeDocumentPtr base_doc =
39
40
Doc (" collection/key" , 0 ,
40
41
{{" foo" , FieldValue::FromString (" foo-value" )},
41
- {" baz" , FieldValue::FromString (" baz-value" )}})) ;
42
+ {" baz" , FieldValue::FromString (" baz-value" )}});
42
43
43
44
std::unique_ptr<Mutation> set = SetMutation (
44
45
" collection/key" , {{" bar" , FieldValue::FromString (" bar-value" )}});
45
46
MaybeDocumentPtr set_doc =
46
47
set->ApplyToLocalView (base_doc, base_doc.get (), Timestamp::Now ());
47
48
ASSERT_NE (set_doc, nullptr );
48
49
ASSERT_EQ (set_doc->type (), MaybeDocument::Type::Document);
49
- EXPECT_EQ (*set_doc. get (), Doc (" collection/key" , 0 ,
50
- {{" bar" , FieldValue::FromString (" bar-value" )}},
51
- DocumentState::kLocalMutations ));
50
+ EXPECT_EQ (*set_doc, * Doc (" collection/key" , 0 ,
51
+ {{" bar" , FieldValue::FromString (" bar-value" )}},
52
+ DocumentState::kLocalMutations ));
52
53
}
53
54
54
55
TEST (Mutation, AppliesPatchToDocuments) {
55
- auto base_doc = std::make_shared<Document>( Doc (
56
+ MaybeDocumentPtr base_doc = Doc (
56
57
" collection/key" , 0 ,
57
58
{{" foo" ,
58
59
FieldValue::FromMap ({{" bar" , FieldValue::FromString (" bar-value" )}})},
59
- {" baz" , FieldValue::FromString (" baz-value" )}})) ;
60
+ {" baz" , FieldValue::FromString (" baz-value" )}});
60
61
61
62
std::unique_ptr<Mutation> patch = PatchMutation (
62
63
" collection/key" , {{" foo.bar" , FieldValue::FromString (" new-bar-value" )}});
63
64
MaybeDocumentPtr local =
64
65
patch->ApplyToLocalView (base_doc, base_doc.get (), Timestamp::Now ());
65
66
ASSERT_NE (local, nullptr );
66
67
EXPECT_EQ (
67
- *local. get () ,
68
- Doc (" collection/key" , 0 ,
69
- {{" foo" , FieldValue::FromMap (
70
- {{" bar" , FieldValue::FromString (" new-bar-value" )}})},
71
- {" baz" , FieldValue::FromString (" baz-value" )}},
72
- DocumentState::kLocalMutations ));
68
+ *local,
69
+ * Doc (" collection/key" , 0 ,
70
+ {{" foo" , FieldValue::FromMap (
71
+ {{" bar" , FieldValue::FromString (" new-bar-value" )}})},
72
+ {" baz" , FieldValue::FromString (" baz-value" )}},
73
+ DocumentState::kLocalMutations ));
73
74
}
74
75
75
76
TEST (Mutation, AppliesPatchWithMergeToDocuments) {
76
- auto base_doc = std::make_shared<NoDocument>( DeletedDoc (" collection/key" , 0 ) );
77
+ MaybeDocumentPtr base_doc = DeletedDoc (" collection/key" , 0 );
77
78
78
79
std::unique_ptr<Mutation> upsert = PatchMutation (
79
80
" collection/key" , {{" foo.bar" , FieldValue::FromString (" new-bar-value" )}},
@@ -82,11 +83,11 @@ TEST(Mutation, AppliesPatchWithMergeToDocuments) {
82
83
upsert->ApplyToLocalView (base_doc, base_doc.get (), Timestamp::Now ());
83
84
ASSERT_NE (new_doc, nullptr );
84
85
EXPECT_EQ (
85
- *new_doc. get () ,
86
- Doc (" collection/key" , 0 ,
87
- {{" foo" , FieldValue::FromMap (
88
- {{" bar" , FieldValue::FromString (" new-bar-value" )}})}},
89
- DocumentState::kLocalMutations ));
86
+ *new_doc,
87
+ * Doc (" collection/key" , 0 ,
88
+ {{" foo" , FieldValue::FromMap (
89
+ {{" bar" , FieldValue::FromString (" new-bar-value" )}})}},
90
+ DocumentState::kLocalMutations ));
90
91
}
91
92
92
93
TEST (Mutation, AppliesPatchToNullDocWithMergeToDocuments) {
@@ -99,38 +100,38 @@ TEST(Mutation, AppliesPatchToNullDocWithMergeToDocuments) {
99
100
upsert->ApplyToLocalView (base_doc, base_doc.get (), Timestamp::Now ());
100
101
ASSERT_NE (new_doc, nullptr );
101
102
EXPECT_EQ (
102
- *new_doc. get () ,
103
- Doc (" collection/key" , 0 ,
104
- {{" foo" , FieldValue::FromMap (
105
- {{" bar" , FieldValue::FromString (" new-bar-value" )}})}},
106
- DocumentState::kLocalMutations ));
103
+ *new_doc,
104
+ * Doc (" collection/key" , 0 ,
105
+ {{" foo" , FieldValue::FromMap (
106
+ {{" bar" , FieldValue::FromString (" new-bar-value" )}})}},
107
+ DocumentState::kLocalMutations ));
107
108
}
108
109
109
110
TEST (Mutation, DeletesValuesFromTheFieldMask) {
110
- auto base_doc = std::make_shared<Document>( Doc (
111
+ MaybeDocumentPtr base_doc = Doc (
111
112
" collection/key" , 0 ,
112
113
{{" foo" ,
113
114
FieldValue::FromMap ({{" bar" , FieldValue::FromString (" bar-value" )},
114
- {" baz" , FieldValue::FromString (" baz-value" )}})}})) ;
115
+ {" baz" , FieldValue::FromString (" baz-value" )}})}});
115
116
116
117
std::unique_ptr<Mutation> patch =
117
118
PatchMutation (" collection/key" , FieldValue::Map (), {Field (" foo.bar" )});
118
119
119
120
MaybeDocumentPtr patch_doc =
120
121
patch->ApplyToLocalView (base_doc, base_doc.get (), Timestamp::Now ());
121
122
ASSERT_NE (patch_doc, nullptr );
122
- EXPECT_EQ (*patch_doc. get () ,
123
- Doc (" collection/key" , 0 ,
124
- {{" foo" , FieldValue::FromMap (
125
- {{" baz" , FieldValue::FromString (" baz-value" )}})}},
126
- DocumentState::kLocalMutations ));
123
+ EXPECT_EQ (*patch_doc,
124
+ * Doc (" collection/key" , 0 ,
125
+ {{" foo" , FieldValue::FromMap (
126
+ {{" baz" , FieldValue::FromString (" baz-value" )}})}},
127
+ DocumentState::kLocalMutations ));
127
128
}
128
129
129
130
TEST (Mutation, PatchesPrimitiveValue) {
130
- auto base_doc = std::make_shared<Document>(
131
+ MaybeDocumentPtr base_doc =
131
132
Doc (" collection/key" , 0 ,
132
133
{{" foo" , FieldValue::FromString (" foo-value" )},
133
- {" baz" , FieldValue::FromString (" baz-value" )}})) ;
134
+ {" baz" , FieldValue::FromString (" baz-value" )}});
134
135
135
136
std::unique_ptr<Mutation> patch = PatchMutation (
136
137
" collection/key" , {{" foo.bar" , FieldValue::FromString (" new-bar-value" )}});
@@ -139,17 +140,16 @@ TEST(Mutation, PatchesPrimitiveValue) {
139
140
patch->ApplyToLocalView (base_doc, base_doc.get (), Timestamp::Now ());
140
141
ASSERT_NE (patched_doc, nullptr );
141
142
EXPECT_EQ (
142
- *patched_doc. get () ,
143
- Doc (" collection/key" , 0 ,
144
- {{" foo" , FieldValue::FromMap (
145
- {{" bar" , FieldValue::FromString (" new-bar-value" )}})},
146
- {" baz" , FieldValue::FromString (" baz-value" )}},
147
- DocumentState::kLocalMutations ));
143
+ *patched_doc,
144
+ * Doc (" collection/key" , 0 ,
145
+ {{" foo" , FieldValue::FromMap (
146
+ {{" bar" , FieldValue::FromString (" new-bar-value" )}})},
147
+ {" baz" , FieldValue::FromString (" baz-value" )}},
148
+ DocumentState::kLocalMutations ));
148
149
}
149
150
150
151
TEST (Mutation, PatchingDeletedDocumentsDoesNothing) {
151
- auto base_doc =
152
- std::make_shared<NoDocument>(testutil::DeletedDoc (" collection/key" , 0 ));
152
+ MaybeDocumentPtr base_doc = testutil::DeletedDoc (" collection/key" , 0 );
153
153
std::unique_ptr<Mutation> patch =
154
154
PatchMutation (" collection/key" , {{" foo" , FieldValue::FromString (" bar" )}});
155
155
MaybeDocumentPtr patched_doc =
@@ -251,45 +251,45 @@ TEST(Mutation, AppliesServerAckedArrayTransformsToDocuments) {
251
251
}
252
252
253
253
TEST (Mutation, DeleteDeletes) {
254
- auto base_doc = std::make_shared<Document>(
255
- Doc (" collection/key" , 0 , {{" foo" , FieldValue::FromString (" bar" )}})) ;
254
+ MaybeDocumentPtr base_doc =
255
+ Doc (" collection/key" , 0 , {{" foo" , FieldValue::FromString (" bar" )}});
256
256
257
257
std::unique_ptr<Mutation> del = testutil::DeleteMutation (" collection/key" );
258
258
MaybeDocumentPtr deleted_doc =
259
259
del->ApplyToLocalView (base_doc, base_doc.get (), Timestamp::Now ());
260
260
261
261
ASSERT_NE (deleted_doc, nullptr );
262
- EXPECT_EQ (*deleted_doc. get (), testutil::DeletedDoc (" collection/key" , 0 ));
262
+ EXPECT_EQ (*deleted_doc, * testutil::DeletedDoc (" collection/key" , 0 ));
263
263
}
264
264
265
265
TEST (Mutation, SetWithMutationResult) {
266
- auto base_doc = std::make_shared<Document>(
267
- Doc (" collection/key" , 0 , {{" foo" , FieldValue::FromString (" bar" )}})) ;
266
+ MaybeDocumentPtr base_doc =
267
+ Doc (" collection/key" , 0 , {{" foo" , FieldValue::FromString (" bar" )}});
268
268
269
269
std::unique_ptr<Mutation> set = SetMutation (
270
270
" collection/key" , {{" foo" , FieldValue::FromString (" new-bar" )}});
271
271
MaybeDocumentPtr set_doc =
272
272
set->ApplyToRemoteDocument (base_doc, MutationResult (4 ));
273
273
274
274
ASSERT_NE (set_doc, nullptr );
275
- EXPECT_EQ (*set_doc. get (), Doc (" collection/key" , 4 ,
276
- {{" foo" , FieldValue::FromString (" new-bar" )}},
277
- DocumentState::kCommittedMutations ));
275
+ EXPECT_EQ (*set_doc, * Doc (" collection/key" , 4 ,
276
+ {{" foo" , FieldValue::FromString (" new-bar" )}},
277
+ DocumentState::kCommittedMutations ));
278
278
}
279
279
280
280
TEST (Mutation, PatchWithMutationResult) {
281
- auto base_doc = std::make_shared<Document>(
282
- Doc (" collection/key" , 0 , {{" foo" , FieldValue::FromString (" bar" )}})) ;
281
+ MaybeDocumentPtr base_doc =
282
+ Doc (" collection/key" , 0 , {{" foo" , FieldValue::FromString (" bar" )}});
283
283
284
284
std::unique_ptr<Mutation> patch = PatchMutation (
285
285
" collection/key" , {{" foo" , FieldValue::FromString (" new-bar" )}});
286
286
MaybeDocumentPtr patch_doc =
287
287
patch->ApplyToRemoteDocument (base_doc, MutationResult (4 ));
288
288
289
289
ASSERT_NE (patch_doc, nullptr );
290
- EXPECT_EQ (*patch_doc. get (), Doc (" collection/key" , 4 ,
291
- {{" foo" , FieldValue::FromString (" new-bar" )}},
292
- DocumentState::kCommittedMutations ));
290
+ EXPECT_EQ (*patch_doc, * Doc (" collection/key" , 4 ,
291
+ {{" foo" , FieldValue::FromString (" new-bar" )}},
292
+ DocumentState::kCommittedMutations ));
293
293
}
294
294
295
295
TEST (Mutation, Transitions) {
0 commit comments