@@ -27,6 +27,36 @@ fn empty_delete() -> FindAndModify {
2727 FindAndModify :: with_delete ( ns, filter, None )
2828}
2929
30+ #[ test]
31+ fn build_with_delete_no_options ( ) {
32+ let ns = Namespace {
33+ db : "test_db" . to_string ( ) ,
34+ coll : "test_coll" . to_string ( ) ,
35+ } ;
36+ let filter = doc ! { "x" : { "$gt" : 1 } } ;
37+ let max_time = Duration :: from_millis ( 2u64 ) ;
38+
39+ let op = FindAndModify :: with_delete ( ns, filter. clone ( ) , None ) ;
40+
41+ let description = StreamDescription :: new_testing ( ) ;
42+ let mut cmd = op. build ( & description) . unwrap ( ) ;
43+
44+ assert_eq ! ( cmd. name. as_str( ) , "findAndModify" ) ;
45+ assert_eq ! ( cmd. target_db. as_str( ) , "test_db" ) ;
46+ assert_eq ! ( cmd. read_pref. as_ref( ) , None ) ;
47+
48+ let mut expected_body = doc ! {
49+ "findAndModify" : "test_coll" ,
50+ "query" : filter,
51+ "remove" : true
52+ } ;
53+
54+ bson_util:: sort_document ( & mut cmd. body ) ;
55+ bson_util:: sort_document ( & mut expected_body) ;
56+
57+ assert_eq ! ( cmd. body, expected_body) ;
58+ }
59+
3060#[ test]
3161fn build_with_delete ( ) {
3262 let ns = Namespace {
@@ -123,6 +153,36 @@ fn empty_replace() -> FindAndModify {
123153 FindAndModify :: with_replace ( ns, filter, replacement, None ) . unwrap ( )
124154}
125155
156+ #[ test]
157+ fn build_with_replace_no_options ( ) {
158+ let ns = Namespace {
159+ db : "test_db" . to_string ( ) ,
160+ coll : "test_coll" . to_string ( ) ,
161+ } ;
162+ let filter = doc ! { "x" : { "$gt" : 1 } } ;
163+ let replacement = doc ! { "x" : { "inc" : 1 } } ;
164+
165+ let op = FindAndModify :: with_replace ( ns, filter. clone ( ) , replacement. clone ( ) , None ) . unwrap ( ) ;
166+
167+ let description = StreamDescription :: new_testing ( ) ;
168+ let mut cmd = op. build ( & description) . unwrap ( ) ;
169+
170+ assert_eq ! ( cmd. name. as_str( ) , "findAndModify" ) ;
171+ assert_eq ! ( cmd. target_db. as_str( ) , "test_db" ) ;
172+ assert_eq ! ( cmd. read_pref. as_ref( ) , None ) ;
173+
174+ let mut expected_body = doc ! {
175+ "findAndModify" : "test_coll" ,
176+ "query" : filter,
177+ "update" : replacement,
178+ } ;
179+
180+ bson_util:: sort_document ( & mut cmd. body ) ;
181+ bson_util:: sort_document ( & mut expected_body) ;
182+
183+ assert_eq ! ( cmd. body, expected_body) ;
184+ }
185+
126186#[ test]
127187fn build_with_replace ( ) {
128188 let ns = Namespace {
@@ -224,6 +284,35 @@ fn empty_update() -> FindAndModify {
224284 FindAndModify :: with_update ( ns, filter, update, None ) . unwrap ( )
225285}
226286
287+ #[ test]
288+ fn build_with_update_no_options ( ) {
289+ let ns = Namespace {
290+ db : "test_db" . to_string ( ) ,
291+ coll : "test_coll" . to_string ( ) ,
292+ } ;
293+ let filter = doc ! { "x" : { "$gt" : 1 } } ;
294+ let update = UpdateModifications :: Document ( doc ! { "$x" : { "$inc" : 1 } } ) ;
295+ let op = FindAndModify :: with_update ( ns, filter. clone ( ) , update. clone ( ) , None ) . unwrap ( ) ;
296+
297+ let description = StreamDescription :: new_testing ( ) ;
298+ let mut cmd = op. build ( & description) . unwrap ( ) ;
299+
300+ assert_eq ! ( cmd. name. as_str( ) , "findAndModify" ) ;
301+ assert_eq ! ( cmd. target_db. as_str( ) , "test_db" ) ;
302+ assert_eq ! ( cmd. read_pref. as_ref( ) , None ) ;
303+
304+ let mut expected_body = doc ! {
305+ "findAndModify" : "test_coll" ,
306+ "query" : filter,
307+ "update" : update. to_bson( ) ,
308+ } ;
309+
310+ bson_util:: sort_document ( & mut cmd. body ) ;
311+ bson_util:: sort_document ( & mut expected_body) ;
312+
313+ assert_eq ! ( cmd. body, expected_body) ;
314+ }
315+
227316#[ test]
228317fn build_with_update ( ) {
229318 let ns = Namespace {
0 commit comments