use dialtone_common::rest::users::web_user::UserStatus;
use dialtone_sqlx::control::user::authn::authn_user;
use dialtone_sqlx::control::user::change_auth::change_user_auth;
use dialtone_sqlx::db::user_principal::change_status::change_user_status;
use dialtone_sqlx::db::user_principal::create_user;
use dialtone_test_util::{test_action, test_pg};
use sqlx::types::chrono::Utc;
#[tokio::test]
async fn change_user_auth_test() {
test_pg::test_pg(move |pool| async move {
let acct = "test@example.com";
let password = "secretpassword";
let new_password = "new_password";
create_user(&pool, &acct, password).await.unwrap();
change_user_status(&pool, acct, &UserStatus::Active)
.await
.unwrap();
let action = authn_user(&pool, acct, password, "127.0.0.1", Utc::now())
.await
.unwrap();
assert!(action);
let action = change_user_auth(&pool, acct, new_password).await;
test_action!(action);
assert!(action.unwrap());
let action = authn_user(&pool, acct, new_password, "127.0.0.1", Utc::now())
.await
.unwrap();
assert!(action);
})
.await;
}
#[tokio::test]
async fn change_no_user_auth_test() {
test_pg::test_pg(move |pool| async move {
let acct = "test@example.com";
let password = "secretpassword";
let action = change_user_auth(&pool, acct, password).await;
test_action!(action);
assert!(!action.unwrap());
})
.await;
}