use dialtone_common::rest::actors::actor_reference::ActorReferenceType; use dialtone_sqlx::db::actor_reference::delete::delete_actor_reference; use dialtone_sqlx::db::actor_reference::fetch::fetch_actor_references; use dialtone_sqlx::db::actor_reference::insert::insert_actor_reference; use dialtone_test_util::create_actor::create_actor_tst_utl; use dialtone_test_util::create_site::create_site_tst_utl; use dialtone_test_util::{test_action, test_pg}; #[tokio::test] async fn insert_delete_fetch_actor_reference_test() { test_pg::test_pg(move |pool| async move { let host_name = "example.net"; create_site_tst_utl(&pool, host_name).await; let actor1 = create_actor_tst_utl(&pool, "test_actor_one", host_name).await; let actor1_id = actor1.owned_actor.ap.id; let actor2 = create_actor_tst_utl(&pool, "test_actor_two", host_name).await; let actor2_id = actor2.owned_actor.ap.id; // follow actor2 let action = insert_actor_reference( &pool, &actor1_id, &actor2_id, &ActorReferenceType::Following, ) .await; test_action!(action); // like actor2 let action = insert_actor_reference(&pool, &actor1_id, &actor2_id, &ActorReferenceType::Likes).await; test_action!(action); // fetch references let action = fetch_actor_references(&pool, &actor1_id, &actor2_id).await; test_action!(action); let references = action.unwrap(); assert!(references.contains(&ActorReferenceType::Following)); assert!(references.contains(&ActorReferenceType::Likes)); // delete likes let action = delete_actor_reference(&pool, &actor1_id, &actor2_id, &ActorReferenceType::Likes).await; test_action!(action); // fetch references and verify likes is gone let action = fetch_actor_references(&pool, &actor1_id, &actor2_id).await; test_action!(action); let references = action.unwrap(); assert!(references.contains(&ActorReferenceType::Following)); assert!(!references.contains(&ActorReferenceType::Likes)); }) .await; }