vaegram 0.2.0

Telegram MTProto client library for users and bots
Documentation
use crate::Client;
use crate::errors::Result;
use crate::raw::functions;
use crate::types::User;

impl Client {
    /// Signs in with the code mailed by [`send_recovery_code`](Client::send_recovery_code).
    ///
    /// Removes the cloud password, since no new one is set. Saves the session and returns the signed-in [`User`].
    pub async fn recover_password(&self, recovery_code: &str) -> Result<User> {
        let request = functions::auth::RecoverPassword { code: recovery_code.into(), new_settings: None };
        let auth = self.invoke(&request).await?;
        self.authorized(auth).await
    }
}

#[cfg(test)]
mod tests {
    use crate::Client;
    use crate::raw::{Serializable, functions};

    #[tokio::test]
    async fn sends_only_the_code() {
        let (client, mut sent) = Client::recording();
        let _ = client.recover_password("12345").await;
        let expected = functions::auth::RecoverPassword { code: "12345".into(), new_settings: None };
        assert_eq!(sent.recv().await.unwrap(), expected.to_bytes());
    }
}