Skip to content

Commit 3310315

Browse files
committed
test: set chat name multiple times in a row
1 parent a7729e3 commit 3310315

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

src/chat/chat_tests.rs

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,20 +1389,52 @@ async fn test_pinned_after_new_msgs() -> Result<()> {
13891389

13901390
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
13911391
async fn test_set_chat_name() {
1392-
let t = TestContext::new().await;
1393-
let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo")
1392+
let mut tcm = TestContextManager::new();
1393+
let alice = &tcm.alice().await;
1394+
1395+
let chat_id = create_group_chat(alice, ProtectionStatus::Unprotected, "foo")
13941396
.await
13951397
.unwrap();
13961398
assert_eq!(
1397-
Chat::load_from_db(&t, chat_id).await.unwrap().get_name(),
1399+
Chat::load_from_db(alice, chat_id).await.unwrap().get_name(),
13981400
"foo"
13991401
);
14001402

1401-
set_chat_name(&t, chat_id, "bar").await.unwrap();
1403+
set_chat_name(alice, chat_id, "bar").await.unwrap();
14021404
assert_eq!(
1403-
Chat::load_from_db(&t, chat_id).await.unwrap().get_name(),
1405+
Chat::load_from_db(alice, chat_id).await.unwrap().get_name(),
14041406
"bar"
14051407
);
1408+
1409+
let bob = &tcm.bob().await;
1410+
let bob_contact_id = alice.add_or_lookup_contact_id(bob).await;
1411+
add_contact_to_chat(alice, chat_id, bob_contact_id)
1412+
.await
1413+
.unwrap();
1414+
1415+
let sent_msg = alice.send_text(chat_id, "Hi").await;
1416+
let received_msg = bob.recv_msg(&sent_msg).await;
1417+
let bob_chat_id = received_msg.chat_id;
1418+
1419+
for new_name in [
1420+
"Baz",
1421+
"xyzzy",
1422+
"Quux",
1423+
"another name",
1424+
"something different",
1425+
] {
1426+
set_chat_name(alice, chat_id, new_name).await.unwrap();
1427+
let sent_msg = alice.pop_sent_msg().await;
1428+
let received_msg = bob.recv_msg(&sent_msg).await;
1429+
assert_eq!(received_msg.chat_id, bob_chat_id);
1430+
assert_eq!(
1431+
Chat::load_from_db(bob, bob_chat_id)
1432+
.await
1433+
.unwrap()
1434+
.get_name(),
1435+
new_name
1436+
);
1437+
}
14061438
}
14071439

14081440
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]

0 commit comments

Comments
 (0)