Skip to content

Commit 9ca5385

Browse files
committed
feat: allow to set another transport as primary
1 parent 4b19988 commit 9ca5385

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

deltachat-rpc-client/tests/test_multitransport.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from deltachat_rpc_client.rpc import JsonRpcError
44

5+
56
def test_add_second_address(acfactory) -> None:
67
account = acfactory.new_configured_account()
78
assert len(account.list_transports()) == 1
@@ -22,3 +23,30 @@ def test_add_second_address(acfactory) -> None:
2223

2324
account.delete_transport(second_addr)
2425
assert len(account.list_transports()) == 2
26+
27+
28+
def test_change_address(acfactory) -> None:
29+
"""Test Alice configuring a second transport and setting it as a primary one."""
30+
alice, bob = acfactory.get_online_accounts(2)
31+
32+
alice_chat_bob = alice.create_chat(bob)
33+
alice_chat_bob.send_text("Hello!")
34+
35+
msg1 = bob.wait_for_incoming_msg().get_snapshot()
36+
sender_addr1 = msg1.sender.get_snapshot().address
37+
38+
alice.stop_io()
39+
old_alice_addr = alice.get_config("configured_addr")
40+
qr = acfactory.get_account_qr()
41+
alice.add_transport_from_qr(qr)
42+
new_alice_addr = alice.list_transports()[1]["addr"]
43+
alice.set_config("configured_addr", new_alice_addr)
44+
alice.start_io()
45+
46+
alice_chat_bob.send_text("Hello again!")
47+
48+
msg2 = bob.wait_for_incoming_msg().get_snapshot()
49+
sender_addr2 = msg2.sender.get_snapshot().address
50+
51+
assert msg1.sender == msg2.sender
52+
assert sender_addr1 != sender_addr2

src/config.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -811,20 +811,20 @@ impl Context {
811811
.await?;
812812
}
813813
Config::ConfiguredAddr => {
814-
if self.is_configured().await? {
815-
bail!("Cannot change ConfiguredAddr");
816-
}
817-
if let Some(addr) = value {
818-
info!(
819-
self,
820-
"Creating a pseudo configured account which will not be able to send or receive messages. Only meant for tests!"
821-
);
822-
ConfiguredLoginParam::from_json(&format!(
823-
r#"{{"addr":"{addr}","imap":[],"imap_user":"","imap_password":"","smtp":[],"smtp_user":"","smtp_password":"","certificate_checks":"Automatic","oauth2":false}}"#
824-
))?
825-
.save_to_transports_table(self, &EnteredLoginParam::default())
826-
.await?;
814+
if !self.is_configured().await? {
815+
if let Some(addr) = value {
816+
info!(
817+
self,
818+
"Creating a pseudo configured account which will not be able to send or receive messages. Only meant for tests!"
819+
);
820+
ConfiguredLoginParam::from_json(&format!(
821+
r#"{{"addr":"{addr}","imap":[],"imap_user":"","imap_password":"","smtp":[],"smtp_user":"","smtp_password":"","certificate_checks":"Automatic","oauth2":false}}"#
822+
))?
823+
.save_to_transports_table(self, &EnteredLoginParam::default())
824+
.await?;
825+
}
827826
}
827+
self.sql.set_raw_config(key.as_ref(), value).await?;
828828
}
829829
_ => {
830830
self.sql.set_raw_config(key.as_ref(), value).await?;

0 commit comments

Comments
 (0)