Skip to content

Commit 3df693a

Browse files
authored
add some more tests for edit messages cornercases (#6572)
extracted some tests from closed #6566
1 parent 1cabca3 commit 3df693a

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

src/chat/chat_tests.rs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3712,19 +3712,64 @@ async fn test_receive_edit_request_after_removal() -> Result<()> {
37123712
}
37133713

37143714
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
3715-
async fn test_cannot_edit_html() -> Result<()> {
3715+
async fn test_cannot_send_edit_request() -> Result<()> {
37163716
let mut tcm = TestContextManager::new();
37173717
let alice = &tcm.alice().await;
37183718
let bob = &tcm.bob().await;
3719-
let chat = alice.create_chat(bob).await;
3719+
let chat_id = alice
3720+
.create_group_with_members(ProtectionStatus::Unprotected, "My Group", &[bob])
3721+
.await;
3722+
3723+
// Alice can edit her message
3724+
let sent1 = alice.send_text(chat_id, "foo").await;
3725+
send_edit_request(alice, sent1.sender_msg_id, "bar".to_string()).await?;
3726+
3727+
// Bob cannot edit Alice's message
3728+
let msg = bob.recv_msg(&sent1).await;
3729+
assert!(send_edit_request(bob, msg.id, "bar".to_string())
3730+
.await
3731+
.is_err());
37203732

3733+
// HTML messages cannot be edited
37213734
let mut msg = Message::new_text("plain text".to_string());
37223735
msg.set_html(Some("<b>html</b> text".to_string()));
3723-
send_msg(alice, chat.id, &mut msg).await.unwrap();
3736+
let sent2 = alice.send_msg(chat_id, &mut msg).await;
37243737
assert!(msg.has_html());
3725-
assert!(send_edit_request(alice, msg.id, "foo".to_string())
3738+
assert!(
3739+
send_edit_request(alice, sent2.sender_msg_id, "foo".to_string())
3740+
.await
3741+
.is_err()
3742+
);
3743+
3744+
// Info messages cannot be edited
3745+
set_chat_name(alice, chat_id, "bar").await?;
3746+
let msg = alice.get_last_msg().await;
3747+
assert!(msg.is_info());
3748+
assert_eq!(msg.from_id, ContactId::SELF);
3749+
assert!(send_edit_request(alice, msg.id, "bar".to_string())
3750+
.await
3751+
.is_err());
3752+
3753+
// Videochat invitations cannot be edited
3754+
alice
3755+
.set_config(Config::WebrtcInstance, Some("https://foo.bar"))
3756+
.await?;
3757+
let msg_id = send_videochat_invitation(alice, chat_id).await?;
3758+
assert!(send_edit_request(alice, msg_id, "bar".to_string())
37263759
.await
37273760
.is_err());
37283761

3762+
// If not text was given initally, there is nothing to edit
3763+
// (this also avoids complexity in UI element changes; focus is typos and rewordings)
3764+
let mut msg = Message::new(Viewtype::File);
3765+
msg.make_vcard(alice, &[ContactId::SELF]).await?;
3766+
let sent3 = alice.send_msg(chat_id, &mut msg).await;
3767+
assert!(msg.text.is_empty());
3768+
assert!(
3769+
send_edit_request(alice, sent3.sender_msg_id, "bar".to_string())
3770+
.await
3771+
.is_err()
3772+
);
3773+
37293774
Ok(())
37303775
}

0 commit comments

Comments
 (0)