use dialtone_sqlx::control::actor::change_default::change_default_actor; use dialtone_sqlx::control::user::create_with_actor::create_user_with_default_actor; use dialtone_sqlx::db::actor::fetch_owned::fetch_default_owned_actor; use dialtone_test_util::create_actor::create_actor_for_user_tst_utl; use dialtone_test_util::{test_action, test_pg}; #[tokio::test] async fn change_default_actor_test() { test_pg::test_pg(move |pool| async move { // create a users with a default actors let action = create_user_with_default_actor(&pool, "test_user", "example.com", "secretpassword") .await; test_action!(action); let credentialed_actor = action.unwrap(); // verify the default actors let action = fetch_default_owned_actor(&pool, &credentialed_actor.creating_user_acct).await; test_action!(action); assert_eq!( action.unwrap().unwrap().ap.id, credentialed_actor.owned_actor.ap.id ); // create a new actors for the users let action = create_actor_for_user_tst_utl( &pool, "another_actor", "example.com", &credentialed_actor.creating_user_acct, false, ) .await; let new_actor = action.owned_actor; // verify the default actors did not change let action = fetch_default_owned_actor(&pool, &credentialed_actor.creating_user_acct).await; test_action!(action); assert_eq!( action.unwrap().unwrap().ap.id, credentialed_actor.owned_actor.ap.id ); // change the default actors let action = change_default_actor( &pool, &credentialed_actor.creating_user_acct, &new_actor.ap.id, ) .await; test_action!(action); // verify the default actors is now the new actors let action = fetch_default_owned_actor(&pool, &credentialed_actor.creating_user_acct).await; test_action!(action); assert_eq!(action.unwrap().unwrap().ap.id, new_actor.ap.id); }) .await; }