Skip to content

Commit

Permalink
Fix the response on non-text alias
Browse files Browse the repository at this point in the history
  • Loading branch information
necto committed Jan 15, 2025
1 parent 2c45e1a commit 25796fc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ async fn receive_alias_description(
dialogue.exit().await?;
}
None => {
bot.send_message(msg.chat.id, "Please, send me your full name.").await?;
bot.send_message(msg.chat.id, "Please, send me a text alias description.").await?;
}
}

Expand Down
30 changes: 30 additions & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,36 @@ async fn test_add_alias_cancel_on_description() {
assert!(!mock.matched());
}

#[tokio::test]
async fn test_add_alias_description_nontext() {
let mut server = Server::new_async().await;
let mock = server.mock("POST", "/1/mail_hostings/mock_mail_hosting_id/mailboxes/mock_name/aliases")
.match_header(reqwest::header::AUTHORIZATION, "Bearer 123mock_kmail_token")
.with_body(r#"
{
"result":"success",
"data":true
}
"#)
.create_async()
.await;
let (bot, probe_mail) = mock_bot(message_text("/add"), &server.url());
bot.dispatch_and_check_last_text("Enter the single-word name of the alias to add").await;
bot.update(message_text("alias"));
bot.dispatch_and_check_last_text("Enter the description of the alias").await;
bot.update(message_sticker("👍")); // Invalid response for description
bot.dispatch_and_check_last_text("Please, send me a text alias description.").await;
bot.update(message_sticker("🛌")); // Another invalid description
bot.dispatch_and_check_last_text("Please, send me a text alias description.").await;
bot.update(message_text("valid description"));
bot.dispatch_and_check_last_text("Probe email sent successfully.").await;
mock.assert(); // API request was sent
assert_eq!(probe_mail.lock().await.alias_email, "alias@mock_domain");
assert_eq!(probe_mail.lock().await.description, "valid description");
assert_eq!(probe_mail.lock().await.alias_name, "alias");
}

#[tokio::test]
async fn test_list_aliases_success() {
let mut server = Server::new_async().await;
Expand Down

0 comments on commit 25796fc

Please sign in to comment.