@@ -56,58 +56,45 @@ fn test_split_address_book() {
5656
5757#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
5858async fn test_get_contacts ( ) -> Result < ( ) > {
59- let context = TestContext :: new ( ) . await ;
60-
61- assert ! ( context. get_all_self_addrs( ) . await ?. is_empty( ) ) ;
59+ let mut tcm = TestContextManager :: new ( ) ;
60+ let context = tcm. bob ( ) . await ;
61+ let alice = tcm. alice ( ) . await ;
62+ alice. set_config ( Config :: Displayname , Some ( "MyName" ) ) . await ?;
6263
63- // Bob is not in the contacts yet.
64- let contacts = Contact :: get_all ( & context. ctx , 0 , Some ( "bob " ) ) . await ?;
64+ // Alice is not in the contacts yet.
65+ let contacts = Contact :: get_all ( & context. ctx , 0 , Some ( "Alice " ) ) . await ?;
6566 assert_eq ! ( contacts. len( ) , 0 ) ;
6667
67- let ( id, _modified) = Contact :: add_or_lookup (
68- & context. ctx ,
69- "bob" ,
70- & ContactAddress :: new ( "[email protected] " ) ?
, 71- Origin :: IncomingReplyTo ,
72- )
73- . await ?;
68+ let id = context. add_or_lookup_contact_id ( & alice) . await ;
7469 assert_ne ! ( id, ContactId :: UNDEFINED ) ;
7570
76- let contact = Contact :: get_by_id ( & context. ctx , id) . await . unwrap ( ) ;
71+ let contact = Contact :: get_by_id ( & context, id) . await . unwrap ( ) ;
7772 assert_eq ! ( contact. get_name( ) , "" ) ;
78- assert_eq ! ( contact. get_authname( ) , "bob " ) ;
79- assert_eq ! ( contact. get_display_name( ) , "bob " ) ;
73+ assert_eq ! ( contact. get_authname( ) , "MyName " ) ;
74+ assert_eq ! ( contact. get_display_name( ) , "MyName " ) ;
8075
8176 // Search by name.
82- let contacts = Contact :: get_all ( & context. ctx , 0 , Some ( "bob " ) ) . await ?;
77+ let contacts = Contact :: get_all ( & context, 0 , Some ( "myname " ) ) . await ?;
8378 assert_eq ! ( contacts. len( ) , 1 ) ;
8479 assert_eq ! ( contacts. first( ) , Some ( & id) ) ;
8580
8681 // Search by address.
87- let contacts = Contact :: get_all ( & context. ctx , 0 , Some ( "user " ) ) . await ?;
82+ let contacts =
Contact :: get_all ( & context
, 0 , Some ( "[email protected] " ) ) . await ?
; 8883 assert_eq ! ( contacts. len( ) , 1 ) ;
8984 assert_eq ! ( contacts. first( ) , Some ( & id) ) ;
9085
91- let contacts = Contact :: get_all ( & context. ctx , 0 , Some ( "alice " ) ) . await ?;
86+ let contacts = Contact :: get_all ( & context, 0 , Some ( "Foobar " ) ) . await ?;
9287 assert_eq ! ( contacts. len( ) , 0 ) ;
9388
94- // Set Bob name to "someone" manually.
95- let ( contact_bob_id, modified) = Contact :: add_or_lookup (
96- & context. ctx ,
97- "someone" ,
98- & ContactAddress :: new ( "[email protected] " ) ?
, 99- Origin :: ManuallyCreated ,
100- )
101- . await ?;
102- assert_eq ! ( contact_bob_id, id) ;
103- assert_eq ! ( modified, Modifier :: Modified ) ;
89+ // Set Alice name to "someone" manually.
90+ id. set_name ( & context, "someone" ) . await ?;
10491 let contact = Contact :: get_by_id ( & context. ctx , id) . await . unwrap ( ) ;
10592 assert_eq ! ( contact. get_name( ) , "someone" ) ;
106- assert_eq ! ( contact. get_authname( ) , "bob " ) ;
93+ assert_eq ! ( contact. get_authname( ) , "MyName " ) ;
10794 assert_eq ! ( contact. get_display_name( ) , "someone" ) ;
10895
10996 // Not searchable by authname, because it is not displayed.
110- let contacts = Contact :: get_all ( & context. ctx , 0 , Some ( "bob " ) ) . await ?;
97+ let contacts = Contact :: get_all ( & context, 0 , Some ( "MyName " ) ) . await ?;
11198 assert_eq ! ( contacts. len( ) , 0 ) ;
11299
113100 // Search by display name (same as manually set name).
@@ -282,7 +269,7 @@ async fn test_contact_name_changes() -> Result<()> {
282269 assert_eq ! ( contact
. get_display_name
( ) , "[email protected] " ) ; 283270 assert_eq ! ( contact
. get_name_n_addr
( ) , "[email protected] " ) ; 284271 let contacts =
Contact :: get_all ( & t
, 0 , Some ( "[email protected] " ) ) . await ?
; 285- assert_eq ! ( contacts. len( ) , 1 ) ;
272+ assert_eq ! ( contacts. len( ) , 0 ) ;
286273
287274 // second message inits the name
288275 receive_imf (
@@ -308,9 +295,9 @@ async fn test_contact_name_changes() -> Result<()> {
308295 assert_eq ! ( contact. get_display_name( ) , "Flobbyfoo" ) ;
309296 assert_eq ! ( contact
. get_name_n_addr
( ) , "Flobbyfoo ([email protected] )" ) ; 310297 let contacts =
Contact :: get_all ( & t
, 0 , Some ( "[email protected] " ) ) . await ?
; 311- assert_eq ! ( contacts. len( ) , 1 ) ;
298+ assert_eq ! ( contacts. len( ) , 0 ) ;
312299 let contacts = Contact :: get_all ( & t, 0 , Some ( "flobbyfoo" ) ) . await ?;
313- assert_eq ! ( contacts. len( ) , 1 ) ;
300+ assert_eq ! ( contacts. len( ) , 0 ) ;
314301
315302 // third message changes the name
316303 receive_imf (
@@ -338,11 +325,11 @@ async fn test_contact_name_changes() -> Result<()> {
338325 assert_eq ! ( contact. get_display_name( ) , "Foo Flobby" ) ;
339326 assert_eq ! ( contact
. get_name_n_addr
( ) , "Foo Flobby ([email protected] )" ) ; 340327 let contacts =
Contact :: get_all ( & t
, 0 , Some ( "[email protected] " ) ) . await ?
; 341- assert_eq ! ( contacts. len( ) , 1 ) ;
328+ assert_eq ! ( contacts. len( ) , 0 ) ;
342329 let contacts = Contact :: get_all ( & t, 0 , Some ( "flobbyfoo" ) ) . await ?;
343330 assert_eq ! ( contacts. len( ) , 0 ) ;
344331 let contacts = Contact :: get_all ( & t, 0 , Some ( "Foo Flobby" ) ) . await ?;
345- assert_eq ! ( contacts. len( ) , 1 ) ;
332+ assert_eq ! ( contacts. len( ) , 0 ) ;
346333
347334 // change name manually
348335 let test_id =
Contact :: create ( & t
, "Falk" , "[email protected] " ) . await ?
; @@ -356,30 +343,23 @@ async fn test_contact_name_changes() -> Result<()> {
356343 assert_eq ! ( contact. get_display_name( ) , "Falk" ) ;
357344 assert_eq ! ( contact
. get_name_n_addr
( ) , "Falk ([email protected] )" ) ; 358345 let contacts =
Contact :: get_all ( & t
, 0 , Some ( "[email protected] " ) ) . await ?
; 359- assert_eq ! ( contacts. len( ) , 1 ) ;
346+ assert_eq ! ( contacts. len( ) , 0 ) ;
360347 let contacts = Contact :: get_all ( & t, 0 , Some ( "falk" ) ) . await ?;
361- assert_eq ! ( contacts. len( ) , 1 ) ;
348+ assert_eq ! ( contacts. len( ) , 0 ) ;
362349
363350 Ok ( ( ) )
364351}
365352
366353#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
367354async fn test_delete ( ) -> Result < ( ) > {
368355 let alice = TestContext :: new_alice ( ) . await ;
356+ let bob = TestContext :: new_bob ( ) . await ;
369357
370358 assert ! ( Contact :: delete( & alice, ContactId :: SELF ) . await . is_err( ) ) ;
371359
372360 // Create Bob contact
373- let ( contact_id, _) = Contact :: add_or_lookup (
374- & alice,
375- "Bob" ,
376- & ContactAddress :: new ( "[email protected] " ) ?
, 377- Origin :: ManuallyCreated ,
378- )
379- . await ?;
380- let chat = alice
381- . create_chat_with_contact ( "Bob" , "[email protected] " ) 382- . await ;
361+ let contact_id = alice. add_or_lookup_contact_id ( & bob) . await ;
362+ let chat = alice. create_chat ( & bob) . await ;
383363 assert_eq ! (
384364 Contact :: get_all
( & alice
, 0 , Some ( "[email protected] " ) ) 385365 . await ?
@@ -416,30 +396,32 @@ async fn test_delete() -> Result<()> {
416396
417397#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
418398async fn test_delete_and_recreate_contact ( ) -> Result < ( ) > {
419- let t = TestContext :: new_alice ( ) . await ;
399+ let mut tcm = TestContextManager :: new ( ) ;
400+ let t = tcm. alice ( ) . await ;
401+ let bob = tcm. bob ( ) . await ;
420402
421403 // test recreation after physical deletion
422- let contact_id1 =
Contact :: create ( & t , "Foo" , "[email protected] " ) . await ? ; 423- assert_eq ! ( Contact :: get_all
( & t
, 0 , Some ( "[email protected] " ) ) . await ?
. len
( ) , 1 ) ; 404+ let contact_id1 = t . add_or_lookup_contact_id ( & bob ) . await ;
405+ assert_eq ! ( Contact :: get_all
( & t
, 0 , Some ( "[email protected] " ) ) . await ?
. len
( ) , 1 ) ; 424406 Contact :: delete ( & t, contact_id1) . await ?;
425407 assert ! ( Contact :: get_by_id( & t, contact_id1) . await . is_err( ) ) ;
426- assert_eq ! ( Contact :: get_all
( & t
, 0 , Some ( "[email protected] " ) ) . await ?
. len
( ) , 0 ) ; 427- let contact_id2 =
Contact :: create ( & t , "Foo" , "[email protected] " ) . await ? ; 408+ assert_eq ! ( Contact :: get_all
( & t
, 0 , Some ( "[email protected] " ) ) . await ?
. len
( ) , 0 ) ; 409+ let contact_id2 = t . add_or_lookup_contact_id ( & bob ) . await ;
428410 assert_ne ! ( contact_id2, contact_id1) ;
429- assert_eq ! ( Contact :: get_all
( & t
, 0 , Some ( "[email protected] " ) ) . await ?
. len
( ) , 1 ) ; 411+ assert_eq ! ( Contact :: get_all
( & t
, 0 , Some ( "[email protected] " ) ) . await ?
. len
( ) , 1 ) ; 430412
431413 // test recreation after hiding
432- t
. create_chat_with_contact ( "Foo" , "[email protected] " ) . await ; 414+ t. create_chat ( & bob ) . await ;
433415 Contact :: delete ( & t, contact_id2) . await ?;
434416 let contact = Contact :: get_by_id ( & t, contact_id2) . await ?;
435417 assert_eq ! ( contact. origin, Origin :: Hidden ) ;
436- assert_eq ! ( Contact :: get_all
( & t
, 0 , Some ( "[email protected] " ) ) . await ?
. len
( ) , 0 ) ; 418+ assert_eq ! ( Contact :: get_all
( & t
, 0 , Some ( "[email protected] " ) ) . await ?
. len
( ) , 0 ) ; 437419
438- let contact_id3 =
Contact :: create ( & t , "Foo" , "[email protected] " ) . await ? ; 420+ let contact_id3 = t . add_or_lookup_contact_id ( & bob ) . await ;
439421 let contact = Contact :: get_by_id ( & t, contact_id3) . await ?;
440- assert_eq ! ( contact. origin, Origin :: ManuallyCreated ) ;
422+ assert_eq ! ( contact. origin, Origin :: CreateChat ) ;
441423 assert_eq ! ( contact_id3, contact_id2) ;
442- assert_eq ! ( Contact :: get_all
( & t
, 0 , Some ( "[email protected] " ) ) . await ?
. len
( ) , 1 ) ; 424+ assert_eq ! ( Contact :: get_all
( & t
, 0 , Some ( "[email protected] " ) ) . await ?
. len
( ) , 1 ) ; 443425
444426 Ok ( ( ) )
445427}
0 commit comments