@@ -191,11 +191,21 @@ def test__parent_info_nested(self):
191191
192192 def test_add_auto_assigned (self ):
193193 from google .cloud .firestore_v1beta1 .proto import document_pb2
194- from google .cloud .firestore_v1beta1 import _helpers
195194 from google .cloud .firestore_v1beta1 .document import DocumentReference
195+ from google .cloud .firestore_v1beta1 import SERVER_TIMESTAMP
196+ from google .cloud .firestore_v1beta1 ._helpers import pbs_for_set_no_merge
196197
197198 # Create a minimal fake GAPIC add attach it to a real client.
198- firestore_api = mock .Mock (spec = ["create_document" ])
199+ firestore_api = mock .Mock (spec = ["create_document" , "commit" ])
200+ write_result = mock .Mock (
201+ update_time = mock .sentinel .update_time , spec = ["update_time" ]
202+ )
203+ commit_response = mock .Mock (
204+ write_results = [write_result ],
205+ spec = ["write_results" , "commit_time" ],
206+ commit_time = mock .sentinel .commit_time ,
207+ )
208+ firestore_api .commit .return_value = commit_response
199209 create_doc_response = document_pb2 .Document ()
200210 firestore_api .create_document .return_value = create_doc_response
201211 client = _make_client ()
@@ -212,20 +222,19 @@ def test_add_auto_assigned(self):
212222 create_doc_response .update_time .FromDatetime (datetime .datetime .utcnow ())
213223 firestore_api .create_document .return_value = create_doc_response
214224
215- # Actually call add() on our collection.
216- document_data = {"been" : "here" }
225+ # Actually call add() on our collection; include a transform to make
226+ # sure transforms during adds work.
227+ document_data = {"been" : "here" , "now" : SERVER_TIMESTAMP }
217228 update_time , document_ref = collection .add (document_data )
218229
219230 # Verify the response and the mocks.
220- self .assertIs (update_time , create_doc_response .update_time )
231+ self .assertIs (update_time , mock . sentinel .update_time )
221232 self .assertIsInstance (document_ref , DocumentReference )
222233 self .assertIs (document_ref ._client , client )
223234 expected_path = collection ._path + (auto_assigned_id ,)
224235 self .assertEqual (document_ref ._path , expected_path )
225236
226- expected_document_pb = document_pb2 .Document (
227- fields = _helpers .encode_dict (document_data )
228- )
237+ expected_document_pb = document_pb2 .Document ()
229238 firestore_api .create_document .assert_called_once_with (
230239 parent_path ,
231240 collection_id = collection .id ,
@@ -234,6 +243,13 @@ def test_add_auto_assigned(self):
234243 mask = None ,
235244 metadata = client ._rpc_metadata ,
236245 )
246+ write_pbs = pbs_for_set_no_merge (document_ref ._document_path , document_data )
247+ firestore_api .commit .assert_called_once_with (
248+ client ._database_string ,
249+ write_pbs ,
250+ transaction = None ,
251+ metadata = client ._rpc_metadata ,
252+ )
237253
238254 @staticmethod
239255 def _write_pb_for_create (document_path , document_data ):
0 commit comments