use dialtone_common::rest::ap_objects::ap_object_reference::ApObjectReferenceType; use dialtone_sqlx::db::ap_object_reference::delete::delete_ap_object_reference; use dialtone_sqlx::db::ap_object_reference::fetch::fetch_ap_object_references; use dialtone_sqlx::db::ap_object_reference::insert::insert_ap_object_reference; use dialtone_test_util::create_actor::create_actor_tst_utl; use dialtone_test_util::create_ap_object::create_article_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_ap_object_reference_test() { test_pg::test_pg(move |pool| async move { let host_name = "example.net"; create_site_tst_utl(&pool, host_name).await; let created_actor = create_actor_tst_utl(&pool, "testymctestfase", host_name).await; let actor_id = created_actor.owned_actor.ap.id; let article = create_article_tst_utl( &pool, host_name, "

some content

", Some(&created_actor.owned_actor.ap.preferred_user_name), ) .await; let ap_object_id = article.id.unwrap(); // like the article let action = insert_ap_object_reference( &pool, &actor_id, &ap_object_id, &ApObjectReferenceType::Like, ) .await; test_action!(action); // flag the article let action = insert_ap_object_reference( &pool, &actor_id, &ap_object_id, &ApObjectReferenceType::Flag, ) .await; test_action!(action); // fetch references let action = fetch_ap_object_references(&pool, &actor_id, &ap_object_id).await; test_action!(action); let references = action.unwrap(); assert!(references.contains(&ApObjectReferenceType::Like)); assert!(references.contains(&ApObjectReferenceType::Flag)); // delete flag let action = delete_ap_object_reference( &pool, &actor_id, &ap_object_id, &ApObjectReferenceType::Flag, ) .await; test_action!(action); // fetch references and verify flag is gone let action = fetch_ap_object_references(&pool, &actor_id, &ap_object_id).await; test_action!(action); let references = action.unwrap(); assert!(references.contains(&ApObjectReferenceType::Like)); assert!(!references.contains(&ApObjectReferenceType::Flag)); }) .await; }