From a728272bba4973d5ec63470661b3622eba49a399 Mon Sep 17 00:00:00 2001 From: amir Date: Thu, 12 Dec 2024 03:03:12 -0500 Subject: [PATCH 1/3] add test service server --- tests/mod.rs | 1 + tests/utils.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/utils.rs diff --git a/tests/mod.rs b/tests/mod.rs index 82609503..352d5ca6 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -1,2 +1,3 @@ pub mod service; +pub mod utils; pub mod watcher; diff --git a/tests/utils.rs b/tests/utils.rs new file mode 100644 index 00000000..710fae41 --- /dev/null +++ b/tests/utils.rs @@ -0,0 +1,55 @@ +use anyhow::Result; +// Util backend server for testing +// Performs the same routine the main service server does +// OnceCell is used to ensure the server is only started once +use log::info; +use pubky_nexus::{redis_is_empty, reindex, routes, setup, Config}; +use tokio::{net::TcpListener, sync::OnceCell}; + +#[derive(Clone, Debug)] +pub struct TestServiceServer {} + +// static oncecell for the server +pub static TEST_SERVER: OnceCell = OnceCell::const_new(); + +impl TestServiceServer { + pub async fn get_test_server() -> TestServiceServer { + // Start the server if it hasn't been started + match TEST_SERVER.get() { + Some(server) => server.clone(), + None => { + let server = Self::start_server().await.unwrap(); + TEST_SERVER + .set(server.clone()) + .expect("Failed to set test server"); + server + } + } + } + + async fn start_server() -> Result { + tokio::spawn(async { + let config = Config::from_env(); + setup(&config).await; + + // Reindex if REINDEX is set to true or Redis is empty + let should_reindex = config.reindex || redis_is_empty().await.unwrap_or(false); + + if should_reindex { + info!("Starting reindexing process."); + reindex().await; + } + + // App router + let app = routes::routes(); + + // Start server + let listener = TcpListener::bind(&config.server_binding()).await.unwrap(); + info!("Listening on {:?}\n", listener.local_addr().unwrap()); + axum::serve(listener, app.into_make_service()) + .await + .unwrap(); + }); + Ok(TestServiceServer {}) + } +} From bd2bedf09c3bbb9fb333c8adc3092be63196def9 Mon Sep 17 00:00:00 2001 From: amir Date: Thu, 12 Dec 2024 03:03:50 -0500 Subject: [PATCH 2/3] use shared tokio runtime and test service server --- src/models/post/details.rs | 2 +- src/models/user/details.rs | 2 +- tests/service/all.rs | 8 ++--- tests/service/endpoints.rs | 6 ++-- tests/service/stream/post/author.rs | 2 +- tests/service/stream/post/author_replies.rs | 2 +- tests/service/stream/post/bookmarks.rs | 8 ++--- tests/service/stream/post/kind/all.rs | 6 ++-- tests/service/stream/post/kind/file.rs | 24 ++++++------- tests/service/stream/post/kind/image.rs | 24 ++++++------- tests/service/stream/post/kind/link.rs | 24 ++++++------- tests/service/stream/post/kind/long.rs | 24 ++++++------- tests/service/stream/post/kind/video.rs | 24 ++++++------- tests/service/stream/post/post_replies.rs | 12 +++---- tests/service/stream/post/posts.rs | 26 +++++++------- tests/service/stream/post/reach/engagement.rs | 28 +++++++-------- tests/service/stream/post/reach/timeline.rs | 32 ++++++++--------- tests/service/stream/post/tags.rs | 36 +++++++++---------- tests/service/stream/user/list.rs | 10 +++--- tests/service/stream/user/reach.rs | 2 +- tests/service/stream/user/score.rs | 8 ++--- tests/service/stream/user/search.rs | 2 +- tests/service/tags/hot.rs | 20 +++++------ tests/service/tags/mod.rs | 2 +- tests/service/tags/post.rs | 22 ++++++------ tests/service/tags/search.rs | 10 +++--- tests/service/tags/user.rs | 20 +++++------ tests/service/tags/wot.rs | 2 +- tests/service/user/reach.rs | 6 ++-- tests/service/user/search.rs | 6 ++-- tests/service/user/views.rs | 10 +++--- tests/watcher/bookmarks/del.rs | 2 +- tests/watcher/bookmarks/raw.rs | 2 +- tests/watcher/bookmarks/viewer.rs | 2 +- tests/watcher/files/create.rs | 2 +- tests/watcher/files/delete.rs | 2 +- tests/watcher/follows/del.rs | 2 +- tests/watcher/follows/del_friends.rs | 2 +- tests/watcher/follows/del_notification.rs | 2 +- tests/watcher/follows/del_sequential.rs | 2 +- tests/watcher/follows/put.rs | 2 +- tests/watcher/follows/put_friends.rs | 2 +- tests/watcher/follows/put_notification.rs | 2 +- tests/watcher/follows/put_sequential.rs | 2 +- tests/watcher/mentions/notification.rs | 2 +- tests/watcher/mentions/raw.rs | 2 +- tests/watcher/mutes/del.rs | 2 +- tests/watcher/mutes/put.rs | 2 +- tests/watcher/network/counts.rs | 2 +- tests/watcher/posts/attachments.rs | 2 +- .../posts/del_bookmarked_notification.rs | 2 +- tests/watcher/posts/del_reply_notification.rs | 2 +- .../posts/del_reply_parent_notification.rs | 2 +- .../watcher/posts/del_repost_notification.rs | 2 +- .../posts/del_reposted_notification.rs | 2 +- .../watcher/posts/del_tagged_notification.rs | 2 +- tests/watcher/posts/del_with_relations.rs | 2 +- tests/watcher/posts/del_without_relations.rs | 6 ++-- .../posts/edit_bookmarked_notification.rs | 2 +- .../posts/edit_reply_parent_notification.rs | 2 +- .../posts/edit_reposted_notification.rs | 2 +- .../watcher/posts/edit_tagged_notification.rs | 2 +- tests/watcher/posts/engagement.rs | 2 +- tests/watcher/posts/pioneer.rs | 2 +- tests/watcher/posts/raw.rs | 2 +- tests/watcher/posts/reply.rs | 2 +- tests/watcher/posts/reply_engagement.rs | 2 +- tests/watcher/posts/reply_notification.rs | 2 +- tests/watcher/posts/reply_repost.rs | 2 +- tests/watcher/posts/repost.rs | 2 +- tests/watcher/posts/repost_notification.rs | 2 +- tests/watcher/tags/post_del.rs | 2 +- tests/watcher/tags/post_muti_user.rs | 2 +- tests/watcher/tags/post_notification.rs | 2 +- tests/watcher/tags/post_put.rs | 2 +- tests/watcher/tags/user_notification.rs | 2 +- tests/watcher/tags/user_to_self_put.rs | 2 +- tests/watcher/tags/user_to_user_del.rs | 2 +- tests/watcher/tags/user_to_user_put.rs | 2 +- tests/watcher/users/del_with_relations.rs | 2 +- tests/watcher/users/del_without_relations.rs | 2 +- tests/watcher/users/raw.rs | 2 +- tests/watcher/utils.rs | 10 +++++- 83 files changed, 267 insertions(+), 259 deletions(-) diff --git a/src/models/post/details.rs b/src/models/post/details.rs index 977784ea..289fbd3b 100644 --- a/src/models/post/details.rs +++ b/src/models/post/details.rs @@ -186,7 +186,7 @@ mod tests { const REPLY_ID: &str = "2ZECXVXHZBE00"; const POST_ID: &str = "2ZECRNM66G900"; - #[tokio::test] + #[tokio_shared_rt::test(shared)] async fn test_post_details_get_from_graph() { // Open connections against ddbb let config = Config::from_env(); diff --git a/src/models/user/details.rs b/src/models/user/details.rs index 1b85864b..d3906085 100644 --- a/src/models/user/details.rs +++ b/src/models/user/details.rs @@ -126,7 +126,7 @@ mod tests { "not_existing_user_id_either", // Does not exist ]; - #[tokio::test] + #[tokio_shared_rt::test(shared)] async fn test_get_by_ids_from_redis() { let config = Config::from_env(); setup(&config).await; diff --git a/tests/service/all.rs b/tests/service/all.rs index 7b5fc7ab..7c8e6dcb 100644 --- a/tests/service/all.rs +++ b/tests/service/all.rs @@ -9,7 +9,7 @@ use serde_json::json; const HOST_URL: &str = "http://localhost:8080"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_static_serving() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; let test_file_path = "static"; @@ -48,7 +48,7 @@ async fn test_static_serving() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_file_details() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; let test_file_id = "2ZK2H8P2T5NG0"; @@ -74,7 +74,7 @@ async fn test_file_details() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_files_by_ids() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; let test_file_id = "2ZK2H8P2T5NG0"; @@ -105,7 +105,7 @@ async fn test_files_by_ids() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_get_post() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; diff --git a/tests/service/endpoints.rs b/tests/service/endpoints.rs index 261a85ce..1bf66c72 100644 --- a/tests/service/endpoints.rs +++ b/tests/service/endpoints.rs @@ -2,7 +2,7 @@ use anyhow::Result; const HOST_URL: &str = "http://localhost:8080"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_swagger_ui() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -14,7 +14,7 @@ async fn test_swagger_ui() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_openapi_schema() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -30,7 +30,7 @@ async fn test_openapi_schema() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_info_endpoint() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; diff --git a/tests/service/stream/post/author.rs b/tests/service/stream/post/author.rs index 97fa4a0c..af076287 100644 --- a/tests/service/stream/post/author.rs +++ b/tests/service/stream/post/author.rs @@ -2,7 +2,7 @@ use super::{ROOT_PATH, USER_ID}; use crate::service::utils::make_request; use anyhow::Result; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_user_posts() -> Result<()> { let path = format!( "{ROOT_PATH}?author_id={}&source=author&sorting=timeline", diff --git a/tests/service/stream/post/author_replies.rs b/tests/service/stream/post/author_replies.rs index f31aa978..3f7e8792 100644 --- a/tests/service/stream/post/author_replies.rs +++ b/tests/service/stream/post/author_replies.rs @@ -2,7 +2,7 @@ use super::ROOT_PATH; use crate::service::utils::make_request; use anyhow::Result; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_user_replies() -> Result<()> { let author_id = "pxnu33x7jtpx9ar1ytsi4yxbp6a5o36gwhffs8zoxmbuptici1jy"; let path = format!( diff --git a/tests/service/stream/post/bookmarks.rs b/tests/service/stream/post/bookmarks.rs index 8089e465..42dd72d2 100644 --- a/tests/service/stream/post/bookmarks.rs +++ b/tests/service/stream/post/bookmarks.rs @@ -6,7 +6,7 @@ use anyhow::Result; // User with most bookmarks const BOOKMARKER_ID: &str = "o1gg96ewuojmopcjbz8895478wdtxtzzuxnfjjz8o8e77csa1ngo"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_bookmarked_posts() -> Result<()> { let observer_id = BOOKMARKER_ID; let path = format!("{ROOT_PATH}?observer_id={}&source=bookmarks", observer_id); @@ -40,7 +40,7 @@ pub const POST_TK: &str = "2ZAX1DBDD5YG0"; pub const START_TIMELINE: &str = "1724134149050"; pub const END_TIMELINE: &str = "1724134141150"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_user_bookmarks_by_timeline_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?observer_id={BOOKMARKER_ID}&source=bookmarks&start={START_TIMELINE}"); @@ -54,7 +54,7 @@ async fn test_stream_user_bookmarks_by_timeline_with_start() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_user_bookmarks_by_timeline_with_start_and_end() -> Result<()> { let path = format!( "{ROOT_PATH}?observer_id={BOOKMARKER_ID}&source=bookmarks&start={START_TIMELINE}&end={END_TIMELINE}" @@ -69,7 +69,7 @@ async fn test_stream_user_bookmarks_by_timeline_with_start_and_end() -> Result<( Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_user_bookmarks_by_timeline_with_skip_end() -> Result<()> { let path = format!( "{ROOT_PATH}?observer_id={BOOKMARKER_ID}&source=bookmarks&limit=5&end={END_TIMELINE}" diff --git a/tests/service/stream/post/kind/all.rs b/tests/service/stream/post/kind/all.rs index e0f833aa..d5c9cc29 100644 --- a/tests/service/stream/post/kind/all.rs +++ b/tests/service/stream/post/kind/all.rs @@ -25,7 +25,7 @@ pub const END_TIMELINE: &str = "1980477299303"; pub const PUBKY_TAG: &str = "pubky"; pub const FK_TAG: &str = "4k"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind() -> Result<()> { let path = format!("{ROOT_PATH}?author_id={BOGOTA}&source=author"); @@ -38,7 +38,7 @@ async fn test_stream_post_kind() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_with_start_and_end() -> Result<()> { let path = format!( "{ROOT_PATH}?author_id={BOGOTA}&source=author&start={START_TIMELINE}&end={END_TIMELINE}" @@ -51,7 +51,7 @@ async fn test_stream_post_kind_with_start_and_end() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_with_tag() -> Result<()> { let path = format!("{ROOT_PATH}?author_id={BOGOTA}&source=author&tags={PUBKY_TAG}"); diff --git a/tests/service/stream/post/kind/file.rs b/tests/service/stream/post/kind/file.rs index 6426f6c5..cca4843b 100644 --- a/tests/service/stream/post/kind/file.rs +++ b/tests/service/stream/post/kind/file.rs @@ -19,7 +19,7 @@ const POST_F8: &str = "GJMW1TGL5BKG1"; pub const START_TIMELINE: &str = "1980477299345"; pub const END_TIMELINE: &str = "1980477299309"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_file_post_kind() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}"); @@ -32,7 +32,7 @@ async fn test_stream_file_post_kind() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_file_post_kind_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}"); @@ -43,7 +43,7 @@ async fn test_stream_file_post_kind_with_start() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_file_post_kind_with_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&end={START_TIMELINE}"); @@ -54,7 +54,7 @@ async fn test_stream_file_post_kind_with_end() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_file_post_kind_with_start_and_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}&end={END_TIMELINE}"); @@ -65,7 +65,7 @@ async fn test_stream_file_post_kind_with_start_and_end() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_file_post_kind_with_author() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author"); @@ -76,7 +76,7 @@ async fn test_stream_file_post_kind_with_author() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_file_post_kind_with_author_skip_and_limit() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author&skip=1&limit=1"); @@ -89,7 +89,7 @@ async fn test_stream_file_post_kind_with_author_skip_and_limit() -> Result<()> { // ##### REACH: FOLLOWERS #### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_followers() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}"); @@ -102,7 +102,7 @@ async fn test_stream_post_kind_followers() -> Result<()> { const REACH_START_TIMELINE: &str = "1980477299360"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_followers_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}"); @@ -115,7 +115,7 @@ async fn test_stream_post_kind_followers_with_start() -> Result<()> { // ##### REACH: FOLLOWING #### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_following() -> Result<()> { let path = format!("{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}"); @@ -126,7 +126,7 @@ async fn test_stream_post_kind_following() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_following_with_start() -> Result<()> { let path = format!( "{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}&start=1980477299325" @@ -141,7 +141,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> { // ##### REACH: FRIENDS #### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_friends() -> Result<()> { let path = format!("{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}"); @@ -152,7 +152,7 @@ async fn test_stream_post_kind_friends() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_friends_with_start() -> Result<()> { let path = format!( "{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}" diff --git a/tests/service/stream/post/kind/image.rs b/tests/service/stream/post/kind/image.rs index dd6448f2..5439b7e0 100644 --- a/tests/service/stream/post/kind/image.rs +++ b/tests/service/stream/post/kind/image.rs @@ -19,7 +19,7 @@ const POST_I8: &str = "5YCW1TGL5BKG1"; pub const START_TIMELINE: &str = "1820477299345"; pub const END_TIMELINE: &str = "1820477299308"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_image_post_kind() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}"); @@ -32,7 +32,7 @@ async fn test_stream_image_post_kind() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_image_post_kind_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}"); @@ -43,7 +43,7 @@ async fn test_stream_image_post_kind_with_start() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_image_post_kind_with_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&end={START_TIMELINE}"); @@ -54,7 +54,7 @@ async fn test_stream_image_post_kind_with_end() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_image_post_kind_with_start_and_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}&end={END_TIMELINE}"); @@ -65,7 +65,7 @@ async fn test_stream_image_post_kind_with_start_and_end() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_image_post_kind_with_author() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author"); @@ -76,7 +76,7 @@ async fn test_stream_image_post_kind_with_author() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_image_post_kind_with_author_skip_and_limit() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author&skip=1&limit=1"); @@ -89,7 +89,7 @@ async fn test_stream_image_post_kind_with_author_skip_and_limit() -> Result<()> // ##### REACH: FOLLOWING #### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_followers() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}"); @@ -102,7 +102,7 @@ async fn test_stream_post_kind_followers() -> Result<()> { const REACH_START_TIMELINE: &str = "1820477299355"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_followers_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}"); @@ -115,7 +115,7 @@ async fn test_stream_post_kind_followers_with_start() -> Result<()> { // ##### REACH: FOLLOWING #### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_following() -> Result<()> { let path = format!("{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}"); @@ -126,7 +126,7 @@ async fn test_stream_post_kind_following() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_following_with_start() -> Result<()> { let path = format!( "{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}&start=1820477299325" @@ -141,7 +141,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> { // ##### REACH: FRIENDS #### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_friends() -> Result<()> { let path = format!("{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}"); @@ -152,7 +152,7 @@ async fn test_stream_post_kind_friends() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_friends_with_start() -> Result<()> { let path = format!( "{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}" diff --git a/tests/service/stream/post/kind/link.rs b/tests/service/stream/post/kind/link.rs index 1908f74b..53ac5277 100644 --- a/tests/service/stream/post/kind/link.rs +++ b/tests/service/stream/post/kind/link.rs @@ -23,7 +23,7 @@ const POST_PK: &str = "2ZFWAA83B97G0"; pub const START_TIMELINE: &str = "1980477299350"; pub const END_TIMELINE: &str = "1980477299312"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_link_post_kind() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}"); @@ -37,7 +37,7 @@ async fn test_stream_link_post_kind() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_link_post_kind_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}"); @@ -51,7 +51,7 @@ async fn test_stream_link_post_kind_with_start() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_link_post_kind_with_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&end={START_TIMELINE}"); @@ -62,7 +62,7 @@ async fn test_stream_link_post_kind_with_end() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_link_post_kind_with_start_and_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}&end={END_TIMELINE}"); @@ -73,7 +73,7 @@ async fn test_stream_link_post_kind_with_start_and_end() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_link_post_kind_with_author() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author"); @@ -84,7 +84,7 @@ async fn test_stream_link_post_kind_with_author() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_link_post_kind_with_author_skip_and_limit() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author&skip=1&limit=1"); @@ -97,7 +97,7 @@ async fn test_stream_link_post_kind_with_author_skip_and_limit() -> Result<()> { // ##### REACH: FOLLOWERS #### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_followers() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}"); @@ -110,7 +110,7 @@ async fn test_stream_post_kind_followers() -> Result<()> { const REACH_START_TIMELINE: &str = "1980477299360"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_followers_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}"); @@ -123,7 +123,7 @@ async fn test_stream_post_kind_followers_with_start() -> Result<()> { // ##### REACH: FOLLOWING #### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_following() -> Result<()> { let path = format!("{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}"); @@ -134,7 +134,7 @@ async fn test_stream_post_kind_following() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_following_with_start() -> Result<()> { let path = format!( "{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}&start=1980477299330" @@ -149,7 +149,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> { // ##### REACH: FRIENDS #### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_friends() -> Result<()> { let path = format!("{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}"); @@ -160,7 +160,7 @@ async fn test_stream_post_kind_friends() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_friends_with_start() -> Result<()> { let path = format!( "{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}" diff --git a/tests/service/stream/post/kind/long.rs b/tests/service/stream/post/kind/long.rs index 743d9ab3..8b50adb1 100644 --- a/tests/service/stream/post/kind/long.rs +++ b/tests/service/stream/post/kind/long.rs @@ -19,7 +19,7 @@ const POST_L8: &str = "4ZCW1TGL5BKG1"; pub const START_TIMELINE: &str = "1819477230345"; pub const END_TIMELINE: &str = "1819477230308"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_long_post_kind() -> Result<()> { let path = format!("{ROOT_PATH}?kind=long"); @@ -32,7 +32,7 @@ async fn test_stream_long_post_kind() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_long_post_kind_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?kind=long&start={START_TIMELINE}"); @@ -43,7 +43,7 @@ async fn test_stream_long_post_kind_with_start() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_long_post_kind_with_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind=long&end={START_TIMELINE}"); @@ -54,7 +54,7 @@ async fn test_stream_long_post_kind_with_end() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_long_post_kind_with_start_and_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind=long&start={START_TIMELINE}&end={END_TIMELINE}"); @@ -65,7 +65,7 @@ async fn test_stream_long_post_kind_with_start_and_end() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_long_post_kind_with_author() -> Result<()> { let path = format!("{ROOT_PATH}?kind=long&author_id={BOGOTA}&source=author"); @@ -76,7 +76,7 @@ async fn test_stream_long_post_kind_with_author() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_long_post_kind_with_author_skip_and_limit() -> Result<()> { let path = format!("{ROOT_PATH}?kind=long&author_id={BOGOTA}&source=author&skip=1&limit=1"); @@ -89,7 +89,7 @@ async fn test_stream_long_post_kind_with_author_skip_and_limit() -> Result<()> { // ##### REACH: FOLLOWERS #### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_followers() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}"); @@ -102,7 +102,7 @@ async fn test_stream_post_kind_followers() -> Result<()> { const REACH_START_TIMELINE: &str = "1819477230355"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_followers_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}"); @@ -115,7 +115,7 @@ async fn test_stream_post_kind_followers_with_start() -> Result<()> { // ##### REACH: FOLLOWING #### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_following() -> Result<()> { let path = format!("{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}"); @@ -126,7 +126,7 @@ async fn test_stream_post_kind_following() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_following_with_start() -> Result<()> { let path = format!( "{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}&start=1819477230325" @@ -141,7 +141,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> { // ##### REACH: FRIENDS #### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_friends() -> Result<()> { let path = format!("{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}"); @@ -152,7 +152,7 @@ async fn test_stream_post_kind_friends() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_friends_with_start() -> Result<()> { let path = format!( "{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}" diff --git a/tests/service/stream/post/kind/video.rs b/tests/service/stream/post/kind/video.rs index ccbf7ec6..0d3a75bc 100644 --- a/tests/service/stream/post/kind/video.rs +++ b/tests/service/stream/post/kind/video.rs @@ -19,7 +19,7 @@ const POST_V8: &str = "MLOW1TGL5BKH1"; pub const START_TIMELINE: &str = "1980477299345"; pub const END_TIMELINE: &str = "1980477299308"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_video_post_kind() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}"); @@ -32,7 +32,7 @@ async fn test_stream_video_post_kind() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_video_post_kind_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}"); @@ -43,7 +43,7 @@ async fn test_stream_video_post_kind_with_start() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_video_post_kind_with_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&end={START_TIMELINE}"); @@ -54,7 +54,7 @@ async fn test_stream_video_post_kind_with_end() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_video_post_kind_with_start_and_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}&end={END_TIMELINE}"); @@ -65,7 +65,7 @@ async fn test_stream_video_post_kind_with_start_and_end() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_video_post_kind_with_author() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author"); @@ -76,7 +76,7 @@ async fn test_stream_video_post_kind_with_author() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_video_post_kind_with_author_skip_and_limit() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author&skip=1&limit=1"); @@ -89,7 +89,7 @@ async fn test_stream_video_post_kind_with_author_skip_and_limit() -> Result<()> // ##### REACH: FOLLOWERS #### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_followers() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}"); @@ -102,7 +102,7 @@ async fn test_stream_post_kind_followers() -> Result<()> { const REACH_START_TIMELINE: &str = "1980477299355"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_followers_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}"); @@ -115,7 +115,7 @@ async fn test_stream_post_kind_followers_with_start() -> Result<()> { // ##### REACH: FOLLOWING #### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_following() -> Result<()> { let path = format!("{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}"); @@ -126,7 +126,7 @@ async fn test_stream_post_kind_following() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_following_with_start() -> Result<()> { let path = format!( "{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}&start=1980477299325" @@ -141,7 +141,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> { // ##### REACH: FRIENDS #### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_friends() -> Result<()> { let path = format!("{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}"); @@ -152,7 +152,7 @@ async fn test_stream_post_kind_friends() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_post_kind_friends_with_start() -> Result<()> { let path = format!( "{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}" diff --git a/tests/service/stream/post/post_replies.rs b/tests/service/stream/post/post_replies.rs index 94461553..95066329 100644 --- a/tests/service/stream/post/post_replies.rs +++ b/tests/service/stream/post/post_replies.rs @@ -15,7 +15,7 @@ const CHILD_4_POST_ID: &str = "5F8YQJ1L2D3E"; const CHILD_5_POST_ID: &str = "6G3ZB9X0H7M4"; const CHILD_6_POST_ID: &str = "7N8K0Y1C3T2Q"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_replies() -> Result<()> { let path = format!( "{ROOT_PATH}?source=post_replies&author_id={}&post_id={}", @@ -49,7 +49,7 @@ async fn test_stream_posts_replies() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_replies_with_limit() -> Result<()> { let path = format!( "{ROOT_PATH}?source=post_replies&author_id={}&post_id={}&limit=3", @@ -76,7 +76,7 @@ async fn test_stream_posts_replies_with_limit() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_replies_with_start_query() -> Result<()> { let path = format!( "{ROOT_PATH}?source=post_replies&author_id={}&post_id={}&start=1719477230025", @@ -103,7 +103,7 @@ async fn test_stream_posts_replies_with_start_query() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_replies_with_end_query() -> Result<()> { let path = format!( "{ROOT_PATH}?source=post_replies&author_id={}&post_id={}&end=1719477230060", @@ -130,7 +130,7 @@ async fn test_stream_posts_replies_with_end_query() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_replies_with_start_and_end_query() -> Result<()> { let path = format!( "{ROOT_PATH}?source=post_replies&author_id={}&post_id={}&start=1719477230150&end=1719477230017", @@ -162,7 +162,7 @@ async fn test_stream_posts_replies_with_start_and_end_query() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_replies_with_start_and_end_also_limit_query() -> Result<()> { let path = format!( "{ROOT_PATH}?source=post_replies&author_id={}&post_id={}&start=1719477230150&end=1719477230017&limit=3", diff --git a/tests/service/stream/post/posts.rs b/tests/service/stream/post/posts.rs index 907a62c0..61d0fef6 100644 --- a/tests/service/stream/post/posts.rs +++ b/tests/service/stream/post/posts.rs @@ -21,7 +21,7 @@ pub const POST_TJ: &str = "2ZHT82S7G2M00"; pub const START_TIMELINE: &str = "1722261385301"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_global_timeline() -> Result<()> { let path = format!("{ROOT_PATH}?sorting=timeline"); let body = make_request(&path).await?; @@ -42,7 +42,7 @@ async fn test_stream_posts_global_timeline() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_global_timeline_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?sorting=timeline&start={START_TIMELINE}"); @@ -56,7 +56,7 @@ async fn test_stream_posts_global_timeline_with_start() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_global_timeline_with_start_and_limit() -> Result<()> { let path = format!("{ROOT_PATH}?sorting=timeline&start={START_TIMELINE}&limit=5"); @@ -68,7 +68,7 @@ async fn test_stream_posts_global_timeline_with_start_and_limit() -> Result<()> Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_global_timeline_with_start_and_limit_and_skip() -> Result<()> { let path = format!("{ROOT_PATH}?sorting=timeline&start={START_TIMELINE}&skip=3&limit=5"); @@ -80,7 +80,7 @@ async fn test_stream_posts_global_timeline_with_start_and_limit_and_skip() -> Re Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_global_total_engagement() -> Result<()> { let path = format!("{ROOT_PATH}?sorting=total_engagement"); let body = make_request(&path).await?; @@ -131,7 +131,7 @@ pub const POST_00: &str = "2Z1P68V42JJ00"; pub const ENGAGEMENT_SCORE: &str = "10"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_global_total_engagement_with_start_score() -> Result<()> { let path = format!( "{}?sorting=total_engagement&start={}", @@ -148,7 +148,7 @@ async fn test_stream_posts_global_total_engagement_with_start_score() -> Result< Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_global_total_engagement_with_start_end_score() -> Result<()> { let path = format!( "{}?sorting=total_engagement&start={}&end={}", @@ -163,7 +163,7 @@ async fn test_stream_posts_global_total_engagement_with_start_end_score() -> Res Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_global_total_engagement_with_end_score() -> Result<()> { let path = format!( "{}?sorting=total_engagement&end={}", @@ -178,7 +178,7 @@ async fn test_stream_posts_global_total_engagement_with_end_score() -> Result<() Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_tag_search_by_engagement() -> Result<()> { let post_order = vec![POST_A, POST_H, POST_C, POST_B]; let path = format!( @@ -198,7 +198,7 @@ async fn test_post_tag_search_by_engagement() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_tag_search_by_engagement_with_skip() -> Result<()> { let post_order = vec![POST_G, POST_F]; let path = format!( @@ -220,7 +220,7 @@ async fn test_post_tag_search_by_engagement_with_skip() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_tag_search_by_engagement_with_skip_and_limit() -> Result<()> { let post_order = vec![POST_H]; let path = format!( @@ -242,7 +242,7 @@ async fn test_post_tag_search_by_engagement_with_skip_and_limit() -> Result<()> Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_combined_parameters() -> Result<()> { // This one should hit the graph let observer_id = USER_ID; @@ -274,7 +274,7 @@ async fn test_stream_combined_parameters() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_invalid_sorting() -> Result<()> { // Invalid sorting option should fail let endpoint = "/v0/stream/posts?sorting=invalid"; diff --git a/tests/service/stream/post/reach/engagement.rs b/tests/service/stream/post/reach/engagement.rs index aeef2f88..e96155b4 100644 --- a/tests/service/stream/post/reach/engagement.rs +++ b/tests/service/stream/post/reach/engagement.rs @@ -15,7 +15,7 @@ pub const POST_ED_ING: &str = "C3L7W0F9Q4K8"; const START_SCORE: &str = "5"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_engagement_reach_following_with_tag() -> Result<()> { test_reach_filter_with_posts( AMSTERDAM, @@ -31,7 +31,7 @@ async fn test_stream_posts_by_engagement_reach_following_with_tag() -> Result<() .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_engagement_reach_following_with_tag_and_start() -> Result<()> { test_reach_filter_with_posts( AMSTERDAM, @@ -47,7 +47,7 @@ async fn test_stream_posts_by_engagement_reach_following_with_tag_and_start() -> .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_engagement_reach_following_with_tag_start_and_skip() -> Result<()> { test_reach_filter_with_posts( AMSTERDAM, @@ -63,7 +63,7 @@ async fn test_stream_posts_by_engagement_reach_following_with_tag_start_and_skip .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_engagement_reach_following_with_tag_start_skip_and_limit( ) -> Result<()> { test_reach_filter_with_posts( @@ -82,7 +82,7 @@ async fn test_stream_posts_by_engagement_reach_following_with_tag_start_skip_and .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_engagement_reach_following_with_tag_and_end() -> Result<()> { test_reach_filter_with_posts( AMSTERDAM, @@ -98,7 +98,7 @@ async fn test_stream_posts_by_engagement_reach_following_with_tag_and_end() -> R .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_engagement_reach_following_with_tag_start_and_end() -> Result<()> { test_reach_filter_with_posts( AMSTERDAM, @@ -122,7 +122,7 @@ pub const POST_EB_ER: &str = "3NFG9K0L5QH4"; pub const POST_EC_ER: &str = "M4X1P9L2J6K8"; pub const POST_ED_ER: &str = "L3W5N0F8Q2J7"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_engagement_reach_followers_with_tag() -> Result<()> { test_reach_filter_with_posts( BOGOTA, @@ -138,7 +138,7 @@ async fn test_stream_posts_by_engagement_reach_followers_with_tag() -> Result<() .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_engagement_reach_followers_with_tag_and_start() -> Result<()> { test_reach_filter_with_posts( BOGOTA, @@ -154,7 +154,7 @@ async fn test_stream_posts_by_engagement_reach_followers_with_tag_and_start() -> .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_engagement_reach_followers_with_tag_start_and_skip() -> Result<()> { test_reach_filter_with_posts( BOGOTA, @@ -170,7 +170,7 @@ async fn test_stream_posts_by_engagement_reach_followers_with_tag_start_and_skip .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_engagement_reach_followers_with_tag_start_skip_and_limit( ) -> Result<()> { test_reach_filter_with_posts( @@ -189,7 +189,7 @@ async fn test_stream_posts_by_engagement_reach_followers_with_tag_start_skip_and .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_engagement_reach_followers_with_tag_and_end() -> Result<()> { test_reach_filter_with_posts( BOGOTA, @@ -205,7 +205,7 @@ async fn test_stream_posts_by_engagement_reach_followers_with_tag_and_end() -> R .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_engagement_reach_followers_with_tag_start_and_end() -> Result<()> { test_reach_filter_with_posts( BOGOTA, @@ -229,7 +229,7 @@ const EIXAMPLE: &str = "8attbeo9ftu5nztqkcfw3gydksehr7jbspgfi64u4h8eo5e7dbiy"; pub const POST_EA_FR: &str = "M4X1P9L2J6K8"; pub const POST_EB_FR: &str = "L3W5N0F8Q2J7"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_engagement_reach_friends_with_tag() -> Result<()> { test_reach_filter_with_posts( EIXAMPLE, @@ -245,7 +245,7 @@ async fn test_stream_posts_by_engagement_reach_friends_with_tag() -> Result<()> .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_not_found_posts_by_engagement_reach_friends_with_tag() -> Result<()> { let path = format!("{ROOT_PATH}?sorting=total_engagement&tags=opensource&source=friends&observer_id={EIXAMPLE}&skip=2"); make_wrong_request(&path, Some(404)).await?; diff --git a/tests/service/stream/post/reach/timeline.rs b/tests/service/stream/post/reach/timeline.rs index bcdbefbc..dc3ece8b 100644 --- a/tests/service/stream/post/reach/timeline.rs +++ b/tests/service/stream/post/reach/timeline.rs @@ -3,7 +3,7 @@ use crate::service::stream::post::{AMSTERDAM, BOGOTA, ROOT_PATH, TAG_LABEL_2, US use crate::service::utils::{make_request, make_wrong_request}; use anyhow::Result; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_following() -> Result<()> { let path = format!("{ROOT_PATH}?observer_id={}&source=following", USER_ID); let body = make_request(&path).await?; @@ -20,7 +20,7 @@ async fn test_stream_posts_following() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_followers() -> Result<()> { let path = format!("{ROOT_PATH}?observer_id={}&source=followers", USER_ID); let body = make_request(&path).await?; @@ -50,7 +50,7 @@ pub const POST_TD_ING: &str = "N7Q2F5W8J0L3"; const START_TIMELINE: &str = "1729308318220"; const END_TIMELINE: &str = "1693824190130"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_timeline_reach_following_with_tag() -> Result<()> { test_reach_filter_with_posts( AMSTERDAM, @@ -66,7 +66,7 @@ async fn test_stream_posts_by_timeline_reach_following_with_tag() -> Result<()> .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_timeline_reach_following_with_tag_and_start() -> Result<()> { test_reach_filter_with_posts( AMSTERDAM, @@ -82,7 +82,7 @@ async fn test_stream_posts_by_timeline_reach_following_with_tag_and_start() -> R .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_timeline_reach_following_with_tag_start_and_skip() -> Result<()> { test_reach_filter_with_posts( AMSTERDAM, @@ -98,7 +98,7 @@ async fn test_stream_posts_by_timeline_reach_following_with_tag_start_and_skip() .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_timeline_reach_following_with_tag_start_skip_and_limit() -> Result<()> { test_reach_filter_with_posts( @@ -115,7 +115,7 @@ async fn test_stream_posts_by_timeline_reach_following_with_tag_start_skip_and_l .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_timeline_reach_following_with_tag_and_end() -> Result<()> { test_reach_filter_with_posts( AMSTERDAM, @@ -131,7 +131,7 @@ async fn test_stream_posts_by_timeline_reach_following_with_tag_and_end() -> Res .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_timeline_reach_following_with_tag_start_and_end() -> Result<()> { test_reach_filter_with_posts( AMSTERDAM, @@ -158,7 +158,7 @@ pub const POST_TD_ER: &str = "M4X1P9L2J6K8"; const START_TIMELINE_ER: &str = "1709308315950"; const END_TIMELINE_ER: &str = "1693823567900"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_timeline_reach_followers_with_tag() -> Result<()> { test_reach_filter_with_posts( BOGOTA, @@ -174,7 +174,7 @@ async fn test_stream_posts_by_timeline_reach_followers_with_tag() -> Result<()> .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_timeline_reach_followers_with_tag_and_start() -> Result<()> { test_reach_filter_with_posts( BOGOTA, @@ -190,7 +190,7 @@ async fn test_stream_posts_by_timeline_reach_followers_with_tag_and_start() -> R .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_timeline_reach_followers_with_tag_start_and_skip() -> Result<()> { test_reach_filter_with_posts( BOGOTA, @@ -206,7 +206,7 @@ async fn test_stream_posts_by_timeline_reach_followers_with_tag_start_and_skip() .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_timeline_reach_followers_with_tag_start_skip_and_limit() -> Result<()> { test_reach_filter_with_posts( @@ -223,7 +223,7 @@ async fn test_stream_posts_by_timeline_reach_followers_with_tag_start_skip_and_l .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_timeline_reach_followers_with_tag_and_end() -> Result<()> { test_reach_filter_with_posts( BOGOTA, @@ -239,7 +239,7 @@ async fn test_stream_posts_by_timeline_reach_followers_with_tag_and_end() -> Res .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_timeline_reach_followers_with_tag_start_and_end() -> Result<()> { test_reach_filter_with_posts( BOGOTA, @@ -263,7 +263,7 @@ const EIXAMPLE: &str = "8attbeo9ftu5nztqkcfw3gydksehr7jbspgfi64u4h8eo5e7dbiy"; pub const POST_TA_FR: &str = "L3W5N0F8Q2J7"; pub const POST_TB_FR: &str = "M4X1P9L2J6K8"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_timeline_reach_friends_with_tag() -> Result<()> { test_reach_filter_with_posts( EIXAMPLE, @@ -279,7 +279,7 @@ async fn test_stream_posts_by_timeline_reach_friends_with_tag() -> Result<()> { .await } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_not_found_posts_by_timeline_reach_friends_with_tag() -> Result<()> { let path = format!( "{ROOT_PATH}?sorting=timeline&tags=opensource&source=friends&observer_id={EIXAMPLE}&skip=2" diff --git a/tests/service/stream/post/tags.rs b/tests/service/stream/post/tags.rs index d6ff2c81..2b075259 100644 --- a/tests/service/stream/post/tags.rs +++ b/tests/service/stream/post/tags.rs @@ -7,7 +7,7 @@ use super::{POST_A, POST_B, POST_C, POST_D, POST_E, POST_F, POST_G, POST_H}; use super::{ROOT_PATH, VIEWER_ID}; use super::{TAG_LABEL_1, TAG_LABEL_2, TAG_LABEL_3, TAG_LABEL_4}; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_tag_search() -> Result<()> { let post_order = vec![POST_C, POST_B, POST_A, POST_D, POST_E, POST_F]; let path = format!("{}?tags={}&limit=6", ROOT_PATH, TAG_LABEL_2); @@ -26,7 +26,7 @@ async fn test_post_tag_search() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_tag_search_with_limit() -> Result<()> { let post_order = vec![POST_C, POST_B]; let path = format!("{}?tags={}&limit=2", ROOT_PATH, TAG_LABEL_2); @@ -45,7 +45,7 @@ async fn test_post_tag_search_with_limit() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_tag_search_with_skip() -> Result<()> { let post_order = vec![POST_G, POST_H]; let path = format!("{}?tags={}&skip=6", ROOT_PATH, TAG_LABEL_2); @@ -64,7 +64,7 @@ async fn test_post_tag_search_with_skip() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_tag_search_with_skip_and_limit() -> Result<()> { let post_order = vec![POST_B]; let path = format!("{}?tags={}&skip=1&limit=1", ROOT_PATH, TAG_LABEL_2); @@ -83,7 +83,7 @@ async fn test_post_tag_search_with_skip_and_limit() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_tag_search_with_viewer_id() -> Result<()> { const BOOKMARK_ID: &str = "A9G7F2L4Q1W3"; @@ -102,7 +102,7 @@ async fn test_post_tag_search_with_viewer_id() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_tag() -> Result<()> { let path = format!("{ROOT_PATH}?tags={}&sorting=timeline", TAG_LABEL_1); let body = make_request(&path).await?; @@ -146,7 +146,7 @@ pub const POST_TM: &str = "2ZDYA7MH312G0"; pub const START_TIMELINE: &str = "1719244802772"; pub const END_TIMELINE: &str = "1719231303114"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_tag_timeline_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?tags={TAG_LABEL_1}&sorting=timeline&start={START_TIMELINE}"); @@ -160,7 +160,7 @@ async fn test_stream_posts_by_tag_timeline_with_start() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_tag_timeline_with_start_and_end() -> Result<()> { let path = format!( "{ROOT_PATH}?tags={TAG_LABEL_1}&sorting=timeline&start={START_TIMELINE}&end={END_TIMELINE}" @@ -174,7 +174,7 @@ async fn test_stream_posts_by_tag_timeline_with_start_and_end() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_tag_timeline_with_end() -> Result<()> { let path = format!("{ROOT_PATH}?tags={TAG_LABEL_1}&sorting=timeline&end={START_TIMELINE}"); @@ -186,7 +186,7 @@ async fn test_stream_posts_by_tag_timeline_with_end() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_tag_timeline_with_end_and_skip() -> Result<()> { let path = format!("{ROOT_PATH}?tags={TAG_LABEL_1}&sorting=timeline&end={START_TIMELINE}&skip=2"); @@ -199,7 +199,7 @@ async fn test_stream_posts_by_tag_timeline_with_end_and_skip() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_tag_timeline_with_start_skip_and_limit() -> Result<()> { let path = format!( "{ROOT_PATH}?tags={TAG_LABEL_1}&sorting=timeline&start={START_TIMELINE}&skip=2&limit=5" @@ -213,7 +213,7 @@ async fn test_stream_posts_by_tag_timeline_with_start_skip_and_limit() -> Result Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_multiple_tags() -> Result<()> { let path = format!( "{ROOT_PATH}?tags={},{},{}&sorting=timeline&limit=30", @@ -267,7 +267,7 @@ pub const POST_EL: &str = "2ZDYGS5S86D00"; pub const ENGAGEMENT_SCORE_START: &str = "6"; pub const ENGAGEMENT_SCORE_END: &str = "4"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_tag_posts_by_engagment_tag() -> Result<()> { let path = format!("{ROOT_PATH}?tags={}&sorting=total_engagement", TAG_LABEL_1); @@ -292,7 +292,7 @@ async fn test_stream_tag_posts_by_engagment_tag() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_tag_posts_by_engagement_with_start() -> Result<()> { let path = format!( "{}?tags={}&sorting=total_engagement&start={}", @@ -309,7 +309,7 @@ async fn test_stream_tag_posts_by_engagement_with_start() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_tag_posts_by_engagement_with_start_and_end() -> Result<()> { let path = format!( "{}?tags={}&sorting=total_engagement&start={}&end={}", @@ -324,7 +324,7 @@ async fn test_stream_tag_posts_by_engagement_with_start_and_end() -> Result<()> Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_tag_posts_by_engagement_with_start_and_limit() -> Result<()> { let path = format!( "{}?tags={}&sorting=total_engagement&start={}&limit=6", @@ -339,7 +339,7 @@ async fn test_stream_tag_posts_by_engagement_with_start_and_limit() -> Result<() Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_tag_posts_by_engagement_with_end_skip_and_limit() -> Result<()> { let path = format!( "{}?tags={}&sorting=total_engagement&end={}&skip=3&limit=6", @@ -354,7 +354,7 @@ async fn test_stream_tag_posts_by_engagement_with_end_skip_and_limit() -> Result Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_specific_tag_with_no_result() -> Result<()> { let path = format!("{}?tags={}", ROOT_PATH, "randommm"); make_wrong_request(&path, None).await?; diff --git a/tests/service/stream/user/list.rs b/tests/service/stream/user/list.rs index b9cfaf64..c3bb7394 100644 --- a/tests/service/stream/user/list.rs +++ b/tests/service/stream/user/list.rs @@ -4,7 +4,7 @@ use serde_json::json; // ##### LIST OF USERS BY ID ###### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_users_by_ids_valid_request() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -57,7 +57,7 @@ async fn test_stream_users_by_ids_valid_request() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_users_by_ids_limit_exceeded() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -83,7 +83,7 @@ async fn test_stream_users_by_ids_limit_exceeded() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_users_by_ids_with_invalid_ids() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -133,7 +133,7 @@ async fn test_stream_users_by_ids_with_invalid_ids() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_users_by_ids_empty_list() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -161,7 +161,7 @@ async fn test_stream_users_by_ids_empty_list() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_users_by_ids_with_viewer_id() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; diff --git a/tests/service/stream/user/reach.rs b/tests/service/stream/user/reach.rs index 4a3f6d71..f611f5ac 100644 --- a/tests/service/stream/user/reach.rs +++ b/tests/service/stream/user/reach.rs @@ -1,7 +1,7 @@ use crate::service::utils::HOST_URL; use anyhow::Result; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_following() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; diff --git a/tests/service/stream/user/score.rs b/tests/service/stream/user/score.rs index 2eba7954..f4101aaa 100644 --- a/tests/service/stream/user/score.rs +++ b/tests/service/stream/user/score.rs @@ -3,7 +3,7 @@ use anyhow::Result; // ##### MOST FOLLOWED USERS ###### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_most_followed() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -77,7 +77,7 @@ async fn test_stream_most_followed() -> Result<()> { // ##### PIONEERS USERS ###### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_pioneers() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -147,7 +147,7 @@ async fn test_stream_pioneers() -> Result<()> { // ##### RECOMMENDED USERS ###### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_recommended() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -218,7 +218,7 @@ async fn test_stream_recommended() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_recommended_missing_user_id() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; diff --git a/tests/service/stream/user/search.rs b/tests/service/stream/user/search.rs index 319c7aa4..a4d09045 100644 --- a/tests/service/stream/user/search.rs +++ b/tests/service/stream/user/search.rs @@ -1,7 +1,7 @@ use crate::service::utils::HOST_URL; use anyhow::Result; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_stream_users_by_username_search() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; diff --git a/tests/service/tags/hot.rs b/tests/service/tags/hot.rs index bf76b167..4d9995c7 100644 --- a/tests/service/tags/hot.rs +++ b/tests/service/tags/hot.rs @@ -54,7 +54,7 @@ fn compare_unit_hot_tag(tag: &Value, hot_tag: StreamTagMockup) { assert_eq!(tagger_ids.len(), hot_tag.tagger_ids); } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_global_hot_tags() -> Result<()> { let body = make_request("/v0/tags/hot").await?; @@ -72,7 +72,7 @@ async fn test_global_hot_tags() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_global_hot_tags_with_today_timeframe() -> Result<()> { let body = make_request("/v0/tags/hot?timeframe=today").await?; @@ -90,7 +90,7 @@ async fn test_global_hot_tags_with_today_timeframe() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_global_hot_tags_with_this_month_timeframe() -> Result<()> { let body = make_request("/v0/tags/hot?timeframe=this_month").await?; @@ -108,7 +108,7 @@ async fn test_global_hot_tags_with_this_month_timeframe() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_global_hot_tags_skip_limit() -> Result<()> { let body = make_request("/v0/tags/hot?skip=3&limit=5").await?; @@ -129,7 +129,7 @@ async fn test_global_hot_tags_skip_limit() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_hot_tags_by_following_reach() -> Result<()> { let endpoint = &format!("/v0/tags/hot?user_id={}&reach=following", PEER_PUBKY,); @@ -148,7 +148,7 @@ async fn test_hot_tags_by_following_reach() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_hot_tags_by_reach_no_user_id() -> Result<()> { let endpoint = "/v0/tags/hot?reach=following"; @@ -157,7 +157,7 @@ async fn test_hot_tags_by_reach_no_user_id() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_hot_tags_by_reach_no_reach() -> Result<()> { let endpoint = &format!("/v0/tags/hot?user_id={}", PEER_PUBKY); @@ -166,7 +166,7 @@ async fn test_hot_tags_by_reach_no_reach() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_hot_tags_by_following_using_taggers_limit() -> Result<()> { let endpoint = &format!( "/v0/tags/hot?user_id={}&reach=following&taggers_limit=3", @@ -188,7 +188,7 @@ async fn test_hot_tags_by_following_using_taggers_limit() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_hot_tags_by_followers_reach() -> Result<()> { let endpoint = &format!("/v0/tags/hot?user_id={}&reach=followers", PEER_PUBKY); @@ -207,7 +207,7 @@ async fn test_hot_tags_by_followers_reach() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_hot_tags_by_friends_reach() -> Result<()> { let endpoint = &format!("/v0/tags/hot?user_id={}&reach=friends", PEER_PUBKY); diff --git a/tests/service/tags/mod.rs b/tests/service/tags/mod.rs index 078d1163..99439973 100644 --- a/tests/service/tags/mod.rs +++ b/tests/service/tags/mod.rs @@ -13,7 +13,7 @@ pub mod wot; const PEER_PUBKY: &str = "db6w58pd5h63fbhtd88y8zz7pai9rkjwqt9omg6i7dz31dynrgcy"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn check_mockups_loaded() -> Result<(), DynError> { let endpoint = format!("/v0/user/{}/tags", PEER_PUBKY); diff --git a/tests/service/tags/post.rs b/tests/service/tags/post.rs index b533fb5c..fd95a182 100644 --- a/tests/service/tags/post.rs +++ b/tests/service/tags/post.rs @@ -11,7 +11,7 @@ const FREE_LABEL: &str = "free"; // TODO: Create deterministic integration tests -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_tag() -> Result<()> { let path = format!("/v0/post/{}/{}/tags", PEER_PUBKY, POST_ID); let body = make_request(&path).await?; @@ -32,7 +32,7 @@ async fn test_post_tag() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_user_tags_limit_tag_filter_active() -> Result<()> { let path = format!("/v0/post/{}/{}/tags?limit_tags=2", PEER_PUBKY, POST_ID); let body = make_request(&path).await?; @@ -52,7 +52,7 @@ async fn test_user_tags_limit_tag_filter_active() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_user_tags_limit_taggers_filter_active() -> Result<()> { let path = format!("/v0/post/{}/{}/tags?limit_taggers=1", PEER_PUBKY, POST_ID); let body = make_request(&path).await?; @@ -72,7 +72,7 @@ async fn test_user_tags_limit_taggers_filter_active() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_user_tags_full_filter_active() -> Result<()> { let path = format!( "/v0/post/{}/{}/tags?limit_tags=1&limit_taggers=1", @@ -95,7 +95,7 @@ async fn test_user_tags_full_filter_active() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_does_not_exist() -> Result<()> { let endpoint = format!("/v0/post/{}/{}/tags", PEER_PUBKY, "JTDX9ZSWPQF8"); // TODO: Control post not found error control @@ -103,7 +103,7 @@ async fn test_post_does_not_exist() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_user_does_not_exist() -> Result<()> { let endpoint = format!( "/v0/post/{}/{}/tags", @@ -114,7 +114,7 @@ async fn test_user_does_not_exist() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_specific_tag() -> Result<()> { let path = format!("/v0/post/{}/{}/taggers/{}", PEER_PUBKY, POST_ID, FREE_LABEL); let body = make_request(&path).await?; @@ -132,7 +132,7 @@ async fn test_post_specific_tag() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_specific_tag_with_limit() -> Result<()> { let path = format!( "/v0/post/{}/{}/taggers/{}?limit=1", @@ -153,7 +153,7 @@ async fn test_post_specific_tag_with_limit() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_specific_tag_with_skip() -> Result<()> { let path = format!( "/v0/post/{}/{}/taggers/{}?skip=1", @@ -174,7 +174,7 @@ async fn test_post_specific_tag_with_skip() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_specific_tag_with_full_filters() -> Result<()> { let path = format!( "/v0/post/{}/{}/taggers/{}?skip=2&limit=1", @@ -195,7 +195,7 @@ async fn test_post_specific_tag_with_full_filters() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_specific_tag_with_no_result() -> Result<()> { let path = format!( "/v0/post/{}/{}/taggers/{}?skip=3&limit=1", diff --git a/tests/service/tags/search.rs b/tests/service/tags/search.rs index 2f162888..e7182ce4 100644 --- a/tests/service/tags/search.rs +++ b/tests/service/tags/search.rs @@ -10,7 +10,7 @@ const POST_A: &str = "2VDW8YBDZJ02"; const POST_B: &str = "1TDV7XBCF4M1"; const POST_C: &str = "HC3T5CEPBPHQ"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_tag_search_by_timeline() -> Result<()> { let post_order = vec![POST_A, POST_B, POST_C]; let path = format!("{}/{}", ROOT_PATH, FREE_LABEL); @@ -29,7 +29,7 @@ async fn test_tag_search_by_timeline() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_tag_search_with_skip() -> Result<()> { let post_order = vec![POST_B, POST_C]; let path = format!("{}/{}?skip=1", ROOT_PATH, FREE_LABEL); @@ -48,7 +48,7 @@ async fn test_tag_search_with_skip() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_tag_search_with_limit() -> Result<()> { let post_order = vec![POST_A]; let path = format!("{}/{}?limit=1", ROOT_PATH, FREE_LABEL); @@ -67,7 +67,7 @@ async fn test_tag_search_with_limit() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_tag_search_with_limit_and_skip() -> Result<()> { let post_order = vec![POST_C]; let path = format!("{}/{}?limit=1&skip=2", ROOT_PATH, FREE_LABEL); @@ -86,7 +86,7 @@ async fn test_tag_search_with_limit_and_skip() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_post_specific_tag_with_no_result() -> Result<()> { let path = format!("{}/{}", ROOT_PATH, "randommm"); make_wrong_request(&path, None).await?; diff --git a/tests/service/tags/user.rs b/tests/service/tags/user.rs index aeb85b52..16ac3f70 100644 --- a/tests/service/tags/user.rs +++ b/tests/service/tags/user.rs @@ -8,7 +8,7 @@ use super::utils::{analyse_tag_details_structure, compare_tag_details, TagMockup const PUBKY_PEER: &str = "5f4e8eoogmkhqeyo5ijdix3ma6rw9byj8m36yrjp78pnxxc379to"; const PUBKY_LABEL: &str = "pubky"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_full_user_tags_endpoint() -> Result<()> { let path = format!("/v0/user/{}/tags", PUBKY_PEER); let body = make_request(&path).await?; @@ -28,7 +28,7 @@ async fn test_full_user_tags_endpoint() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_user_tags_limit_tag_filter_active() -> Result<()> { let path = format!("/v0/user/{}/tags?limit_tags=2", PUBKY_PEER); let body = make_request(&path).await?; @@ -48,7 +48,7 @@ async fn test_user_tags_limit_tag_filter_active() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_user_tags_limit_taggers_filter_active() -> Result<()> { let path = format!("/v0/user/{}/tags?limit_taggers=1", PUBKY_PEER); let body = make_request(&path).await?; @@ -68,7 +68,7 @@ async fn test_user_tags_limit_taggers_filter_active() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_user_tags_full_filter_active() -> Result<()> { let path = format!("/v0/user/{}/tags?limit_tags=1&limit_taggers=1", PUBKY_PEER); let body = make_request(&path).await?; @@ -88,7 +88,7 @@ async fn test_user_tags_full_filter_active() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_user_does_not_exist() -> Result<()> { let endpoint = format!( "/v0/user/{}/tags", @@ -101,7 +101,7 @@ async fn test_user_does_not_exist() -> Result<()> { // #### USER TAGGERS ###### -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_user_specific_tag() -> Result<()> { let path = format!("/v0/user/{}/taggers/{}", PUBKY_PEER, PUBKY_LABEL); let body = make_request(&path).await?; @@ -119,7 +119,7 @@ async fn test_user_specific_tag() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_user_specific_tag_with_limit() -> Result<()> { let path = format!("/v0/user/{}/taggers/{}?limit=1", PUBKY_PEER, PUBKY_LABEL); let body = make_request(&path).await?; @@ -137,7 +137,7 @@ async fn test_user_specific_tag_with_limit() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_user_specific_tag_with_skip() -> Result<()> { let path = format!("/v0/user/{}/taggers/{}?skip=1", PUBKY_PEER, PUBKY_LABEL); let body = make_request(&path).await?; @@ -155,7 +155,7 @@ async fn test_user_specific_tag_with_skip() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_user_specific_tag_with_full_filters() -> Result<()> { let path = format!( "/v0/user/{}/taggers/{}?skip=2&limit=1", @@ -176,7 +176,7 @@ async fn test_user_specific_tag_with_full_filters() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_user_specific_tag_with_no_result() -> Result<()> { let path = format!( "/v0/user/{}/taggers/{}?skip=3&limit=1", diff --git a/tests/service/tags/wot.rs b/tests/service/tags/wot.rs index ec3bd07c..ffb0a198 100644 --- a/tests/service/tags/wot.rs +++ b/tests/service/tags/wot.rs @@ -17,7 +17,7 @@ const USER_A: &str = "cjoodgkwaf1bwepoe8m6zsp8guobh5wdwmqqnk496jcd175jjwey"; const USER_B: &str = "fs8qf51odhpf9ecoms8i9tbjtyshhjdejpsf3nxcbup3ugs7q4xo"; const USER_C: &str = "cuimec4ngawamq8wa6fjzki6boxmwqcm11x6g7ontufrjwgdaxqo"; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_wot_user_tags_endpoints() -> Result<()> { // Make sure, we still not index the WoT tags let path = format!( diff --git a/tests/service/user/reach.rs b/tests/service/user/reach.rs index d9599029..6d544a5c 100644 --- a/tests/service/user/reach.rs +++ b/tests/service/user/reach.rs @@ -1,7 +1,7 @@ use crate::service::utils::HOST_URL; use anyhow::Result; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_get_followers() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -56,7 +56,7 @@ async fn test_get_followers() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_get_following() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -115,7 +115,7 @@ async fn test_get_following() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_get_friends() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; diff --git a/tests/service/user/search.rs b/tests/service/user/search.rs index 8a4e46cc..555026d4 100644 --- a/tests/service/user/search.rs +++ b/tests/service/user/search.rs @@ -1,7 +1,7 @@ use crate::service::utils::HOST_URL; use anyhow::Result; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_search_users_by_username() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -41,7 +41,7 @@ async fn test_search_users_by_username() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_search_non_existing_user() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -75,7 +75,7 @@ async fn test_search_non_existing_user() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_search_empty_username() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; diff --git a/tests/service/user/views.rs b/tests/service/user/views.rs index 87af59df..fbaa5c39 100644 --- a/tests/service/user/views.rs +++ b/tests/service/user/views.rs @@ -1,7 +1,7 @@ use crate::service::utils::HOST_URL; use anyhow::Result; -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_user_endpoint() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -66,7 +66,7 @@ async fn test_user_endpoint() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_get_relationship() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -92,7 +92,7 @@ async fn test_get_relationship() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_get_counts() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -119,7 +119,7 @@ async fn test_get_counts() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_get_details() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; @@ -148,7 +148,7 @@ async fn test_get_details() -> Result<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared)] async fn test_get_muted() -> Result<()> { let client = httpc_test::new_client(HOST_URL)?; diff --git a/tests/watcher/bookmarks/del.rs b/tests/watcher/bookmarks/del.rs index 0909e585..de0304d6 100644 --- a/tests/watcher/bookmarks/del.rs +++ b/tests/watcher/bookmarks/del.rs @@ -7,7 +7,7 @@ use pubky_nexus::models::post::{Bookmark, PostStream}; #[tokio_shared_rt::test(shared)] async fn test_homeserver_unbookmark() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Step 1: Create a user let keypair = Keypair::random(); diff --git a/tests/watcher/bookmarks/raw.rs b/tests/watcher/bookmarks/raw.rs index 4e0781e9..2245e767 100644 --- a/tests/watcher/bookmarks/raw.rs +++ b/tests/watcher/bookmarks/raw.rs @@ -7,7 +7,7 @@ use pubky_nexus::models::post::{Bookmark, PostStream}; #[tokio_shared_rt::test(shared)] async fn test_homeserver_bookmark() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Step 1: Create a user let keypair = Keypair::random(); diff --git a/tests/watcher/bookmarks/viewer.rs b/tests/watcher/bookmarks/viewer.rs index cba910b4..ba01a613 100644 --- a/tests/watcher/bookmarks/viewer.rs +++ b/tests/watcher/bookmarks/viewer.rs @@ -7,7 +7,7 @@ use pubky_nexus::models::post::PostStream; #[tokio_shared_rt::test(shared)] async fn test_homeserver_viewer_bookmark() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Step 1: Create a user let keypair = Keypair::random(); diff --git a/tests/watcher/files/create.rs b/tests/watcher/files/create.rs index 1b9162f0..56864fc6 100644 --- a/tests/watcher/files/create.rs +++ b/tests/watcher/files/create.rs @@ -10,7 +10,7 @@ use serde_json::to_vec; #[tokio_shared_rt::test(shared)] async fn test_put_pubkyapp_file() -> Result<()> { // Arrange - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(true).await?; let keypair = Keypair::random(); let user = PubkyAppUser { diff --git a/tests/watcher/files/delete.rs b/tests/watcher/files/delete.rs index 91ba4f7e..85fed59b 100644 --- a/tests/watcher/files/delete.rs +++ b/tests/watcher/files/delete.rs @@ -10,7 +10,7 @@ use serde_json::to_vec; #[tokio_shared_rt::test(shared)] async fn test_delete_pubkyapp_file() -> Result<()> { // Arrange - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(true).await?; let keypair = Keypair::random(); let user = PubkyAppUser { diff --git a/tests/watcher/follows/del.rs b/tests/watcher/follows/del.rs index 89e1f6fc..ab02c5f2 100644 --- a/tests/watcher/follows/del.rs +++ b/tests/watcher/follows/del.rs @@ -13,7 +13,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_homeserver_unfollow() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create first user (follower) let follower_keypair = Keypair::random(); diff --git a/tests/watcher/follows/del_friends.rs b/tests/watcher/follows/del_friends.rs index 1a27d211..06935f15 100644 --- a/tests/watcher/follows/del_friends.rs +++ b/tests/watcher/follows/del_friends.rs @@ -9,7 +9,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_homeserver_unfollow_friend() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Step 1: Create first user (follower) let follower_keypair = Keypair::random(); diff --git a/tests/watcher/follows/del_notification.rs b/tests/watcher/follows/del_notification.rs index 5de2d3de..7ec27609 100644 --- a/tests/watcher/follows/del_notification.rs +++ b/tests/watcher/follows/del_notification.rs @@ -10,7 +10,7 @@ use pubky_app_specs::PubkyAppUser; #[tokio_shared_rt::test(shared)] async fn test_homeserver_unfollow_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Step 1: Create first user (follower) let follower_keypair = Keypair::random(); diff --git a/tests/watcher/follows/del_sequential.rs b/tests/watcher/follows/del_sequential.rs index 14879383..6cce48d3 100644 --- a/tests/watcher/follows/del_sequential.rs +++ b/tests/watcher/follows/del_sequential.rs @@ -10,7 +10,7 @@ use pubky_nexus::RedisOps; #[tokio_shared_rt::test(shared)] async fn test_homeserver_sequential_unfollow() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create followee let followee_keypair = Keypair::random(); diff --git a/tests/watcher/follows/put.rs b/tests/watcher/follows/put.rs index be0ff81f..197d1be0 100644 --- a/tests/watcher/follows/put.rs +++ b/tests/watcher/follows/put.rs @@ -13,7 +13,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_homeserver_put_follow() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create first user (follower) let follower_keypair = Keypair::random(); diff --git a/tests/watcher/follows/put_friends.rs b/tests/watcher/follows/put_friends.rs index 6baa2074..f1fb766a 100644 --- a/tests/watcher/follows/put_friends.rs +++ b/tests/watcher/follows/put_friends.rs @@ -8,7 +8,7 @@ use pubky_nexus::RedisOps; #[tokio_shared_rt::test(shared)] async fn test_homeserver_follow_friend() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create Alice user let alice_keypair = Keypair::random(); diff --git a/tests/watcher/follows/put_notification.rs b/tests/watcher/follows/put_notification.rs index ebf2188f..8b67cf45 100644 --- a/tests/watcher/follows/put_notification.rs +++ b/tests/watcher/follows/put_notification.rs @@ -9,7 +9,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_homeserver_follow_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Step 1: Create first user (follower) let follower_keypair = Keypair::random(); diff --git a/tests/watcher/follows/put_sequential.rs b/tests/watcher/follows/put_sequential.rs index 68a7b7d4..f527a0f4 100644 --- a/tests/watcher/follows/put_sequential.rs +++ b/tests/watcher/follows/put_sequential.rs @@ -8,7 +8,7 @@ use pubky_nexus::RedisOps; #[tokio_shared_rt::test(shared)] async fn test_homeserver_sequential_follow() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create followee let followee_keypair = Keypair::random(); diff --git a/tests/watcher/mentions/notification.rs b/tests/watcher/mentions/notification.rs index 8450c49c..d3ffe631 100644 --- a/tests/watcher/mentions/notification.rs +++ b/tests/watcher/mentions/notification.rs @@ -9,7 +9,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_homeserver_mentions_notifications() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create first user (author) let author_keypair = Keypair::random(); diff --git a/tests/watcher/mentions/raw.rs b/tests/watcher/mentions/raw.rs index 72ed6f14..4e8b01aa 100644 --- a/tests/watcher/mentions/raw.rs +++ b/tests/watcher/mentions/raw.rs @@ -7,7 +7,7 @@ use pubky_nexus::{models::post::PostRelationships, RedisOps}; #[tokio_shared_rt::test(shared)] async fn test_homeserver_mentions() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create first user (author) let author_user_keypair = Keypair::random(); diff --git a/tests/watcher/mutes/del.rs b/tests/watcher/mutes/del.rs index 360fd33e..5801456e 100644 --- a/tests/watcher/mutes/del.rs +++ b/tests/watcher/mutes/del.rs @@ -7,7 +7,7 @@ use pubky_nexus::models::user::{Muted, Relationship}; #[tokio_shared_rt::test(shared)] async fn test_homeserver_del_mute() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create first user (muter) let muter_keypair = Keypair::random(); diff --git a/tests/watcher/mutes/put.rs b/tests/watcher/mutes/put.rs index ecc980af..7e9c0ddf 100644 --- a/tests/watcher/mutes/put.rs +++ b/tests/watcher/mutes/put.rs @@ -7,7 +7,7 @@ use pubky_nexus::models::user::{Muted, Relationship}; #[tokio_shared_rt::test(shared)] async fn test_homeserver_put_mute() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create first user (muter) let muter_keypair = Keypair::random(); diff --git a/tests/watcher/network/counts.rs b/tests/watcher/network/counts.rs index 809bf5a1..1dabd008 100644 --- a/tests/watcher/network/counts.rs +++ b/tests/watcher/network/counts.rs @@ -25,7 +25,7 @@ const NUM_USERS: usize = 10; #[tokio_shared_rt::test(shared)] async fn test_large_network_scenario_counts() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; if !PROCESS_EVENTS_ONE_BY_ONE { test = test.remove_event_processing().await; } diff --git a/tests/watcher/posts/attachments.rs b/tests/watcher/posts/attachments.rs index c059806c..21171d12 100644 --- a/tests/watcher/posts/attachments.rs +++ b/tests/watcher/posts/attachments.rs @@ -9,7 +9,7 @@ use serde_json::to_vec; #[tokio_shared_rt::test(shared)] async fn test_homeserver_post_attachments() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; let keypair = Keypair::random(); let user = PubkyAppUser { diff --git a/tests/watcher/posts/del_bookmarked_notification.rs b/tests/watcher/posts/del_bookmarked_notification.rs index f1bb9b72..bc66ccf2 100644 --- a/tests/watcher/posts/del_bookmarked_notification.rs +++ b/tests/watcher/posts/del_bookmarked_notification.rs @@ -11,7 +11,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_delete_bookmarked_post_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create User A who makes the original post let keypair_a = Keypair::random(); diff --git a/tests/watcher/posts/del_reply_notification.rs b/tests/watcher/posts/del_reply_notification.rs index 52c6b937..b8c771a0 100644 --- a/tests/watcher/posts/del_reply_notification.rs +++ b/tests/watcher/posts/del_reply_notification.rs @@ -9,7 +9,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_delete_post_that_replied_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create a user who posts let keypair = Keypair::random(); diff --git a/tests/watcher/posts/del_reply_parent_notification.rs b/tests/watcher/posts/del_reply_parent_notification.rs index 60255b43..5de840b1 100644 --- a/tests/watcher/posts/del_reply_parent_notification.rs +++ b/tests/watcher/posts/del_reply_parent_notification.rs @@ -9,7 +9,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_delete_parent_post_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create User A who makes the original post let keypair_a = Keypair::random(); diff --git a/tests/watcher/posts/del_repost_notification.rs b/tests/watcher/posts/del_repost_notification.rs index 9c62c979..1b608844 100644 --- a/tests/watcher/posts/del_repost_notification.rs +++ b/tests/watcher/posts/del_repost_notification.rs @@ -9,7 +9,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_delete_post_that_reposted_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create a user who posts let keypair = Keypair::random(); diff --git a/tests/watcher/posts/del_reposted_notification.rs b/tests/watcher/posts/del_reposted_notification.rs index 19fdf67e..b289bf15 100644 --- a/tests/watcher/posts/del_reposted_notification.rs +++ b/tests/watcher/posts/del_reposted_notification.rs @@ -9,7 +9,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_delete_reposted_post_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create User A who makes the original post let keypair_a = Keypair::random(); diff --git a/tests/watcher/posts/del_tagged_notification.rs b/tests/watcher/posts/del_tagged_notification.rs index 4523690e..a6313dc6 100644 --- a/tests/watcher/posts/del_tagged_notification.rs +++ b/tests/watcher/posts/del_tagged_notification.rs @@ -10,7 +10,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_delete_tagged_post_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create User A who makes the original post let keypair_a = Keypair::random(); diff --git a/tests/watcher/posts/del_with_relations.rs b/tests/watcher/posts/del_with_relations.rs index 713f5a7d..364eb56c 100644 --- a/tests/watcher/posts/del_with_relations.rs +++ b/tests/watcher/posts/del_with_relations.rs @@ -7,7 +7,7 @@ use pubky_nexus::models::post::{PostCounts, PostDetails, PostView}; #[tokio_shared_rt::test(shared)] async fn test_delete_post_with_relationships() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create a new user let keypair = Keypair::random(); diff --git a/tests/watcher/posts/del_without_relations.rs b/tests/watcher/posts/del_without_relations.rs index 2e118443..38f6f8b3 100644 --- a/tests/watcher/posts/del_without_relations.rs +++ b/tests/watcher/posts/del_without_relations.rs @@ -19,7 +19,7 @@ use super::utils::{ #[tokio_shared_rt::test(shared)] async fn test_delete_post_without_relationships() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create a new user let keypair = Keypair::random(); @@ -124,7 +124,7 @@ async fn test_delete_post_without_relationships() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_delete_post_that_reposted() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create a new user let keypair = Keypair::random(); @@ -255,7 +255,7 @@ async fn test_delete_post_that_reposted() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_delete_post_that_replied() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create a new user let keypair = Keypair::random(); diff --git a/tests/watcher/posts/edit_bookmarked_notification.rs b/tests/watcher/posts/edit_bookmarked_notification.rs index c3e7e5d4..31806140 100644 --- a/tests/watcher/posts/edit_bookmarked_notification.rs +++ b/tests/watcher/posts/edit_bookmarked_notification.rs @@ -11,7 +11,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_edit_bookmarked_post_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create User A who makes the original post let keypair_a = Keypair::random(); diff --git a/tests/watcher/posts/edit_reply_parent_notification.rs b/tests/watcher/posts/edit_reply_parent_notification.rs index 501b712b..a81f42cd 100644 --- a/tests/watcher/posts/edit_reply_parent_notification.rs +++ b/tests/watcher/posts/edit_reply_parent_notification.rs @@ -9,7 +9,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_edit_parent_post_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create User A who makes the original post let keypair_a = Keypair::random(); diff --git a/tests/watcher/posts/edit_reposted_notification.rs b/tests/watcher/posts/edit_reposted_notification.rs index 10988b21..bc5daa6a 100644 --- a/tests/watcher/posts/edit_reposted_notification.rs +++ b/tests/watcher/posts/edit_reposted_notification.rs @@ -9,7 +9,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_edit_reposted_post_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create User A who makes the original post let keypair_a = Keypair::random(); diff --git a/tests/watcher/posts/edit_tagged_notification.rs b/tests/watcher/posts/edit_tagged_notification.rs index 2edbceb4..eab3eaba 100644 --- a/tests/watcher/posts/edit_tagged_notification.rs +++ b/tests/watcher/posts/edit_tagged_notification.rs @@ -10,7 +10,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_edit_tagged_post_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create User A who makes the original post let keypair_a = Keypair::random(); diff --git a/tests/watcher/posts/engagement.rs b/tests/watcher/posts/engagement.rs index 995458c5..11011cb4 100644 --- a/tests/watcher/posts/engagement.rs +++ b/tests/watcher/posts/engagement.rs @@ -6,7 +6,7 @@ use pubky_common::crypto::Keypair; #[tokio_shared_rt::test(shared)] async fn test_homeserver_post_engagement() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; let alice_user_keypair = Keypair::random(); diff --git a/tests/watcher/posts/pioneer.rs b/tests/watcher/posts/pioneer.rs index adb11663..89435a7c 100644 --- a/tests/watcher/posts/pioneer.rs +++ b/tests/watcher/posts/pioneer.rs @@ -5,7 +5,7 @@ use pubky_common::crypto::Keypair; #[tokio_shared_rt::test(shared)] async fn test_homeserver_post_pioneer() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; let alice_user_keypair = Keypair::random(); diff --git a/tests/watcher/posts/raw.rs b/tests/watcher/posts/raw.rs index 9b69fc66..3bcc0b50 100644 --- a/tests/watcher/posts/raw.rs +++ b/tests/watcher/posts/raw.rs @@ -11,7 +11,7 @@ use pubky_nexus::models::post::{PostCounts, PostDetails}; #[tokio_shared_rt::test(shared)] async fn test_homeserver_put_post_event() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; let keypair = Keypair::random(); let user = PubkyAppUser { diff --git a/tests/watcher/posts/reply.rs b/tests/watcher/posts/reply.rs index bf8425d6..52c9db9d 100644 --- a/tests/watcher/posts/reply.rs +++ b/tests/watcher/posts/reply.rs @@ -14,7 +14,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_homeserver_post_reply() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; let keypair = Keypair::random(); diff --git a/tests/watcher/posts/reply_engagement.rs b/tests/watcher/posts/reply_engagement.rs index f959bc3d..a777acec 100644 --- a/tests/watcher/posts/reply_engagement.rs +++ b/tests/watcher/posts/reply_engagement.rs @@ -11,7 +11,7 @@ use pubky_common::crypto::Keypair; #[tokio_shared_rt::test(shared)] async fn test_homeserver_reply_engagement_control() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; let keypair = Keypair::random(); diff --git a/tests/watcher/posts/reply_notification.rs b/tests/watcher/posts/reply_notification.rs index e1297af2..779d8ca5 100644 --- a/tests/watcher/posts/reply_notification.rs +++ b/tests/watcher/posts/reply_notification.rs @@ -8,7 +8,7 @@ use pubky_nexus::types::Pagination; #[tokio_shared_rt::test(shared)] async fn test_homeserver_post_reply_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; let alice_keypair = Keypair::random(); diff --git a/tests/watcher/posts/reply_repost.rs b/tests/watcher/posts/reply_repost.rs index 041176d2..22e8c8e3 100644 --- a/tests/watcher/posts/reply_repost.rs +++ b/tests/watcher/posts/reply_repost.rs @@ -7,7 +7,7 @@ use pubky_common::crypto::Keypair; #[tokio_shared_rt::test(shared)] async fn test_homeserver_reply_repost() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; let keypair = Keypair::random(); diff --git a/tests/watcher/posts/repost.rs b/tests/watcher/posts/repost.rs index 833e8d8e..e8992d62 100644 --- a/tests/watcher/posts/repost.rs +++ b/tests/watcher/posts/repost.rs @@ -15,7 +15,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_homeserver_post_repost() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; let keypair = Keypair::random(); diff --git a/tests/watcher/posts/repost_notification.rs b/tests/watcher/posts/repost_notification.rs index 74c28616..d552d3fb 100644 --- a/tests/watcher/posts/repost_notification.rs +++ b/tests/watcher/posts/repost_notification.rs @@ -8,7 +8,7 @@ use pubky_nexus::types::Pagination; #[tokio_shared_rt::test(shared)] async fn test_homeserver_post_repost_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; let alice_keypair = Keypair::random(); diff --git a/tests/watcher/tags/post_del.rs b/tests/watcher/tags/post_del.rs index bcb4a8cb..0455f2b5 100644 --- a/tests/watcher/tags/post_del.rs +++ b/tests/watcher/tags/post_del.rs @@ -14,7 +14,7 @@ use pubky_nexus::RedisOps; #[tokio_shared_rt::test(shared)] async fn test_homeserver_del_tag_post() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Step 1: Create a user let tagger_keypair = Keypair::random(); diff --git a/tests/watcher/tags/post_muti_user.rs b/tests/watcher/tags/post_muti_user.rs index 600673b2..4737356b 100644 --- a/tests/watcher/tags/post_muti_user.rs +++ b/tests/watcher/tags/post_muti_user.rs @@ -26,7 +26,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_homeserver_multi_user() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Step 1: Write in the homeserver and index in nexus let mut user_ids = Vec::with_capacity(4); diff --git a/tests/watcher/tags/post_notification.rs b/tests/watcher/tags/post_notification.rs index 5a020dd6..4680898d 100644 --- a/tests/watcher/tags/post_notification.rs +++ b/tests/watcher/tags/post_notification.rs @@ -11,7 +11,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_homeserver_tag_post_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create first user (post author) let author_keypair = Keypair::random(); diff --git a/tests/watcher/tags/post_put.rs b/tests/watcher/tags/post_put.rs index 05d2616b..3fcafad3 100644 --- a/tests/watcher/tags/post_put.rs +++ b/tests/watcher/tags/post_put.rs @@ -17,7 +17,7 @@ use pubky_nexus::RedisOps; #[tokio_shared_rt::test(shared)] async fn test_homeserver_put_tag_post() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Step 1: Create a user let keypair = Keypair::random(); diff --git a/tests/watcher/tags/user_notification.rs b/tests/watcher/tags/user_notification.rs index d2942b36..aae1ba88 100644 --- a/tests/watcher/tags/user_notification.rs +++ b/tests/watcher/tags/user_notification.rs @@ -10,7 +10,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_homeserver_put_tag_user_notification() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create the first user (tagged user) let tagged_keypair = Keypair::random(); diff --git a/tests/watcher/tags/user_to_self_put.rs b/tests/watcher/tags/user_to_self_put.rs index b1929765..dcfa83ef 100644 --- a/tests/watcher/tags/user_to_self_put.rs +++ b/tests/watcher/tags/user_to_self_put.rs @@ -11,7 +11,7 @@ use pubky_nexus::models::tag::{traits::TagCollection, user::TagUser}; #[tokio_shared_rt::test(shared)] async fn test_homeserver_put_tag_user_self() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Step 1: Create a user let keypair = Keypair::random(); diff --git a/tests/watcher/tags/user_to_user_del.rs b/tests/watcher/tags/user_to_user_del.rs index f7e87b66..76f19d07 100644 --- a/tests/watcher/tags/user_to_user_del.rs +++ b/tests/watcher/tags/user_to_user_del.rs @@ -11,7 +11,7 @@ use pubky_nexus::models::tag::{traits::TagCollection, user::TagUser}; #[tokio_shared_rt::test(shared)] async fn test_homeserver_del_tag_to_another_user() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Step 1: Create the users let tagged_keypair = Keypair::random(); diff --git a/tests/watcher/tags/user_to_user_put.rs b/tests/watcher/tags/user_to_user_put.rs index 2eddf691..1a083be4 100644 --- a/tests/watcher/tags/user_to_user_put.rs +++ b/tests/watcher/tags/user_to_user_put.rs @@ -11,7 +11,7 @@ use pubky_nexus::models::tag::{traits::TagCollection, user::TagUser}; #[tokio_shared_rt::test(shared)] async fn test_homeserver_put_tag_user_another() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Step 1: Create the users let tagged_keypair = Keypair::random(); diff --git a/tests/watcher/users/del_with_relations.rs b/tests/watcher/users/del_with_relations.rs index dc55e544..7fa9ccb1 100644 --- a/tests/watcher/users/del_with_relations.rs +++ b/tests/watcher/users/del_with_relations.rs @@ -12,7 +12,7 @@ use pubky_nexus::models::user::{UserCounts, UserView}; use serde_json::to_vec; #[tokio_shared_rt::test(shared)] async fn test_delete_user_with_relationships() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create a new user let keypair = Keypair::random(); diff --git a/tests/watcher/users/del_without_relations.rs b/tests/watcher/users/del_without_relations.rs index fb53340f..f68bd052 100644 --- a/tests/watcher/users/del_without_relations.rs +++ b/tests/watcher/users/del_without_relations.rs @@ -6,7 +6,7 @@ use pubky_nexus::models::user::{UserCounts, UserView}; #[tokio_shared_rt::test(shared)] async fn test_delete_user_without_relationships() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; // Create a new user without any relationships let keypair = Keypair::random(); diff --git a/tests/watcher/users/raw.rs b/tests/watcher/users/raw.rs index c2dc46d7..c47edd89 100644 --- a/tests/watcher/users/raw.rs +++ b/tests/watcher/users/raw.rs @@ -12,7 +12,7 @@ use pubky_nexus::{ #[tokio_shared_rt::test(shared)] async fn test_homeserver_user_put_event() -> Result<()> { - let mut test = WatcherTest::setup().await?; + let mut test = WatcherTest::setup(false).await?; let keypair = Keypair::random(); diff --git a/tests/watcher/utils.rs b/tests/watcher/utils.rs index 6282d951..79b81acd 100644 --- a/tests/watcher/utils.rs +++ b/tests/watcher/utils.rs @@ -10,6 +10,8 @@ use pubky_homeserver::Homeserver; use pubky_nexus::{setup, Config, EventProcessor}; use serde_json::to_vec; +use crate::utils::TestServiceServer; + /// Struct to hold the setup environment for tests pub struct WatcherTest { pub homeserver: Homeserver, @@ -17,10 +19,11 @@ pub struct WatcherTest { pub event_processor: EventProcessor, pub config: Config, pub ensure_event_processing: bool, + pub service_server: Option, } impl WatcherTest { - pub async fn setup() -> Result { + pub async fn setup(with_service_server: bool) -> Result { let config = Config::from_env(); setup(&config).await; @@ -29,6 +32,10 @@ impl WatcherTest { let client = PubkyClient::test(&testnet); let homeserver_url = format!("http://localhost:{}", homeserver.port()); let event_processor = EventProcessor::test(&testnet, homeserver_url).await; + let service_server = match with_service_server { + true => Some(TestServiceServer::get_test_server().await), + false => None, + }; Ok(Self { config, @@ -36,6 +43,7 @@ impl WatcherTest { client, event_processor, ensure_event_processing: true, + service_server, }) } From ce815ddc94f66ed122fa3b34c7572044517f5954 Mon Sep 17 00:00:00 2001 From: amir Date: Fri, 13 Dec 2024 00:14:42 -0500 Subject: [PATCH 3/3] Refactor tests --- src/lib.rs | 2 +- tests/service/all.rs | 110 ++++++-------- tests/service/endpoints.rs | 5 + tests/service/stream/post/author.rs | 4 +- tests/service/stream/post/author_replies.rs | 4 +- tests/service/stream/post/bookmarks.rs | 10 +- tests/service/stream/post/kind/all.rs | 8 +- tests/service/stream/post/kind/file.rs | 26 ++-- tests/service/stream/post/kind/image.rs | 26 ++-- tests/service/stream/post/kind/link.rs | 26 ++-- tests/service/stream/post/kind/long.rs | 26 ++-- tests/service/stream/post/kind/video.rs | 26 ++-- tests/service/stream/post/mod.rs | 1 + tests/service/stream/post/post_replies.rs | 14 +- tests/service/stream/post/posts.rs | 29 ++-- tests/service/stream/post/reach/engagement.rs | 6 +- tests/service/stream/post/reach/timeline.rs | 13 +- tests/service/stream/post/reach/utils.rs | 4 +- tests/service/stream/post/tags.rs | 39 ++--- tests/service/stream/user/list.rs | 74 +++------ tests/service/stream/user/reach.rs | 34 ++--- tests/service/stream/user/score.rs | 99 +++++------- tests/service/stream/user/search.rs | 15 +- tests/service/tags/hot.rs | 22 +-- tests/service/tags/mod.rs | 12 +- tests/service/tags/post.rs | 25 +-- tests/service/tags/search.rs | 13 +- tests/service/tags/user.rs | 23 +-- tests/service/tags/wot.rs | 21 +-- tests/service/user/reach.rs | 71 ++++----- tests/service/user/search.rs | 59 +++----- tests/service/user/views.rs | 143 +++++++----------- tests/service/utils.rs | 71 +++++++-- tests/utils.rs | 113 ++++++++++---- tests/watcher/utils.rs | 9 +- 35 files changed, 569 insertions(+), 614 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5aefe23a..4620ef11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ mod config; -mod db; +pub mod db; mod error; pub mod events; pub mod models; diff --git a/tests/service/all.rs b/tests/service/all.rs index 7c8e6dcb..165da8cd 100644 --- a/tests/service/all.rs +++ b/tests/service/all.rs @@ -1,16 +1,20 @@ +use crate::service::utils::{get_request, invalid_get_request, post_request}; +use anyhow::Result; +use pubky_nexus::models::tag::TagDetails; +use reqwest::StatusCode; +use serde_json::json; use std::{ fs::{self, create_dir_all, remove_file, File}, io::Write, }; -use anyhow::Result; -use pubky_nexus::models::tag::TagDetails; -use serde_json::json; +use crate::utils::TestServiceServer; const HOST_URL: &str = "http://localhost:8080"; #[tokio_shared_rt::test(shared)] async fn test_static_serving() -> Result<()> { + TestServiceServer::get_test_server().await; let client = httpc_test::new_client(HOST_URL)?; let test_file_path = "static"; let test_file_name = "foobar"; @@ -50,33 +54,28 @@ async fn test_static_serving() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_file_details() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; let test_file_id = "2ZK2H8P2T5NG0"; let test_file_user = "y4euc58gnmxun9wo87gwmanu6kztt9pgw1zz1yp1azp7trrsjamy"; let test_file_uri = format!("pubky://{test_file_user}/pub/pubky.app/files/{test_file_id}"); - let res = client - .do_get( - format!( - "/v0/files/file/{}", - url::form_urlencoded::byte_serialize(test_file_uri.as_bytes()).collect::() - ) - .as_str(), + let res = get_request( + format!( + "/v0/files/file/{}", + url::form_urlencoded::byte_serialize(test_file_uri.as_bytes()).collect::() ) - .await?; + .as_str(), + ) + .await?; - let json_body = res.json_body()?; - assert_eq!(res.status(), 200); - assert_eq!(json_body["id"], test_file_id); - assert_eq!(json_body["owner_id"], test_file_user); + assert_eq!(res["id"], test_file_id); + assert_eq!(res["owner_id"], test_file_user); Ok(()) } #[tokio_shared_rt::test(shared)] async fn test_files_by_ids() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; let test_file_id = "2ZK2H8P2T5NG0"; let test_file_user = "y4euc58gnmxun9wo87gwmanu6kztt9pgw1zz1yp1azp7trrsjamy"; let test_file_uri = format!("pubky://{test_file_user}/pub/pubky.app/files/{test_file_id}"); @@ -85,72 +84,63 @@ async fn test_files_by_ids() -> Result<()> { let test_file_user2 = "sfgetccnq7s3h57a7imf6n7k5fqxus33yg85f1ndhnrnofjdmhjy"; let test_file_uri2 = format!("pubky://{test_file_user2}/pub/pubky.app/files/{test_file_id2}"); - let res = client - .do_post( - "/v0/files/by-ids", - json!({"uris": [test_file_uri, test_file_uri2]}), - ) - .await?; - - let json_body = res.json_body()?; + let res = post_request( + "/v0/files/by-ids", + json!({"uris": [test_file_uri, test_file_uri2]}), + ) + .await?; - assert_eq!(res.status(), 200); - assert_eq!(json_body.as_array().unwrap().len(), 2); + assert_eq!(res.as_array().unwrap().len(), 2); - assert_eq!(json_body[0]["id"], test_file_id); - assert_eq!(json_body[0]["owner_id"], test_file_user); - assert_eq!(json_body[1]["id"], test_file_id2); - assert_eq!(json_body[1]["owner_id"], test_file_user2); + assert_eq!(res[0]["id"], test_file_id); + assert_eq!(res[0]["owner_id"], test_file_user); + assert_eq!(res[1]["id"], test_file_id2); + assert_eq!(res[1]["owner_id"], test_file_user2); Ok(()) } #[tokio_shared_rt::test(shared)] async fn test_get_post() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - let author_id = "y4euc58gnmxun9wo87gwmanu6kztt9pgw1zz1yp1azp7trrsjamy"; let post_id = "2ZCW1TGR5BKG0"; - let res = client - .do_get(&format!( - "/v0/post/{}/{}?viewer_id={}", - author_id, post_id, author_id - )) - .await?; - assert_eq!(res.status(), 200); - - let body = res.json_body()?; - - assert_eq!(body["details"]["content"], "I am told we can reply now!"); - assert_eq!(body["details"]["indexed_at"].as_u64(), Some(1718616844478)); - assert_eq!(body["details"]["id"], post_id); - assert_eq!(body["details"]["author"], author_id); - assert_eq!(body["details"]["attachments"].as_array().unwrap().len(), 1); + let res = get_request(&format!( + "/v0/post/{}/{}?viewer_id={}", + author_id, post_id, author_id + )) + .await?; + + assert_eq!(res["details"]["content"], "I am told we can reply now!"); + assert_eq!(res["details"]["indexed_at"].as_u64(), Some(1718616844478)); + assert_eq!(res["details"]["id"], post_id); + assert_eq!(res["details"]["author"], author_id); + assert_eq!(res["details"]["attachments"].as_array().unwrap().len(), 1); assert_eq!( - (body["details"]["attachments"].as_array().unwrap())[0], + (res["details"]["attachments"].as_array().unwrap())[0], "pubky://y4euc58gnmxun9wo87gwmanu6kztt9pgw1zz1yp1azp7trrsjamy/pub/pubky.app/files/2ZKH7K7M9G3G0".to_string() ); assert_eq!( - body["details"]["uri"], + res["details"]["uri"], "pubky://y4euc58gnmxun9wo87gwmanu6kztt9pgw1zz1yp1azp7trrsjamy/pub/pubky.app/posts/2ZCW1TGR5BKG0" ); - assert_eq!(body["counts"]["tags"].as_u64(), Some(5)); - assert_eq!(body["counts"]["replies"].as_u64(), Some(2)); - assert_eq!(body["counts"]["reposts"].as_u64(), Some(1)); - assert_eq!(body["bookmark"]["indexed_at"].as_u64(), Some(1721764200000)); - assert_eq!(body["bookmark"]["id"], "2Z9PFGC3WWWW0"); + assert_eq!(res["counts"]["tags"].as_u64(), Some(5)); + assert_eq!(res["counts"]["replies"].as_u64(), Some(2)); + assert_eq!(res["counts"]["reposts"].as_u64(), Some(1)); + assert_eq!(res["bookmark"]["indexed_at"].as_u64(), Some(1721764200000)); + assert_eq!(res["bookmark"]["id"], "2Z9PFGC3WWWW0"); // Panic if tags vector is bigger that 1 - let post_tag_object = body["tags"][0].clone(); + let post_tag_object = res["tags"][0].clone(); let post_tag: TagDetails = serde_json::from_value(post_tag_object.clone())?; assert_eq!(post_tag.label, "pubky"); // Test non-existing post - let res = client - .do_get(&format!("/v0/post/{}/{}", author_id, "no_post")) - .await?; - assert_eq!(res.status(), 404); + invalid_get_request( + &format!("/v0/post/{}/{}", author_id, "no_post"), + StatusCode::NOT_FOUND, + ) + .await?; Ok(()) } diff --git a/tests/service/endpoints.rs b/tests/service/endpoints.rs index 1bf66c72..7f79ce02 100644 --- a/tests/service/endpoints.rs +++ b/tests/service/endpoints.rs @@ -1,9 +1,12 @@ use anyhow::Result; +use crate::utils::TestServiceServer; + const HOST_URL: &str = "http://localhost:8080"; #[tokio_shared_rt::test(shared)] async fn test_swagger_ui() -> Result<()> { + TestServiceServer::get_test_server().await; let client = httpc_test::new_client(HOST_URL)?; let res = client.do_get("/swagger-ui").await?; @@ -16,6 +19,7 @@ async fn test_swagger_ui() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_openapi_schema() -> Result<()> { + TestServiceServer::get_test_server().await; let client = httpc_test::new_client(HOST_URL)?; let res = client.do_get("/api-docs/openapi.json").await?; @@ -32,6 +36,7 @@ async fn test_openapi_schema() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_info_endpoint() -> Result<()> { + TestServiceServer::get_test_server().await; let client = httpc_test::new_client(HOST_URL)?; let res = client.do_get("/v0/info").await?; diff --git a/tests/service/stream/post/author.rs b/tests/service/stream/post/author.rs index af076287..85bffbbd 100644 --- a/tests/service/stream/post/author.rs +++ b/tests/service/stream/post/author.rs @@ -1,5 +1,5 @@ use super::{ROOT_PATH, USER_ID}; -use crate::service::utils::make_request; +use crate::service::utils::get_request; use anyhow::Result; #[tokio_shared_rt::test(shared)] @@ -8,7 +8,7 @@ async fn test_stream_user_posts() -> Result<()> { "{ROOT_PATH}?author_id={}&source=author&sorting=timeline", USER_ID ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); diff --git a/tests/service/stream/post/author_replies.rs b/tests/service/stream/post/author_replies.rs index 3f7e8792..cb20e3d9 100644 --- a/tests/service/stream/post/author_replies.rs +++ b/tests/service/stream/post/author_replies.rs @@ -1,5 +1,5 @@ use super::ROOT_PATH; -use crate::service::utils::make_request; +use crate::service::utils::get_request; use anyhow::Result; #[tokio_shared_rt::test(shared)] @@ -9,7 +9,7 @@ async fn test_stream_user_replies() -> Result<()> { "{ROOT_PATH}?author_id={}&source=author_replies&sorting=timeline", author_id ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); diff --git a/tests/service/stream/post/bookmarks.rs b/tests/service/stream/post/bookmarks.rs index 42dd72d2..dea29f1c 100644 --- a/tests/service/stream/post/bookmarks.rs +++ b/tests/service/stream/post/bookmarks.rs @@ -1,6 +1,6 @@ use super::utils::verify_post_list; use super::ROOT_PATH; -use crate::service::utils::make_request; +use crate::service::utils::get_request; use anyhow::Result; // User with most bookmarks @@ -10,7 +10,7 @@ const BOOKMARKER_ID: &str = "o1gg96ewuojmopcjbz8895478wdtxtzzuxnfjjz8o8e77csa1ng async fn test_stream_bookmarked_posts() -> Result<()> { let observer_id = BOOKMARKER_ID; let path = format!("{ROOT_PATH}?observer_id={}&source=bookmarks", observer_id); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -45,7 +45,7 @@ async fn test_stream_user_bookmarks_by_timeline_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?observer_id={BOOKMARKER_ID}&source=bookmarks&start={START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![ POST_TC, POST_TD, POST_TE, POST_TF, POST_TG, POST_TH, POST_TI, POST_TJ, POST_TK, ]; @@ -60,7 +60,7 @@ async fn test_stream_user_bookmarks_by_timeline_with_start_and_end() -> Result<( "{ROOT_PATH}?observer_id={BOOKMARKER_ID}&source=bookmarks&start={START_TIMELINE}&end={END_TIMELINE}" ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![ POST_TC, POST_TD, POST_TE, POST_TF, POST_TG, POST_TH, POST_TI, ]; @@ -75,7 +75,7 @@ async fn test_stream_user_bookmarks_by_timeline_with_skip_end() -> Result<()> { "{ROOT_PATH}?observer_id={BOOKMARKER_ID}&source=bookmarks&limit=5&end={END_TIMELINE}" ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_TA, POST_TB, POST_TC, POST_TD, POST_TE]; verify_post_list(post_list, body); diff --git a/tests/service/stream/post/kind/all.rs b/tests/service/stream/post/kind/all.rs index d5c9cc29..dcca336d 100644 --- a/tests/service/stream/post/kind/all.rs +++ b/tests/service/stream/post/kind/all.rs @@ -1,6 +1,6 @@ use crate::service::stream::post::utils::verify_post_list; use crate::service::stream::post::ROOT_PATH; -use crate::service::utils::make_request; +use crate::service::utils::get_request; use anyhow::Result; const POST_A1: &str = "SIJW1TGL5BKG6"; @@ -29,7 +29,7 @@ pub const FK_TAG: &str = "4k"; async fn test_stream_post_kind() -> Result<()> { let path = format!("{ROOT_PATH}?author_id={BOGOTA}&source=author"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![ POST_A1, POST_A2, POST_A3, POST_A4, POST_A5, POST_A6, POST_A7, POST_A8, POST_A9, POST_A10, ]; @@ -44,7 +44,7 @@ async fn test_stream_post_kind_with_start_and_end() -> Result<()> { "{ROOT_PATH}?author_id={BOGOTA}&source=author&start={START_TIMELINE}&end={END_TIMELINE}" ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_A3, POST_A4, POST_A5, POST_A6, POST_A7]; verify_post_list(post_list, body); @@ -55,7 +55,7 @@ async fn test_stream_post_kind_with_start_and_end() -> Result<()> { async fn test_stream_post_kind_with_tag() -> Result<()> { let path = format!("{ROOT_PATH}?author_id={BOGOTA}&source=author&tags={PUBKY_TAG}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_A4, POST_A9, POST_W_PUBKY_TAG_1, POST_W_PUBKY_TAG_2]; verify_post_list(post_list, body); diff --git a/tests/service/stream/post/kind/file.rs b/tests/service/stream/post/kind/file.rs index cca4843b..65fca494 100644 --- a/tests/service/stream/post/kind/file.rs +++ b/tests/service/stream/post/kind/file.rs @@ -2,7 +2,7 @@ use super::DETROIT; use crate::service::stream::post::utils::verify_post_list_kind; use crate::service::stream::post::ROOT_PATH; use crate::service::stream::post::{AMSTERDAM, BOGOTA}; -use crate::service::utils::make_request; +use crate::service::utils::get_request; use anyhow::Result; const KIND: &str = "file"; @@ -23,7 +23,7 @@ pub const END_TIMELINE: &str = "1980477299309"; async fn test_stream_file_post_kind() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![ POST_F1, POST_F2, POST_F3, POST_F4, POST_F5, POST_F6, POST_F7, POST_F8, ]; @@ -36,7 +36,7 @@ async fn test_stream_file_post_kind() -> Result<()> { async fn test_stream_file_post_kind_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_F3, POST_F4, POST_F5, POST_F6, POST_F7, POST_F8]; verify_post_list_kind(post_list, body, KIND); @@ -47,7 +47,7 @@ async fn test_stream_file_post_kind_with_start() -> Result<()> { async fn test_stream_file_post_kind_with_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&end={START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_F1, POST_F2]; verify_post_list_kind(post_list, body, KIND); @@ -58,7 +58,7 @@ async fn test_stream_file_post_kind_with_end() -> Result<()> { async fn test_stream_file_post_kind_with_start_and_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}&end={END_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_F3, POST_F4, POST_F5, POST_F6]; verify_post_list_kind(post_list, body, KIND); @@ -69,7 +69,7 @@ async fn test_stream_file_post_kind_with_start_and_end() -> Result<()> { async fn test_stream_file_post_kind_with_author() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_F3, POST_F5, POST_F8]; verify_post_list_kind(post_list, body, KIND); @@ -80,7 +80,7 @@ async fn test_stream_file_post_kind_with_author() -> Result<()> { async fn test_stream_file_post_kind_with_author_skip_and_limit() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author&skip=1&limit=1"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_F5]; verify_post_list_kind(post_list, body, KIND); @@ -93,7 +93,7 @@ async fn test_stream_file_post_kind_with_author_skip_and_limit() -> Result<()> { async fn test_stream_post_kind_followers() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_F1, POST_F2]; verify_post_list_kind(post_list, body, KIND); @@ -106,7 +106,7 @@ const REACH_START_TIMELINE: &str = "1980477299360"; async fn test_stream_post_kind_followers_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_F2]; verify_post_list_kind(post_list, body, KIND); @@ -119,7 +119,7 @@ async fn test_stream_post_kind_followers_with_start() -> Result<()> { async fn test_stream_post_kind_following() -> Result<()> { let path = format!("{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_F3, POST_F4, POST_F5, POST_F6, POST_F7, POST_F8]; verify_post_list_kind(post_list, body, KIND); @@ -132,7 +132,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> { "{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}&start=1980477299325" ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_F5, POST_F6, POST_F7, POST_F8]; verify_post_list_kind(post_list, body, KIND); @@ -145,7 +145,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> { async fn test_stream_post_kind_friends() -> Result<()> { let path = format!("{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_F1, POST_F2]; verify_post_list_kind(post_list, body, KIND); @@ -158,7 +158,7 @@ async fn test_stream_post_kind_friends_with_start() -> Result<()> { "{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}" ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_F2]; verify_post_list_kind(post_list, body, KIND); diff --git a/tests/service/stream/post/kind/image.rs b/tests/service/stream/post/kind/image.rs index 5439b7e0..7d1469df 100644 --- a/tests/service/stream/post/kind/image.rs +++ b/tests/service/stream/post/kind/image.rs @@ -2,7 +2,7 @@ use super::DETROIT; use crate::service::stream::post::utils::verify_post_list_kind; use crate::service::stream::post::ROOT_PATH; use crate::service::stream::post::{AMSTERDAM, BOGOTA}; -use crate::service::utils::make_request; +use crate::service::utils::get_request; use anyhow::Result; const KIND: &str = "image"; @@ -23,7 +23,7 @@ pub const END_TIMELINE: &str = "1820477299308"; async fn test_stream_image_post_kind() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![ POST_I1, POST_I2, POST_I3, POST_I4, POST_I5, POST_I6, POST_I7, POST_I8, ]; @@ -36,7 +36,7 @@ async fn test_stream_image_post_kind() -> Result<()> { async fn test_stream_image_post_kind_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_I3, POST_I4, POST_I5, POST_I6, POST_I7, POST_I8]; verify_post_list_kind(post_list, body, KIND); @@ -47,7 +47,7 @@ async fn test_stream_image_post_kind_with_start() -> Result<()> { async fn test_stream_image_post_kind_with_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&end={START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_I1, POST_I2]; verify_post_list_kind(post_list, body, KIND); @@ -58,7 +58,7 @@ async fn test_stream_image_post_kind_with_end() -> Result<()> { async fn test_stream_image_post_kind_with_start_and_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}&end={END_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_I3, POST_I4, POST_I5, POST_I6]; verify_post_list_kind(post_list, body, KIND); @@ -69,7 +69,7 @@ async fn test_stream_image_post_kind_with_start_and_end() -> Result<()> { async fn test_stream_image_post_kind_with_author() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_I3, POST_I5, POST_I8]; verify_post_list_kind(post_list, body, KIND); @@ -80,7 +80,7 @@ async fn test_stream_image_post_kind_with_author() -> Result<()> { async fn test_stream_image_post_kind_with_author_skip_and_limit() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author&skip=1&limit=1"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_I5]; verify_post_list_kind(post_list, body, KIND); @@ -93,7 +93,7 @@ async fn test_stream_image_post_kind_with_author_skip_and_limit() -> Result<()> async fn test_stream_post_kind_followers() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_I1, POST_I2]; verify_post_list_kind(post_list, body, KIND); @@ -106,7 +106,7 @@ const REACH_START_TIMELINE: &str = "1820477299355"; async fn test_stream_post_kind_followers_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_I2]; verify_post_list_kind(post_list, body, KIND); @@ -119,7 +119,7 @@ async fn test_stream_post_kind_followers_with_start() -> Result<()> { async fn test_stream_post_kind_following() -> Result<()> { let path = format!("{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_I3, POST_I4, POST_I5, POST_I6, POST_I7, POST_I8]; verify_post_list_kind(post_list, body, KIND); @@ -132,7 +132,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> { "{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}&start=1820477299325" ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_I5, POST_I6, POST_I7, POST_I8]; verify_post_list_kind(post_list, body, KIND); @@ -145,7 +145,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> { async fn test_stream_post_kind_friends() -> Result<()> { let path = format!("{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_I1, POST_I2]; verify_post_list_kind(post_list, body, KIND); @@ -158,7 +158,7 @@ async fn test_stream_post_kind_friends_with_start() -> Result<()> { "{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}" ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_I2]; verify_post_list_kind(post_list, body, KIND); diff --git a/tests/service/stream/post/kind/link.rs b/tests/service/stream/post/kind/link.rs index 53ac5277..98501103 100644 --- a/tests/service/stream/post/kind/link.rs +++ b/tests/service/stream/post/kind/link.rs @@ -2,7 +2,7 @@ use super::DETROIT; use crate::service::stream::post::utils::verify_post_list_kind; use crate::service::stream::post::ROOT_PATH; use crate::service::stream::post::{AMSTERDAM, BOGOTA}; -use crate::service::utils::make_request; +use crate::service::utils::get_request; use anyhow::Result; const KIND: &str = "link"; @@ -27,7 +27,7 @@ pub const END_TIMELINE: &str = "1980477299312"; async fn test_stream_link_post_kind() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![ POST_L1, POST_L2, POST_L3, POST_L4, POST_L5, POST_L6, POST_L7, POST_L8, POST_ZERO, POST_PANDA, @@ -41,7 +41,7 @@ async fn test_stream_link_post_kind() -> Result<()> { async fn test_stream_link_post_kind_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![ POST_L3, POST_L4, POST_L5, POST_L6, POST_L7, POST_L8, POST_ZERO, POST_PANDA, POST_YT, POST_PK, @@ -55,7 +55,7 @@ async fn test_stream_link_post_kind_with_start() -> Result<()> { async fn test_stream_link_post_kind_with_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&end={START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L1, POST_L2]; verify_post_list_kind(post_list, body, KIND); @@ -66,7 +66,7 @@ async fn test_stream_link_post_kind_with_end() -> Result<()> { async fn test_stream_link_post_kind_with_start_and_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}&end={END_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L3, POST_L4, POST_L5, POST_L6]; verify_post_list_kind(post_list, body, KIND); @@ -77,7 +77,7 @@ async fn test_stream_link_post_kind_with_start_and_end() -> Result<()> { async fn test_stream_link_post_kind_with_author() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L3, POST_L5, POST_L8]; verify_post_list_kind(post_list, body, KIND); @@ -88,7 +88,7 @@ async fn test_stream_link_post_kind_with_author() -> Result<()> { async fn test_stream_link_post_kind_with_author_skip_and_limit() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author&skip=1&limit=1"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L5]; verify_post_list_kind(post_list, body, KIND); @@ -101,7 +101,7 @@ async fn test_stream_link_post_kind_with_author_skip_and_limit() -> Result<()> { async fn test_stream_post_kind_followers() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L1, POST_L2]; verify_post_list_kind(post_list, body, KIND); @@ -114,7 +114,7 @@ const REACH_START_TIMELINE: &str = "1980477299360"; async fn test_stream_post_kind_followers_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L2]; verify_post_list_kind(post_list, body, KIND); @@ -127,7 +127,7 @@ async fn test_stream_post_kind_followers_with_start() -> Result<()> { async fn test_stream_post_kind_following() -> Result<()> { let path = format!("{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L3, POST_L4, POST_L5, POST_L6, POST_L7, POST_L8]; verify_post_list_kind(post_list, body, KIND); @@ -140,7 +140,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> { "{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}&start=1980477299330" ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L5, POST_L6, POST_L7, POST_L8]; verify_post_list_kind(post_list, body, KIND); @@ -153,7 +153,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> { async fn test_stream_post_kind_friends() -> Result<()> { let path = format!("{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L1, POST_L2]; verify_post_list_kind(post_list, body, KIND); @@ -166,7 +166,7 @@ async fn test_stream_post_kind_friends_with_start() -> Result<()> { "{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}" ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L2]; verify_post_list_kind(post_list, body, KIND); diff --git a/tests/service/stream/post/kind/long.rs b/tests/service/stream/post/kind/long.rs index 8b50adb1..ac5c18dc 100644 --- a/tests/service/stream/post/kind/long.rs +++ b/tests/service/stream/post/kind/long.rs @@ -2,7 +2,7 @@ use super::DETROIT; use crate::service::stream::post::utils::verify_post_list_kind; use crate::service::stream::post::ROOT_PATH; use crate::service::stream::post::{AMSTERDAM, BOGOTA}; -use crate::service::utils::make_request; +use crate::service::utils::get_request; use anyhow::Result; const KIND: &str = "long"; @@ -23,7 +23,7 @@ pub const END_TIMELINE: &str = "1819477230308"; async fn test_stream_long_post_kind() -> Result<()> { let path = format!("{ROOT_PATH}?kind=long"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![ POST_L1, POST_L2, POST_L3, POST_L4, POST_L5, POST_L6, POST_L7, POST_L8, ]; @@ -36,7 +36,7 @@ async fn test_stream_long_post_kind() -> Result<()> { async fn test_stream_long_post_kind_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?kind=long&start={START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L3, POST_L4, POST_L5, POST_L6, POST_L7, POST_L8]; verify_post_list_kind(post_list, body, KIND); @@ -47,7 +47,7 @@ async fn test_stream_long_post_kind_with_start() -> Result<()> { async fn test_stream_long_post_kind_with_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind=long&end={START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L1, POST_L2]; verify_post_list_kind(post_list, body, KIND); @@ -58,7 +58,7 @@ async fn test_stream_long_post_kind_with_end() -> Result<()> { async fn test_stream_long_post_kind_with_start_and_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind=long&start={START_TIMELINE}&end={END_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L3, POST_L4, POST_L5, POST_L6]; verify_post_list_kind(post_list, body, KIND); @@ -69,7 +69,7 @@ async fn test_stream_long_post_kind_with_start_and_end() -> Result<()> { async fn test_stream_long_post_kind_with_author() -> Result<()> { let path = format!("{ROOT_PATH}?kind=long&author_id={BOGOTA}&source=author"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L3, POST_L5, POST_L8]; verify_post_list_kind(post_list, body, KIND); @@ -80,7 +80,7 @@ async fn test_stream_long_post_kind_with_author() -> Result<()> { async fn test_stream_long_post_kind_with_author_skip_and_limit() -> Result<()> { let path = format!("{ROOT_PATH}?kind=long&author_id={BOGOTA}&source=author&skip=1&limit=1"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L5]; verify_post_list_kind(post_list, body, KIND); @@ -93,7 +93,7 @@ async fn test_stream_long_post_kind_with_author_skip_and_limit() -> Result<()> { async fn test_stream_post_kind_followers() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L1, POST_L2]; verify_post_list_kind(post_list, body, KIND); @@ -106,7 +106,7 @@ const REACH_START_TIMELINE: &str = "1819477230355"; async fn test_stream_post_kind_followers_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L2]; verify_post_list_kind(post_list, body, KIND); @@ -119,7 +119,7 @@ async fn test_stream_post_kind_followers_with_start() -> Result<()> { async fn test_stream_post_kind_following() -> Result<()> { let path = format!("{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L3, POST_L4, POST_L5, POST_L6, POST_L7, POST_L8]; verify_post_list_kind(post_list, body, KIND); @@ -132,7 +132,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> { "{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}&start=1819477230325" ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L5, POST_L6, POST_L7, POST_L8]; verify_post_list_kind(post_list, body, KIND); @@ -145,7 +145,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> { async fn test_stream_post_kind_friends() -> Result<()> { let path = format!("{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L1, POST_L2]; verify_post_list_kind(post_list, body, KIND); @@ -158,7 +158,7 @@ async fn test_stream_post_kind_friends_with_start() -> Result<()> { "{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}" ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_L2]; verify_post_list_kind(post_list, body, KIND); diff --git a/tests/service/stream/post/kind/video.rs b/tests/service/stream/post/kind/video.rs index 0d3a75bc..6a649414 100644 --- a/tests/service/stream/post/kind/video.rs +++ b/tests/service/stream/post/kind/video.rs @@ -2,7 +2,7 @@ use super::DETROIT; use crate::service::stream::post::utils::verify_post_list_kind; use crate::service::stream::post::ROOT_PATH; use crate::service::stream::post::{AMSTERDAM, BOGOTA}; -use crate::service::utils::make_request; +use crate::service::utils::get_request; use anyhow::Result; const KIND: &str = "video"; @@ -23,7 +23,7 @@ pub const END_TIMELINE: &str = "1980477299308"; async fn test_stream_video_post_kind() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![ POST_V1, POST_V2, POST_V3, POST_V4, POST_V5, POST_V6, POST_V7, POST_V8, ]; @@ -36,7 +36,7 @@ async fn test_stream_video_post_kind() -> Result<()> { async fn test_stream_video_post_kind_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_V3, POST_V4, POST_V5, POST_V6, POST_V7, POST_V8]; verify_post_list_kind(post_list, body, KIND); @@ -47,7 +47,7 @@ async fn test_stream_video_post_kind_with_start() -> Result<()> { async fn test_stream_video_post_kind_with_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&end={START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_V1, POST_V2]; verify_post_list_kind(post_list, body, KIND); @@ -58,7 +58,7 @@ async fn test_stream_video_post_kind_with_end() -> Result<()> { async fn test_stream_video_post_kind_with_start_and_end() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}&end={END_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_V3, POST_V4, POST_V5, POST_V6]; verify_post_list_kind(post_list, body, KIND); @@ -69,7 +69,7 @@ async fn test_stream_video_post_kind_with_start_and_end() -> Result<()> { async fn test_stream_video_post_kind_with_author() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_V3, POST_V5, POST_V8]; verify_post_list_kind(post_list, body, KIND); @@ -80,7 +80,7 @@ async fn test_stream_video_post_kind_with_author() -> Result<()> { async fn test_stream_video_post_kind_with_author_skip_and_limit() -> Result<()> { let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author&skip=1&limit=1"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_V5]; verify_post_list_kind(post_list, body, KIND); @@ -93,7 +93,7 @@ async fn test_stream_video_post_kind_with_author_skip_and_limit() -> Result<()> async fn test_stream_post_kind_followers() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_V1, POST_V2]; verify_post_list_kind(post_list, body, KIND); @@ -106,7 +106,7 @@ const REACH_START_TIMELINE: &str = "1980477299355"; async fn test_stream_post_kind_followers_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_V2]; verify_post_list_kind(post_list, body, KIND); @@ -119,7 +119,7 @@ async fn test_stream_post_kind_followers_with_start() -> Result<()> { async fn test_stream_post_kind_following() -> Result<()> { let path = format!("{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_V3, POST_V4, POST_V5, POST_V6, POST_V7, POST_V8]; verify_post_list_kind(post_list, body, KIND); @@ -132,7 +132,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> { "{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}&start=1980477299325" ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_V5, POST_V6, POST_V7, POST_V8]; verify_post_list_kind(post_list, body, KIND); @@ -145,7 +145,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> { async fn test_stream_post_kind_friends() -> Result<()> { let path = format!("{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_V1, POST_V2]; verify_post_list_kind(post_list, body, KIND); @@ -158,7 +158,7 @@ async fn test_stream_post_kind_friends_with_start() -> Result<()> { "{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}" ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_V2]; verify_post_list_kind(post_list, body, KIND); diff --git a/tests/service/stream/post/mod.rs b/tests/service/stream/post/mod.rs index 03c1499e..76641c18 100644 --- a/tests/service/stream/post/mod.rs +++ b/tests/service/stream/post/mod.rs @@ -6,6 +6,7 @@ pub mod bookmarks; pub mod kind; pub mod post_replies; pub mod posts; +pub mod reach; pub mod tags; pub mod utils; diff --git a/tests/service/stream/post/post_replies.rs b/tests/service/stream/post/post_replies.rs index 95066329..702534c2 100644 --- a/tests/service/stream/post/post_replies.rs +++ b/tests/service/stream/post/post_replies.rs @@ -1,4 +1,4 @@ -use crate::service::utils::make_request; +use crate::service::utils::get_request; use anyhow::Result; use pubky_nexus::models::post::{PostStream, PostView}; @@ -21,7 +21,7 @@ async fn test_stream_posts_replies() -> Result<()> { "{ROOT_PATH}?source=post_replies&author_id={}&post_id={}", AUTHOR_ID, PARENT_POST_ID ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); // Deserialize the response body into a PostStream object @@ -55,7 +55,7 @@ async fn test_stream_posts_replies_with_limit() -> Result<()> { "{ROOT_PATH}?source=post_replies&author_id={}&post_id={}&limit=3", AUTHOR_ID, PARENT_POST_ID ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); // Deserialize the response body into a PostStream object @@ -82,7 +82,7 @@ async fn test_stream_posts_replies_with_start_query() -> Result<()> { "{ROOT_PATH}?source=post_replies&author_id={}&post_id={}&start=1719477230025", AUTHOR_ID, PARENT_POST_ID ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); // Deserialize the response body into a PostStream object @@ -109,7 +109,7 @@ async fn test_stream_posts_replies_with_end_query() -> Result<()> { "{ROOT_PATH}?source=post_replies&author_id={}&post_id={}&end=1719477230060", AUTHOR_ID, PARENT_POST_ID ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); // Deserialize the response body into a PostStream object @@ -136,7 +136,7 @@ async fn test_stream_posts_replies_with_start_and_end_query() -> Result<()> { "{ROOT_PATH}?source=post_replies&author_id={}&post_id={}&start=1719477230150&end=1719477230017", AUTHOR_ID, PARENT_POST_ID ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); // Deserialize the response body into a PostStream object @@ -168,7 +168,7 @@ async fn test_stream_posts_replies_with_start_and_end_also_limit_query() -> Resu "{ROOT_PATH}?source=post_replies&author_id={}&post_id={}&start=1719477230150&end=1719477230017&limit=3", AUTHOR_ID, PARENT_POST_ID ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); // Deserialize the response body into a PostStream object diff --git a/tests/service/stream/post/posts.rs b/tests/service/stream/post/posts.rs index 61d0fef6..21897c66 100644 --- a/tests/service/stream/post/posts.rs +++ b/tests/service/stream/post/posts.rs @@ -1,6 +1,7 @@ -use crate::service::utils::{make_request, make_wrong_request}; +use crate::service::utils::{get_request, invalid_get_request}; use anyhow::Result; use pubky_nexus::models::post::PostStream; +use reqwest::StatusCode; use super::utils::{search_tag_in_post, verify_post_list, verify_timeline_post_list}; use super::{POST_A, POST_B, POST_C, POST_F, POST_G, POST_H}; @@ -24,7 +25,7 @@ pub const START_TIMELINE: &str = "1722261385301"; #[tokio_shared_rt::test(shared)] async fn test_stream_posts_global_timeline() -> Result<()> { let path = format!("{ROOT_PATH}?sorting=timeline"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -46,7 +47,7 @@ async fn test_stream_posts_global_timeline() -> Result<()> { async fn test_stream_posts_global_timeline_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?sorting=timeline&start={START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![ POST_TA, POST_TB, POST_TC, POST_TD, POST_TE, POST_TF, POST_TG, POST_TH, POST_TI, POST_TJ, ]; @@ -60,7 +61,7 @@ async fn test_stream_posts_global_timeline_with_start() -> Result<()> { async fn test_stream_posts_global_timeline_with_start_and_limit() -> Result<()> { let path = format!("{ROOT_PATH}?sorting=timeline&start={START_TIMELINE}&limit=5"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_TA, POST_TB, POST_TC, POST_TD, POST_TE]; verify_timeline_post_list(post_list, body); @@ -72,7 +73,7 @@ async fn test_stream_posts_global_timeline_with_start_and_limit() -> Result<()> async fn test_stream_posts_global_timeline_with_start_and_limit_and_skip() -> Result<()> { let path = format!("{ROOT_PATH}?sorting=timeline&start={START_TIMELINE}&skip=3&limit=5"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_TD, POST_TE, POST_TF, POST_TG, POST_TH]; verify_timeline_post_list(post_list, body); @@ -83,7 +84,7 @@ async fn test_stream_posts_global_timeline_with_start_and_limit_and_skip() -> Re #[tokio_shared_rt::test(shared)] async fn test_stream_posts_global_total_engagement() -> Result<()> { let path = format!("{ROOT_PATH}?sorting=total_engagement"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -138,7 +139,7 @@ async fn test_stream_posts_global_total_engagement_with_start_score() -> Result< ROOT_PATH, ENGAGEMENT_SCORE ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![ POST_EA, POST_EB, POST_EC, POST_ED, POST_EF, POST_EG, POST_EH, POST_EI, POST_EJ, POST_EK, ]; @@ -155,7 +156,7 @@ async fn test_stream_posts_global_total_engagement_with_start_end_score() -> Res ROOT_PATH, ENGAGEMENT_SCORE, ENGAGEMENT_SCORE ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_EA, POST_EB, POST_EC]; verify_post_list(post_list, body); @@ -170,7 +171,7 @@ async fn test_stream_posts_global_total_engagement_with_end_score() -> Result<() ROOT_PATH, ENGAGEMENT_SCORE ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_00, POST_E0, POST_E1, POST_EA, POST_EB, POST_EC]; verify_post_list(post_list, body); @@ -186,7 +187,7 @@ async fn test_post_tag_search_by_engagement() -> Result<()> { ROOT_PATH, TAG_LABEL_2 ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); let tags = body.as_array().expect("Stream tags should be an array"); @@ -205,7 +206,7 @@ async fn test_post_tag_search_by_engagement_with_skip() -> Result<()> { "{}?tags={}&sorting=total_engagement&skip=6", ROOT_PATH, TAG_LABEL_2 ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -227,7 +228,7 @@ async fn test_post_tag_search_by_engagement_with_skip_and_limit() -> Result<()> "{}?tags={}&sorting=total_engagement&skip=1&limit=1", ROOT_PATH, TAG_LABEL_2 ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -252,7 +253,7 @@ async fn test_stream_combined_parameters() -> Result<()> { observer_id, tag ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; // Deserialize the response body into a PostStream object let post_stream: PostStream = serde_json::from_value(body)?; @@ -278,7 +279,7 @@ async fn test_stream_combined_parameters() -> Result<()> { async fn test_stream_invalid_sorting() -> Result<()> { // Invalid sorting option should fail let endpoint = "/v0/stream/posts?sorting=invalid"; - make_wrong_request(endpoint, Some(400)).await?; + invalid_get_request(endpoint, StatusCode::BAD_REQUEST).await?; Ok(()) } diff --git a/tests/service/stream/post/reach/engagement.rs b/tests/service/stream/post/reach/engagement.rs index e96155b4..4d73e87e 100644 --- a/tests/service/stream/post/reach/engagement.rs +++ b/tests/service/stream/post/reach/engagement.rs @@ -1,7 +1,9 @@ use super::utils::test_reach_filter_with_posts; +use crate::service::stream::post::TAG_LABEL_2; use crate::service::stream::post::{AMSTERDAM, BOGOTA, ROOT_PATH}; -use crate::service::{stream::post::TAG_LABEL_2, utils::make_wrong_request}; +use crate::service::utils::invalid_get_request; use anyhow::Result; +use reqwest::StatusCode; // ›››››› THE BELLOW REQUESTS HITS THE GRAPH ‹‹‹‹‹‹‹ @@ -248,7 +250,7 @@ async fn test_stream_posts_by_engagement_reach_friends_with_tag() -> Result<()> #[tokio_shared_rt::test(shared)] async fn test_stream_not_found_posts_by_engagement_reach_friends_with_tag() -> Result<()> { let path = format!("{ROOT_PATH}?sorting=total_engagement&tags=opensource&source=friends&observer_id={EIXAMPLE}&skip=2"); - make_wrong_request(&path, Some(404)).await?; + invalid_get_request(&path, StatusCode::NOT_FOUND).await?; Ok(()) } diff --git a/tests/service/stream/post/reach/timeline.rs b/tests/service/stream/post/reach/timeline.rs index dc3ece8b..d3037516 100644 --- a/tests/service/stream/post/reach/timeline.rs +++ b/tests/service/stream/post/reach/timeline.rs @@ -1,12 +1,15 @@ use super::utils::test_reach_filter_with_posts; -use crate::service::stream::post::{AMSTERDAM, BOGOTA, ROOT_PATH, TAG_LABEL_2, USER_ID}; -use crate::service::utils::{make_request, make_wrong_request}; +use crate::service::{ + stream::post::{AMSTERDAM, BOGOTA, ROOT_PATH, TAG_LABEL_2, USER_ID}, + utils::{get_request, invalid_get_request}, +}; use anyhow::Result; +use reqwest::StatusCode; #[tokio_shared_rt::test(shared)] async fn test_stream_posts_following() -> Result<()> { let path = format!("{ROOT_PATH}?observer_id={}&source=following", USER_ID); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -23,7 +26,7 @@ async fn test_stream_posts_following() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_stream_posts_followers() -> Result<()> { let path = format!("{ROOT_PATH}?observer_id={}&source=followers", USER_ID); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -284,7 +287,7 @@ async fn test_stream_not_found_posts_by_timeline_reach_friends_with_tag() -> Res let path = format!( "{ROOT_PATH}?sorting=timeline&tags=opensource&source=friends&observer_id={EIXAMPLE}&skip=2" ); - make_wrong_request(&path, Some(404)).await?; + invalid_get_request(&path, StatusCode::NOT_FOUND).await?; Ok(()) } diff --git a/tests/service/stream/post/reach/utils.rs b/tests/service/stream/post/reach/utils.rs index c9b54fe2..a7367823 100644 --- a/tests/service/stream/post/reach/utils.rs +++ b/tests/service/stream/post/reach/utils.rs @@ -1,6 +1,6 @@ use crate::service::stream::post::utils::{verify_post_list, verify_timeline_post_list}; use crate::service::stream::post::ROOT_PATH; -use crate::service::utils::make_request; +use crate::service::utils::get_request; use anyhow::Result; // Test all the reach endpoints that hits the graph @@ -41,7 +41,7 @@ pub async fn test_reach_filter_with_posts( println!("PATH: {:?}", path); - let body = make_request(&path).await?; + let body = get_request(&path).await?; if verify_timeline { verify_timeline_post_list(expected_posts.to_vec(), body); diff --git a/tests/service/stream/post/tags.rs b/tests/service/stream/post/tags.rs index 2b075259..45b265e4 100644 --- a/tests/service/stream/post/tags.rs +++ b/tests/service/stream/post/tags.rs @@ -1,6 +1,7 @@ -use crate::service::utils::{make_request, make_wrong_request}; +use crate::service::utils::{get_request, invalid_get_request}; use anyhow::Result; use pubky_nexus::models::post::PostStream; +use reqwest::StatusCode; use super::utils::{search_tag_in_post, verify_post_list, verify_timeline_post_list}; use super::{POST_A, POST_B, POST_C, POST_D, POST_E, POST_F, POST_G, POST_H}; @@ -11,7 +12,7 @@ use super::{TAG_LABEL_1, TAG_LABEL_2, TAG_LABEL_3, TAG_LABEL_4}; async fn test_post_tag_search() -> Result<()> { let post_order = vec![POST_C, POST_B, POST_A, POST_D, POST_E, POST_F]; let path = format!("{}?tags={}&limit=6", ROOT_PATH, TAG_LABEL_2); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -30,7 +31,7 @@ async fn test_post_tag_search() -> Result<()> { async fn test_post_tag_search_with_limit() -> Result<()> { let post_order = vec![POST_C, POST_B]; let path = format!("{}?tags={}&limit=2", ROOT_PATH, TAG_LABEL_2); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -49,7 +50,7 @@ async fn test_post_tag_search_with_limit() -> Result<()> { async fn test_post_tag_search_with_skip() -> Result<()> { let post_order = vec![POST_G, POST_H]; let path = format!("{}?tags={}&skip=6", ROOT_PATH, TAG_LABEL_2); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -68,7 +69,7 @@ async fn test_post_tag_search_with_skip() -> Result<()> { async fn test_post_tag_search_with_skip_and_limit() -> Result<()> { let post_order = vec![POST_B]; let path = format!("{}?tags={}&skip=1&limit=1", ROOT_PATH, TAG_LABEL_2); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -88,7 +89,7 @@ async fn test_post_tag_search_with_viewer_id() -> Result<()> { const BOOKMARK_ID: &str = "A9G7F2L4Q1W3"; let path = format!("{}?tags={}&viewer_id={}", ROOT_PATH, TAG_LABEL_2, VIEWER_ID); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -105,7 +106,7 @@ async fn test_post_tag_search_with_viewer_id() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_stream_posts_by_tag() -> Result<()> { let path = format!("{ROOT_PATH}?tags={}&sorting=timeline", TAG_LABEL_1); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -150,7 +151,7 @@ pub const END_TIMELINE: &str = "1719231303114"; async fn test_stream_posts_by_tag_timeline_with_start() -> Result<()> { let path = format!("{ROOT_PATH}?tags={TAG_LABEL_1}&sorting=timeline&start={START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![ POST_TD, POST_TE, POST_TF, POST_TG, POST_TH, POST_TI, POST_TJ, POST_TK, POST_TL, POST_TM, ]; @@ -166,7 +167,7 @@ async fn test_stream_posts_by_tag_timeline_with_start_and_end() -> Result<()> { "{ROOT_PATH}?tags={TAG_LABEL_1}&sorting=timeline&start={START_TIMELINE}&end={END_TIMELINE}" ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_TD, POST_TE, POST_TF, POST_TG, POST_TH, POST_TI]; verify_timeline_post_list(post_list, body); @@ -178,7 +179,7 @@ async fn test_stream_posts_by_tag_timeline_with_start_and_end() -> Result<()> { async fn test_stream_posts_by_tag_timeline_with_end() -> Result<()> { let path = format!("{ROOT_PATH}?tags={TAG_LABEL_1}&sorting=timeline&end={START_TIMELINE}"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_TA, POST_TB, POST_TC]; verify_timeline_post_list(post_list, body); @@ -191,7 +192,7 @@ async fn test_stream_posts_by_tag_timeline_with_end_and_skip() -> Result<()> { let path = format!("{ROOT_PATH}?tags={TAG_LABEL_1}&sorting=timeline&end={START_TIMELINE}&skip=2"); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_TC]; verify_timeline_post_list(post_list, body); @@ -205,7 +206,7 @@ async fn test_stream_posts_by_tag_timeline_with_start_skip_and_limit() -> Result "{ROOT_PATH}?tags={TAG_LABEL_1}&sorting=timeline&start={START_TIMELINE}&skip=2&limit=5" ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_TF, POST_TG, POST_TH, POST_TI, POST_TJ]; verify_timeline_post_list(post_list, body); @@ -219,7 +220,7 @@ async fn test_stream_posts_by_multiple_tags() -> Result<()> { "{ROOT_PATH}?tags={},{},{}&sorting=timeline&limit=30", TAG_LABEL_2, TAG_LABEL_3, TAG_LABEL_4 ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -271,7 +272,7 @@ pub const ENGAGEMENT_SCORE_END: &str = "4"; async fn test_stream_tag_posts_by_engagment_tag() -> Result<()> { let path = format!("{ROOT_PATH}?tags={}&sorting=total_engagement", TAG_LABEL_1); - let body = make_request(&path).await?; + let body = get_request(&path).await?; // Deserialize the response body into a PostStream object let post_stream: PostStream = serde_json::from_value(body)?; @@ -299,7 +300,7 @@ async fn test_stream_tag_posts_by_engagement_with_start() -> Result<()> { ROOT_PATH, TAG_LABEL_1, ENGAGEMENT_SCORE_START ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![ POST_EB, POST_EC, POST_ED, POST_EE, POST_EF, POST_EG, POST_EH, POST_EI, POST_EJ, POST_EK, ]; @@ -316,7 +317,7 @@ async fn test_stream_tag_posts_by_engagement_with_start_and_end() -> Result<()> ROOT_PATH, TAG_LABEL_1, ENGAGEMENT_SCORE_START, ENGAGEMENT_SCORE_END ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_EB, POST_EC, POST_ED, POST_EE, POST_EF, POST_EG]; verify_post_list(post_list, body); @@ -331,7 +332,7 @@ async fn test_stream_tag_posts_by_engagement_with_start_and_limit() -> Result<() ROOT_PATH, TAG_LABEL_1, ENGAGEMENT_SCORE_END ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_ED, POST_EE, POST_EF, POST_EG, POST_EH, POST_EI]; verify_post_list(post_list, body); @@ -346,7 +347,7 @@ async fn test_stream_tag_posts_by_engagement_with_end_skip_and_limit() -> Result ROOT_PATH, TAG_LABEL_1, ENGAGEMENT_SCORE_END ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let post_list = vec![POST_ED, POST_EE, POST_EF, POST_EG]; verify_post_list(post_list, body); @@ -357,7 +358,7 @@ async fn test_stream_tag_posts_by_engagement_with_end_skip_and_limit() -> Result #[tokio_shared_rt::test(shared)] async fn test_post_specific_tag_with_no_result() -> Result<()> { let path = format!("{}?tags={}", ROOT_PATH, "randommm"); - make_wrong_request(&path, None).await?; + invalid_get_request(&path, StatusCode::NOT_FOUND).await?; Ok(()) } diff --git a/tests/service/stream/user/list.rs b/tests/service/stream/user/list.rs index c3bb7394..9518a36b 100644 --- a/tests/service/stream/user/list.rs +++ b/tests/service/stream/user/list.rs @@ -1,13 +1,12 @@ -use crate::service::utils::HOST_URL; +use crate::service::utils::{invalid_post_request, post_request}; use anyhow::Result; +use reqwest::StatusCode; use serde_json::json; // ##### LIST OF USERS BY ID ###### #[tokio_shared_rt::test(shared)] async fn test_stream_users_by_ids_valid_request() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - // List of valid user IDs let user_ids = vec![ "4snwyct86m383rsduhw5xgcxpw7c63j3pq8x4ycqikxgik8y64ro", @@ -22,16 +21,11 @@ async fn test_stream_users_by_ids_valid_request() -> Result<()> { }); // Send the POST request to the endpoint - let res = client - .do_post("/v0/stream/users/by_ids", request_body) - .await?; - - assert_eq!(res.status(), 200, "Expected HTTP status 200 OK"); + let res = post_request("/v0/stream/users/by_ids", request_body).await?; - let body = res.json_body()?; - assert!(body.is_array(), "Response body should be an array"); + assert!(res.is_array(), "Response body should be an array"); - let users = body.as_array().expect("User stream should be an array"); + let users = res.as_array().expect("User stream should be an array"); // Check if the response has the expected number of users assert_eq!(users.len(), 3, "Expected 3 users in the response"); @@ -59,8 +53,6 @@ async fn test_stream_users_by_ids_valid_request() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_stream_users_by_ids_limit_exceeded() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - // Generate a list of 1001 user IDs to exceed the limit let mut user_ids = Vec::with_capacity(1001); for i in 0..1001 { @@ -73,20 +65,18 @@ async fn test_stream_users_by_ids_limit_exceeded() -> Result<()> { }); // Send the POST request to the endpoint - let res = client - .do_post("/v0/stream/users/by_ids", request_body) - .await?; - - // Expecting a 400 Bad Request due to exceeding the limit - assert_eq!(res.status(), 400, "Expected HTTP status 400 Bad Request"); + invalid_post_request( + "/v0/stream/users/by_ids", + request_body, + StatusCode::BAD_REQUEST, + ) + .await?; Ok(()) } #[tokio_shared_rt::test(shared)] async fn test_stream_users_by_ids_with_invalid_ids() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - // Valid and invalid user IDs let user_ids = vec![ "4snwyct86m383rsduhw5xgcxpw7c63j3pq8x4ycqikxgik8y64ro", // Valid @@ -99,17 +89,11 @@ async fn test_stream_users_by_ids_with_invalid_ids() -> Result<()> { "viewer_id": null }); - let res = client - .do_post("/v0/stream/users/by_ids", request_body) - .await?; + let res = post_request("/v0/stream/users/by_ids", request_body).await?; - // Assuming the endpoint returns 200 OK with valid users only - assert_eq!(res.status(), 200, "Expected HTTP status 200 OK"); + assert!(res.is_array(), "Response body should be an array"); - let body = res.json_body()?; - assert!(body.is_array(), "Response body should be an array"); - - let users = body.as_array().expect("User stream should be an array"); + let users = res.as_array().expect("User stream should be an array"); // Expected valid user IDs let expected_user_ids = vec![ @@ -135,8 +119,6 @@ async fn test_stream_users_by_ids_with_invalid_ids() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_stream_users_by_ids_empty_list() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - // Empty list of user IDs let user_ids: Vec = Vec::new(); @@ -145,16 +127,15 @@ async fn test_stream_users_by_ids_empty_list() -> Result<()> { "viewer_id": null }); - let res = client - .do_post("/v0/stream/users/by_ids", request_body) - .await?; - - // Expecting a 400 Bad Request due to empty user_ids list - assert_eq!(res.status(), 400, "Expected HTTP status 400 Bad Request"); + let res = invalid_post_request( + "/v0/stream/users/by_ids", + request_body, + StatusCode::BAD_REQUEST, + ) + .await?; - let body = res.json_body()?; assert!( - body["error"].as_str().unwrap_or("").contains("empty"), + res["error"].as_str().unwrap_or("").contains("empty"), "Error message should mention that user_ids cannot be empty" ); @@ -163,8 +144,6 @@ async fn test_stream_users_by_ids_empty_list() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_stream_users_by_ids_with_viewer_id() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - // List of valid user IDs let user_ids = vec![ "4snwyct86m383rsduhw5xgcxpw7c63j3pq8x4ycqikxgik8y64ro", @@ -178,16 +157,11 @@ async fn test_stream_users_by_ids_with_viewer_id() -> Result<()> { "viewer_id": viewer_id }); - let res = client - .do_post("/v0/stream/users/by_ids", request_body) - .await?; - - assert_eq!(res.status(), 200, "Expected HTTP status 200 OK"); + let res = post_request("/v0/stream/users/by_ids", request_body).await?; - let body = res.json_body()?; - assert!(body.is_array(), "Response body should be an array"); + assert!(res.is_array(), "Response body should be an array"); - let users = body.as_array().expect("User stream should be an array"); + let users = res.as_array().expect("User stream should be an array"); // Check that the correct number of users is returned assert_eq!( diff --git a/tests/service/stream/user/reach.rs b/tests/service/stream/user/reach.rs index f611f5ac..de997fad 100644 --- a/tests/service/stream/user/reach.rs +++ b/tests/service/stream/user/reach.rs @@ -1,23 +1,18 @@ -use crate::service::utils::HOST_URL; +use crate::service::utils::{get_request, invalid_get_request}; use anyhow::Result; +use reqwest::StatusCode; #[tokio_shared_rt::test(shared)] async fn test_stream_following() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - let user_id = "4snwyct86m383rsduhw5xgcxpw7c63j3pq8x4ycqikxgik8y64ro"; - let res = client - .do_get(&format!( - "/v0/stream/users?user_id={}&source=following&limit=20", - user_id - )) - .await?; - assert_eq!(res.status(), 200); - - let body = res.json_body()?; - assert!(body.is_array()); + let res = get_request(&format!( + "/v0/stream/users?user_id={}&source=following&limit=20", + user_id + )) + .await?; + assert!(res.is_array()); - let following = body.as_array().expect("User stream should be an array"); + let following = res.as_array().expect("User stream should be an array"); // Check if the user is following the expected number of users assert_eq!(following.len(), 15, "Unexpected number of users followed"); @@ -52,13 +47,14 @@ async fn test_stream_following() -> Result<()> { } // Test non-existing user - let res = client - .do_get(&format!( + invalid_get_request( + &format!( "/v0/stream/users?user_id={}&source=following", "bad_user_id" - )) - .await?; - assert_eq!(res.status(), 404); + ), + StatusCode::NOT_FOUND, + ) + .await?; Ok(()) } diff --git a/tests/service/stream/user/score.rs b/tests/service/stream/user/score.rs index f4101aaa..a8ce77c8 100644 --- a/tests/service/stream/user/score.rs +++ b/tests/service/stream/user/score.rs @@ -1,22 +1,16 @@ -use crate::service::utils::HOST_URL; +use crate::service::utils::{get_request, invalid_get_request}; use anyhow::Result; +use reqwest::StatusCode; // ##### MOST FOLLOWED USERS ###### #[tokio_shared_rt::test(shared)] async fn test_stream_most_followed() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - // Test retrieving the most followed users - let res = client - .do_get("/v0/stream/users?source=most_followed&limit=20") - .await?; - assert_eq!(res.status(), 200); - - let body = res.json_body()?; - assert!(body.is_array()); + let res = get_request("/v0/stream/users?source=most_followed&limit=20").await?; + assert!(res.is_array()); - let most_followed_users = body.as_array().expect("User stream should be an array"); + let most_followed_users = res.as_array().expect("User stream should be an array"); // Check if the response has the expected number of users assert!( @@ -55,15 +49,10 @@ async fn test_stream_most_followed() -> Result<()> { } // Test limiting the results to 5 users - let res = client - .do_get("/v0/stream/users?source=most_followed&limit=5") - .await?; - assert_eq!(res.status(), 200); + let res = get_request("/v0/stream/users?source=most_followed&limit=5").await?; + assert!(res.is_array()); - let body = res.json_body()?; - assert!(body.is_array()); - - let limited_users = body.as_array().expect("User stream should be an array"); + let limited_users = res.as_array().expect("User stream should be an array"); // Check if the response has the expected number of users assert_eq!( @@ -79,16 +68,12 @@ async fn test_stream_most_followed() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_stream_pioneers() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - // Test retrieving the most followed users - let res = client.do_get("/v0/stream/users?source=pioneers").await?; - assert_eq!(res.status(), 200); + let res = get_request("/v0/stream/users?source=pioneers").await?; - let body = res.json_body()?; - assert!(body.is_array()); + assert!(res.is_array()); - let pioneers_users = body.as_array().expect("User stream should be an array"); + let pioneers_users = res.as_array().expect("User stream should be an array"); // Check if the response has the expected number of users assert!( @@ -125,15 +110,11 @@ async fn test_stream_pioneers() -> Result<()> { } // Test limiting the results to 5 users - let res = client - .do_get("/v0/stream/users?source=pioneers&limit=5") - .await?; - assert_eq!(res.status(), 200); + let res = get_request("/v0/stream/users?source=pioneers&limit=5").await?; - let body = res.json_body()?; - assert!(body.is_array()); + assert!(res.is_array()); - let limited_users = body.as_array().expect("User stream should be an array"); + let limited_users = res.as_array().expect("User stream should be an array"); // Check if the response has the expected number of users assert_eq!( @@ -149,24 +130,19 @@ async fn test_stream_pioneers() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_stream_recommended() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - // User ID to use for recommendations let user_id = "4snwyct86m383rsduhw5xgcxpw7c63j3pq8x4ycqikxgik8y64ro"; // Test retrieving recommended users - let res = client - .do_get(&format!( - "/v0/stream/users?source=recommended&user_id={}&limit=5", - user_id - )) - .await?; - assert_eq!(res.status(), 200); + let res = get_request(&format!( + "/v0/stream/users?source=recommended&user_id={}&limit=5", + user_id + )) + .await?; - let body = res.json_body()?; - assert!(body.is_array()); + assert!(res.is_array()); - let recommended_users = body.as_array().expect("User stream should be an array"); + let recommended_users = res.as_array().expect("User stream should be an array"); // Check if the response has the expected number of users assert!( @@ -195,18 +171,15 @@ async fn test_stream_recommended() -> Result<()> { } // Test limiting the results to 3 users - let res = client - .do_get(&format!( - "/v0/stream/users?source=recommended&user_id={}&limit=3", - user_id - )) - .await?; - assert_eq!(res.status(), 200); + let res = get_request(&format!( + "/v0/stream/users?source=recommended&user_id={}&limit=3", + user_id + )) + .await?; - let body = res.json_body()?; - assert!(body.is_array()); + assert!(res.is_array()); - let limited_users = body.as_array().expect("User stream should be an array"); + let limited_users = res.as_array().expect("User stream should be an array"); // Check if the response has the expected number of users assert_eq!( @@ -220,19 +193,15 @@ async fn test_stream_recommended() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_stream_recommended_missing_user_id() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - // Test retrieving recommended users without providing user_id - let res = client - .do_get("/v0/stream/users?source=recommended&limit=5") - .await?; - - // Assuming the endpoint returns 400 Bad Request - assert_eq!(res.status(), 400, "Expected HTTP status 400 Bad Request"); + let res = invalid_get_request( + "/v0/stream/users?source=recommended&limit=5", + StatusCode::BAD_REQUEST, + ) + .await?; - let body = res.json_body()?; assert!( - body["error"] + res["error"] .as_str() .unwrap_or("") .contains("user_id query param must be provided"), diff --git a/tests/service/stream/user/search.rs b/tests/service/stream/user/search.rs index a4d09045..3c2485d0 100644 --- a/tests/service/stream/user/search.rs +++ b/tests/service/stream/user/search.rs @@ -1,21 +1,14 @@ -use crate::service::utils::HOST_URL; +use crate::service::utils::get_request; use anyhow::Result; #[tokio_shared_rt::test(shared)] async fn test_stream_users_by_username_search() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - let username = "Jo"; - let res = client - .do_get(&format!("/v0/stream/users/username?username={}", username)) - .await?; - assert_eq!(res.status(), 200); - - let body = res.json_body()?; - assert!(body.is_array()); + let res = get_request(&format!("/v0/stream/users/username?username={}", username)).await?; + assert!(res.is_array()); - let users = body + let users = res .as_array() .expect("User search results should be an array"); diff --git a/tests/service/tags/hot.rs b/tests/service/tags/hot.rs index 4d9995c7..2b110e51 100644 --- a/tests/service/tags/hot.rs +++ b/tests/service/tags/hot.rs @@ -2,7 +2,7 @@ use anyhow::Result; use reqwest::StatusCode; use serde_json::Value; -use crate::service::utils::{make_request, make_wrong_request}; +use crate::service::utils::{get_request, invalid_get_request}; // TODO: Create deterministic integration tests @@ -56,7 +56,7 @@ fn compare_unit_hot_tag(tag: &Value, hot_tag: StreamTagMockup) { #[tokio_shared_rt::test(shared)] async fn test_global_hot_tags() -> Result<()> { - let body = make_request("/v0/tags/hot").await?; + let body = get_request("/v0/tags/hot").await?; assert!(body.is_array()); @@ -74,7 +74,7 @@ async fn test_global_hot_tags() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_global_hot_tags_with_today_timeframe() -> Result<()> { - let body = make_request("/v0/tags/hot?timeframe=today").await?; + let body = get_request("/v0/tags/hot?timeframe=today").await?; assert!(body.is_array()); @@ -92,7 +92,7 @@ async fn test_global_hot_tags_with_today_timeframe() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_global_hot_tags_with_this_month_timeframe() -> Result<()> { - let body = make_request("/v0/tags/hot?timeframe=this_month").await?; + let body = get_request("/v0/tags/hot?timeframe=this_month").await?; assert!(body.is_array()); @@ -110,7 +110,7 @@ async fn test_global_hot_tags_with_this_month_timeframe() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_global_hot_tags_skip_limit() -> Result<()> { - let body = make_request("/v0/tags/hot?skip=3&limit=5").await?; + let body = get_request("/v0/tags/hot?skip=3&limit=5").await?; assert!(body.is_array()); @@ -133,7 +133,7 @@ async fn test_global_hot_tags_skip_limit() -> Result<()> { async fn test_hot_tags_by_following_reach() -> Result<()> { let endpoint = &format!("/v0/tags/hot?user_id={}&reach=following", PEER_PUBKY,); - let body = make_request(endpoint).await?; + let body = get_request(endpoint).await?; assert!(body.is_array()); let tags = body.as_array().expect("Stream tags should be an array"); @@ -152,7 +152,7 @@ async fn test_hot_tags_by_following_reach() -> Result<()> { async fn test_hot_tags_by_reach_no_user_id() -> Result<()> { let endpoint = "/v0/tags/hot?reach=following"; - make_wrong_request(endpoint, Some(StatusCode::BAD_REQUEST.as_u16())).await?; + invalid_get_request(endpoint, StatusCode::BAD_REQUEST).await?; Ok(()) } @@ -161,7 +161,7 @@ async fn test_hot_tags_by_reach_no_user_id() -> Result<()> { async fn test_hot_tags_by_reach_no_reach() -> Result<()> { let endpoint = &format!("/v0/tags/hot?user_id={}", PEER_PUBKY); - make_wrong_request(endpoint, Some(StatusCode::BAD_REQUEST.as_u16())).await?; + invalid_get_request(endpoint, StatusCode::BAD_REQUEST).await?; Ok(()) } @@ -173,7 +173,7 @@ async fn test_hot_tags_by_following_using_taggers_limit() -> Result<()> { PEER_PUBKY, ); - let body = make_request(endpoint).await?; + let body = get_request(endpoint).await?; assert!(body.is_array()); let tags = body.as_array().expect("Stream tags should be an array"); @@ -192,7 +192,7 @@ async fn test_hot_tags_by_following_using_taggers_limit() -> Result<()> { async fn test_hot_tags_by_followers_reach() -> Result<()> { let endpoint = &format!("/v0/tags/hot?user_id={}&reach=followers", PEER_PUBKY); - let body = make_request(endpoint).await?; + let body = get_request(endpoint).await?; assert!(body.is_array()); let tags = body.as_array().expect("Post stream should be an array"); @@ -211,7 +211,7 @@ async fn test_hot_tags_by_followers_reach() -> Result<()> { async fn test_hot_tags_by_friends_reach() -> Result<()> { let endpoint = &format!("/v0/tags/hot?user_id={}&reach=friends", PEER_PUBKY); - let body = make_request(endpoint).await?; + let body = get_request(endpoint).await?; assert!(body.is_array()); let tags = body.as_array().expect("Post stream should be an array"); diff --git a/tests/service/tags/mod.rs b/tests/service/tags/mod.rs index 99439973..59e09758 100644 --- a/tests/service/tags/mod.rs +++ b/tests/service/tags/mod.rs @@ -1,7 +1,6 @@ use pubky_nexus::types::DynError; -use crate::service::utils::HOST_URL; - +use crate::service::utils::get_request; pub mod hot; pub mod post; pub mod search; @@ -17,14 +16,7 @@ const PEER_PUBKY: &str = "db6w58pd5h63fbhtd88y8zz7pai9rkjwqt9omg6i7dz31dynrgcy"; async fn check_mockups_loaded() -> Result<(), DynError> { let endpoint = format!("/v0/user/{}/tags", PEER_PUBKY); - let client = httpc_test::new_client(HOST_URL)?; - let res = client.do_get(&endpoint).await?; - - assert_eq!( - res.status(), - 200, - "Check if the tags.cypher graph is imported before run that tests" - ); + get_request(&endpoint).await?; Ok(()) } diff --git a/tests/service/tags/post.rs b/tests/service/tags/post.rs index fd95a182..c1d729d6 100644 --- a/tests/service/tags/post.rs +++ b/tests/service/tags/post.rs @@ -1,6 +1,7 @@ use anyhow::Result; +use reqwest::StatusCode; -use crate::service::utils::{make_request, make_wrong_request}; +use crate::service::utils::{get_request, invalid_get_request}; use super::utils::{analyse_tag_details_structure, compare_tag_details, TagMockup}; @@ -14,7 +15,7 @@ const FREE_LABEL: &str = "free"; #[tokio_shared_rt::test(shared)] async fn test_post_tag() -> Result<()> { let path = format!("/v0/post/{}/{}/tags", PEER_PUBKY, POST_ID); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -35,7 +36,7 @@ async fn test_post_tag() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_user_tags_limit_tag_filter_active() -> Result<()> { let path = format!("/v0/post/{}/{}/tags?limit_tags=2", PEER_PUBKY, POST_ID); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -55,7 +56,7 @@ async fn test_user_tags_limit_tag_filter_active() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_user_tags_limit_taggers_filter_active() -> Result<()> { let path = format!("/v0/post/{}/{}/tags?limit_taggers=1", PEER_PUBKY, POST_ID); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -78,7 +79,7 @@ async fn test_user_tags_full_filter_active() -> Result<()> { "/v0/post/{}/{}/tags?limit_tags=1&limit_taggers=1", PEER_PUBKY, POST_ID ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -99,7 +100,7 @@ async fn test_user_tags_full_filter_active() -> Result<()> { async fn test_post_does_not_exist() -> Result<()> { let endpoint = format!("/v0/post/{}/{}/tags", PEER_PUBKY, "JTDX9ZSWPQF8"); // TODO: Control post not found error control - make_wrong_request(&endpoint, None).await?; + invalid_get_request(&endpoint, StatusCode::NOT_FOUND).await?; Ok(()) } @@ -110,14 +111,14 @@ async fn test_user_does_not_exist() -> Result<()> { "db6w58pd5h63fbhtd88y8zz7pai9rkjwqt9omg6i7dz31dynrgc4", POST_ID ); // TODO: Control post not found error control - make_wrong_request(&endpoint, None).await?; + invalid_get_request(&endpoint, StatusCode::NOT_FOUND).await?; Ok(()) } #[tokio_shared_rt::test(shared)] async fn test_post_specific_tag() -> Result<()> { let path = format!("/v0/post/{}/{}/taggers/{}", PEER_PUBKY, POST_ID, FREE_LABEL); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -138,7 +139,7 @@ async fn test_post_specific_tag_with_limit() -> Result<()> { "/v0/post/{}/{}/taggers/{}?limit=1", PEER_PUBKY, POST_ID, FREE_LABEL ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -159,7 +160,7 @@ async fn test_post_specific_tag_with_skip() -> Result<()> { "/v0/post/{}/{}/taggers/{}?skip=1", PEER_PUBKY, POST_ID, FREE_LABEL ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -180,7 +181,7 @@ async fn test_post_specific_tag_with_full_filters() -> Result<()> { "/v0/post/{}/{}/taggers/{}?skip=2&limit=1", PEER_PUBKY, POST_ID, FREE_LABEL ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -201,7 +202,7 @@ async fn test_post_specific_tag_with_no_result() -> Result<()> { "/v0/post/{}/{}/taggers/{}?skip=3&limit=1", PEER_PUBKY, POST_ID, FREE_LABEL ); - make_wrong_request(&path, None).await?; + invalid_get_request(&path, StatusCode::NOT_FOUND).await?; Ok(()) } diff --git a/tests/service/tags/search.rs b/tests/service/tags/search.rs index e7182ce4..5ca4397b 100644 --- a/tests/service/tags/search.rs +++ b/tests/service/tags/search.rs @@ -1,7 +1,8 @@ use anyhow::Result; +use reqwest::StatusCode; use serde_json::Value; -use crate::service::utils::{make_request, make_wrong_request}; +use crate::service::utils::{get_request, invalid_get_request}; const ROOT_PATH: &str = "/v0/search/tags"; const FREE_LABEL: &str = "free"; @@ -14,7 +15,7 @@ const POST_C: &str = "HC3T5CEPBPHQ"; async fn test_tag_search_by_timeline() -> Result<()> { let post_order = vec![POST_A, POST_B, POST_C]; let path = format!("{}/{}", ROOT_PATH, FREE_LABEL); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -33,7 +34,7 @@ async fn test_tag_search_by_timeline() -> Result<()> { async fn test_tag_search_with_skip() -> Result<()> { let post_order = vec![POST_B, POST_C]; let path = format!("{}/{}?skip=1", ROOT_PATH, FREE_LABEL); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -52,7 +53,7 @@ async fn test_tag_search_with_skip() -> Result<()> { async fn test_tag_search_with_limit() -> Result<()> { let post_order = vec![POST_A]; let path = format!("{}/{}?limit=1", ROOT_PATH, FREE_LABEL); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -71,7 +72,7 @@ async fn test_tag_search_with_limit() -> Result<()> { async fn test_tag_search_with_limit_and_skip() -> Result<()> { let post_order = vec![POST_C]; let path = format!("{}/{}?limit=1&skip=2", ROOT_PATH, FREE_LABEL); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -89,7 +90,7 @@ async fn test_tag_search_with_limit_and_skip() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_post_specific_tag_with_no_result() -> Result<()> { let path = format!("{}/{}", ROOT_PATH, "randommm"); - make_wrong_request(&path, None).await?; + invalid_get_request(&path, StatusCode::NOT_FOUND).await?; Ok(()) } diff --git a/tests/service/tags/user.rs b/tests/service/tags/user.rs index 16ac3f70..739f8082 100644 --- a/tests/service/tags/user.rs +++ b/tests/service/tags/user.rs @@ -1,6 +1,7 @@ use anyhow::Result; +use reqwest::StatusCode; -use crate::service::utils::{make_request, make_wrong_request}; +use crate::service::utils::{get_request, invalid_get_request}; use super::utils::{analyse_tag_details_structure, compare_tag_details, TagMockup}; @@ -11,7 +12,7 @@ const PUBKY_LABEL: &str = "pubky"; #[tokio_shared_rt::test(shared)] async fn test_full_user_tags_endpoint() -> Result<()> { let path = format!("/v0/user/{}/tags", PUBKY_PEER); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -31,7 +32,7 @@ async fn test_full_user_tags_endpoint() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_user_tags_limit_tag_filter_active() -> Result<()> { let path = format!("/v0/user/{}/tags?limit_tags=2", PUBKY_PEER); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -51,7 +52,7 @@ async fn test_user_tags_limit_tag_filter_active() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_user_tags_limit_taggers_filter_active() -> Result<()> { let path = format!("/v0/user/{}/tags?limit_taggers=1", PUBKY_PEER); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -71,7 +72,7 @@ async fn test_user_tags_limit_taggers_filter_active() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_user_tags_full_filter_active() -> Result<()> { let path = format!("/v0/user/{}/tags?limit_tags=1&limit_taggers=1", PUBKY_PEER); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -95,7 +96,7 @@ async fn test_user_does_not_exist() -> Result<()> { "db6w58pd5h63fbhtd88y8zz7pai9rkjwqt9omg6i7dz31dynrgc4" ); // TODO: Control post not found error control - make_wrong_request(&endpoint, None).await?; + invalid_get_request(&endpoint, StatusCode::NOT_FOUND).await?; Ok(()) } @@ -104,7 +105,7 @@ async fn test_user_does_not_exist() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_user_specific_tag() -> Result<()> { let path = format!("/v0/user/{}/taggers/{}", PUBKY_PEER, PUBKY_LABEL); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -122,7 +123,7 @@ async fn test_user_specific_tag() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_user_specific_tag_with_limit() -> Result<()> { let path = format!("/v0/user/{}/taggers/{}?limit=1", PUBKY_PEER, PUBKY_LABEL); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -140,7 +141,7 @@ async fn test_user_specific_tag_with_limit() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_user_specific_tag_with_skip() -> Result<()> { let path = format!("/v0/user/{}/taggers/{}?skip=1", PUBKY_PEER, PUBKY_LABEL); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -161,7 +162,7 @@ async fn test_user_specific_tag_with_full_filters() -> Result<()> { "/v0/user/{}/taggers/{}?skip=2&limit=1", PUBKY_PEER, PUBKY_LABEL ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -182,7 +183,7 @@ async fn test_user_specific_tag_with_no_result() -> Result<()> { "/v0/user/{}/taggers/{}?skip=3&limit=1", PUBKY_PEER, PUBKY_LABEL ); - make_wrong_request(&path, None).await?; + invalid_get_request(&path, StatusCode::NOT_FOUND).await?; Ok(()) } diff --git a/tests/service/tags/wot.rs b/tests/service/tags/wot.rs index ffb0a198..54f1fdd1 100644 --- a/tests/service/tags/wot.rs +++ b/tests/service/tags/wot.rs @@ -1,7 +1,8 @@ use super::utils::{analyse_tag_details_structure, compare_tag_details, TagMockup}; -use crate::service::utils::{make_request, make_wrong_request}; +use crate::service::utils::{get_request, invalid_get_request}; use anyhow::Result; use pubky_nexus::models::tag::TagDetails; +use reqwest::StatusCode; use serde_json::Value; // ##### WoT user tags #### @@ -25,14 +26,14 @@ async fn test_wot_user_tags_endpoints() -> Result<()> { AURELIO_USER, ATHENS_TAG, EPICTTO_VIEWER ); // If we get error here, delete the Cache:... indexes - make_wrong_request(&path, None).await?; + invalid_get_request(&path, StatusCode::NOT_FOUND).await?; // => Start indexing the WoT tags let path = format!( "/v0/user/{}/tags?viewer_id={}&depth=2", AURELIO_USER, EPICTTO_VIEWER ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -53,7 +54,7 @@ async fn test_wot_user_tags_endpoints() -> Result<()> { "/v0/user/{}/tags?viewer_id={}&depth=2&limit_tags=1", AURELIO_USER, EPICTTO_VIEWER ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -72,7 +73,7 @@ async fn test_wot_user_tags_endpoints() -> Result<()> { "/v0/user/{}/tags?viewer_id={}&depth=2&limit_taggers=1", AURELIO_USER, EPICTTO_VIEWER ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -93,7 +94,7 @@ async fn test_wot_user_tags_endpoints() -> Result<()> { "/v0/user/{}/tags?viewer_id={}&depth=2&limit_tags=1&limit_taggers=1", AURELIO_USER, EPICTTO_VIEWER ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; assert!(body.is_array()); @@ -112,7 +113,7 @@ async fn test_wot_user_tags_endpoints() -> Result<()> { "/v0/user/{}/taggers/{}?viewer_id={}&depth=2", AURELIO_USER, ATHENS_TAG, EPICTTO_VIEWER ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let mut mock_taggers = vec![USER_A, USER_B, USER_C]; verify_taggers_list(mock_taggers, body); @@ -122,7 +123,7 @@ async fn test_wot_user_tags_endpoints() -> Result<()> { "/v0/user/{}/taggers/{}?viewer_id={}&depth=2&limit=2", AURELIO_USER, ATHENS_TAG, EPICTTO_VIEWER ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; mock_taggers = vec![USER_A, USER_B]; verify_taggers_list(mock_taggers, body); @@ -132,7 +133,7 @@ async fn test_wot_user_tags_endpoints() -> Result<()> { "/v0/user/{}/taggers/{}?viewer_id={}&depth=2&limit=1&skip=1", AURELIO_USER, ATHENS_TAG, EPICTTO_VIEWER ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; mock_taggers = vec![USER_B]; verify_taggers_list(mock_taggers, body); @@ -142,7 +143,7 @@ async fn test_wot_user_tags_endpoints() -> Result<()> { "/v0/user/{}?viewer_id={}&depth=2", AURELIO_USER, EPICTTO_VIEWER ); - let body = make_request(&path).await?; + let body = get_request(&path).await?; let tags = body["tags"].clone(); mock_taggers = vec![USER_A, USER_B, USER_C]; diff --git a/tests/service/user/reach.rs b/tests/service/user/reach.rs index 6d544a5c..dcb1a5c6 100644 --- a/tests/service/user/reach.rs +++ b/tests/service/user/reach.rs @@ -1,20 +1,14 @@ -use crate::service::utils::HOST_URL; +use crate::service::utils::{get_request, invalid_get_request}; use anyhow::Result; +use reqwest::StatusCode; #[tokio_shared_rt::test(shared)] async fn test_get_followers() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - let user_id = "4snwyct86m383rsduhw5xgcxpw7c63j3pq8x4ycqikxgik8y64ro"; - let res = client - .do_get(&format!("/v0/user/{}/followers", user_id)) - .await?; - assert_eq!(res.status(), 200); - - let body = res.json_body()?; + let res = get_request(&format!("/v0/user/{}/followers", user_id)).await?; - assert!(body.is_array()); - let followers: Vec = body + assert!(res.is_array()); + let followers: Vec = res .as_array() .unwrap() .iter() @@ -48,27 +42,22 @@ async fn test_get_followers() -> Result<()> { } // Test non-existing user - let res = client - .do_get(&format!("/v0/user/{}/followers", "bad_user_id")) - .await?; - assert_eq!(res.status(), 404); + invalid_get_request( + &format!("/v0/user/{}/followers", "bad_user_id"), + StatusCode::NOT_FOUND, + ) + .await?; Ok(()) } #[tokio_shared_rt::test(shared)] async fn test_get_following() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - let user_id = "4snwyct86m383rsduhw5xgcxpw7c63j3pq8x4ycqikxgik8y64ro"; - let res = client - .do_get(&format!("/v0/user/{}/following", user_id)) - .await?; - assert_eq!(res.status(), 200); - - let body = res.json_body()?; - assert!(body.is_array()); - let following: Vec = body + let res = get_request(&format!("/v0/user/{}/following", user_id)).await?; + + assert!(res.is_array()); + let following: Vec = res .as_array() .unwrap() .iter() @@ -107,27 +96,22 @@ async fn test_get_following() -> Result<()> { } // Test non-existing user - let res = client - .do_get(&format!("/v0/user/{}/following", "bad_user_id")) - .await?; - assert_eq!(res.status(), 404); + invalid_get_request( + &format!("/v0/user/{}/following", "bad_user_id"), + StatusCode::NOT_FOUND, + ) + .await?; Ok(()) } #[tokio_shared_rt::test(shared)] async fn test_get_friends() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - let user_id = "4snwyct86m383rsduhw5xgcxpw7c63j3pq8x4ycqikxgik8y64ro"; - let res = client - .do_get(&format!("/v0/user/{}/friends", user_id)) - .await?; - assert_eq!(res.status(), 200); - - let body = res.json_body()?; - assert!(body.is_array()); - let following: Vec = body + let res = get_request(&format!("/v0/user/{}/friends", user_id)).await?; + + assert!(res.is_array()); + let following: Vec = res .as_array() .unwrap() .iter() @@ -159,10 +143,11 @@ async fn test_get_friends() -> Result<()> { } // Test non-existing user - let res = client - .do_get(&format!("/v0/user/{}/friends", "bad_user_id")) - .await?; - assert_eq!(res.status(), 404); + invalid_get_request( + &format!("/v0/user/{}/friends", "bad_user_id"), + StatusCode::NOT_FOUND, + ) + .await?; Ok(()) } diff --git a/tests/service/user/search.rs b/tests/service/user/search.rs index 555026d4..a6751890 100644 --- a/tests/service/user/search.rs +++ b/tests/service/user/search.rs @@ -1,21 +1,16 @@ -use crate::service::utils::HOST_URL; +use crate::service::utils::{get_request, invalid_get_request}; use anyhow::Result; +use reqwest::StatusCode; #[tokio_shared_rt::test(shared)] async fn test_search_users_by_username() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - let username = "Jo"; - let res = client - .do_get(&format!("/v0/search/users?username={}", username)) - .await?; - assert_eq!(res.status(), 200); + let res = get_request(&format!("/v0/search/users?username={}", username)).await?; - let body = res.json_body()?; - assert!(body.is_array()); + assert!(res.is_array()); - let users = body + let users = res .as_array() .expect("User search results should be an array"); @@ -43,29 +38,20 @@ async fn test_search_users_by_username() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_search_non_existing_user() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - let non_existing_username = "idfjwfs8u9jfkoi"; // Username that doesn't exist - let res = client - .do_get(&format!( - "/v0/search/users?username={}", - non_existing_username - )) - .await?; + let res = invalid_get_request( + &format!("/v0/search/users?username={}", non_existing_username), + StatusCode::NOT_FOUND, + ) + .await?; // Assert that the status code is 404 Not Found - assert_eq!(res.status(), 404); - - let body = res.json_body()?; - assert!( - body["error"].is_string(), - "Error message should be a string" - ); + assert!(res["error"].is_string(), "Error message should be a string"); // Optional: Check that the error message contains the correct details assert!( - body["error"] + res["error"] .as_str() .unwrap_or("") .contains(non_existing_username), @@ -77,26 +63,19 @@ async fn test_search_non_existing_user() -> Result<()> { #[tokio_shared_rt::test(shared)] async fn test_search_empty_username() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - let empty_username = ""; // Empty username - let res = client - .do_get(&format!("/v0/search/users?username={}", empty_username)) - .await?; - - // Assert that the status code is 400 Bad Request - assert_eq!(res.status(), 400); + let res = invalid_get_request( + &format!("/v0/search/users?username={}", empty_username), + StatusCode::BAD_REQUEST, + ) + .await?; - let body = res.json_body()?; - assert!( - body["error"].is_string(), - "Error message should be a string" - ); + assert!(res["error"].is_string(), "Error message should be a string"); // Optional: Check that the error message contains the correct details assert!( - body["error"] + res["error"] .as_str() .unwrap_or("") .contains("Username cannot be empty"), diff --git a/tests/service/user/views.rs b/tests/service/user/views.rs index fbaa5c39..539fdc75 100644 --- a/tests/service/user/views.rs +++ b/tests/service/user/views.rs @@ -1,31 +1,26 @@ -use crate::service::utils::HOST_URL; +use crate::service::utils::{get_request, invalid_get_request}; use anyhow::Result; +use reqwest::StatusCode; #[tokio_shared_rt::test(shared)] async fn test_user_endpoint() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - // Look for Aldert pk user id let user_id = "4snwyct86m383rsduhw5xgcxpw7c63j3pq8x4ycqikxgik8y64ro"; - let res = client.do_get(&format!("/v0/user/{}", user_id)).await?; - assert_eq!(res.status(), 200); + let res = get_request(&format!("/v0/user/{}", user_id)).await?; - let body = res.json_body()?; - assert_eq!(body["details"]["name"], "Aldert"); - assert_eq!(body["details"]["status"], "working"); - assert_eq!(body["details"]["id"], user_id); - assert_eq!(body["details"]["image"], "pubky://4snwyct86m383rsduhw5xgcxpw7c63j3pq8x4ycqikxgik8y64ro/pub/pubky.app/files/003286NSMY490"); - assert_eq!(body["counts"]["friends"], 8); - assert_eq!(body["counts"]["posts"], 4); + assert_eq!(res["details"]["name"], "Aldert"); + assert_eq!(res["details"]["status"], "working"); + assert_eq!(res["details"]["id"], user_id); + assert_eq!(res["details"]["image"], "pubky://4snwyct86m383rsduhw5xgcxpw7c63j3pq8x4ycqikxgik8y64ro/pub/pubky.app/files/003286NSMY490"); + assert_eq!(res["counts"]["friends"], 8); + assert_eq!(res["counts"]["posts"], 4); // Test tags on Ar's profile let ar_id = "pxnu33x7jtpx9ar1ytsi4yxbp6a5o36gwhffs8zoxmbuptici1jy"; - let res = client.do_get(&format!("/v0/user/{}", ar_id)).await?; - assert_eq!(res.status(), 200); + let res = get_request(&format!("/v0/user/{}", ar_id)).await?; - let body = res.json_body()?; //let user_profile: UserView = serde_json::from_value(body)?; - if let Some(tags) = body.get("tags").and_then(|t| t.as_array()) { + if let Some(tags) = res.get("tags").and_then(|t| t.as_array()) { assert_eq!(tags.len(), 3); assert!( tags.iter().any(|tag| tag["label"] == "pkarr"), @@ -43,124 +38,97 @@ async fn test_user_endpoint() -> Result<()> { // Look for Aldert pk user id using Flavio's viewer id let viewer_id = "5g3fwnue819wfdjwiwm8qr35ww6uxxgbzrigrtdgmbi19ksioeoy"; - let res = client - .do_get(&format!("/v0/user/{}?viewer_id={}", user_id, viewer_id)) - .await?; - assert_eq!(res.status(), 200); + let res = get_request(&format!("/v0/user/{}?viewer_id={}", user_id, viewer_id)).await?; - let body = res.json_body()?; assert_eq!( - body["relationship"]["followed_by"], true, + res["relationship"]["followed_by"], true, "Aldert should follow Flavio" ); assert_eq!( - body["relationship"]["following"], false, + res["relationship"]["following"], false, "Flavio should not follow Aldert" ); // Look for a non existing pk let user_id = "bad_user_id"; - let res = client.do_get(&format!("/v0/user/{}", user_id)).await?; - assert_eq!(res.status(), 404); + invalid_get_request(&format!("/v0/user/{}", user_id), StatusCode::NOT_FOUND).await?; Ok(()) } #[tokio_shared_rt::test(shared)] async fn test_get_relationship() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - let user_id = "4snwyct86m383rsduhw5xgcxpw7c63j3pq8x4ycqikxgik8y64ro"; let viewer_id = "5g3fwnue819wfdjwiwm8qr35ww6uxxgbzrigrtdgmbi19ksioeoy"; - let res = client - .do_get(&format!("/v0/user/{}/relationship/{}", user_id, viewer_id)) - .await?; - assert_eq!(res.status(), 200); + let res = get_request(&format!("/v0/user/{}/relationship/{}", user_id, viewer_id)).await?; - let body = res.json_body()?; - assert!(body["following"].is_boolean()); - assert!(body["followed_by"].is_boolean()); + assert!(res["following"].is_boolean()); + assert!(res["followed_by"].is_boolean()); // Test non-existing relationship let user_id = "bad_user_id"; let viewer_id = "bad_viewer_id"; - let res = client - .do_get(&format!("/v0/user/{}/relationship/{}", user_id, viewer_id)) - .await?; - assert_eq!(res.status(), 404); + invalid_get_request( + &format!("/v0/user/{}/relationship/{}", user_id, viewer_id), + StatusCode::NOT_FOUND, + ) + .await?; Ok(()) } #[tokio_shared_rt::test(shared)] async fn test_get_counts() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - let user_id = "4snwyct86m383rsduhw5xgcxpw7c63j3pq8x4ycqikxgik8y64ro"; - let res = client - .do_get(&format!("/v0/user/{}/counts", user_id)) - .await?; - assert_eq!(res.status(), 200); - - let body = res.json_body()?; - assert!(body["tags"].is_number()); - assert!(body["posts"].is_number()); - assert!(body["followers"].is_number()); - assert!(body["following"].is_number()); - assert!(body["friends"].is_number()); + let res = get_request(&format!("/v0/user/{}/counts", user_id)).await?; + + assert!(res["tags"].is_number()); + assert!(res["posts"].is_number()); + assert!(res["followers"].is_number()); + assert!(res["following"].is_number()); + assert!(res["friends"].is_number()); // Test non-existing user let user_id = "bad_user_id"; - let res = client - .do_get(&format!("/v0/user/{}/counts", user_id)) - .await?; - assert_eq!(res.status(), 404); + invalid_get_request( + &format!("/v0/user/{}/counts", user_id), + StatusCode::NOT_FOUND, + ) + .await?; Ok(()) } #[tokio_shared_rt::test(shared)] async fn test_get_details() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - let user_id = "4snwyct86m383rsduhw5xgcxpw7c63j3pq8x4ycqikxgik8y64ro"; - let res = client - .do_get(&format!("/v0/user/{}/details", user_id)) - .await?; - assert_eq!(res.status(), 200); - - let body = res.json_body()?; + let res = get_request(&format!("/v0/user/{}/details", user_id)).await?; - assert!(body["name"].is_string()); - assert!(body["bio"].is_string()); - assert!(body["id"].is_string()); - assert!(body["status"].is_string()); - assert!(body["links"].is_array()); - assert!(body["indexed_at"].is_number()); + assert!(res["name"].is_string()); + assert!(res["bio"].is_string()); + assert!(res["id"].is_string()); + assert!(res["status"].is_string()); + assert!(res["links"].is_array()); + assert!(res["indexed_at"].is_number()); // Test non-existing user let user_id = "bad_user_id"; - let res = client - .do_get(&format!("/v0/user/{}/details", user_id)) - .await?; - assert_eq!(res.status(), 404); + invalid_get_request( + &format!("/v0/user/{}/details", user_id), + StatusCode::NOT_FOUND, + ) + .await?; Ok(()) } #[tokio_shared_rt::test(shared)] async fn test_get_muted() -> Result<()> { - let client = httpc_test::new_client(HOST_URL)?; - let user_id = "db6w580d5h63fbhtd88y8zz7pai9rkjwqt9omg6i7dz31dynrgcy"; - let res = client - .do_get(&format!("/v0/user/{}/muted", user_id)) - .await?; - assert_eq!(res.status(), 200); - - let body = res.json_body()?; - assert!(body.is_array()); - let muted: Vec = body + let res = get_request(&format!("/v0/user/{}/muted", user_id)).await?; + + assert!(res.is_array()); + let muted: Vec = res .as_array() .unwrap() .iter() @@ -187,10 +155,11 @@ async fn test_get_muted() -> Result<()> { } // Test non-existing user - let res = client - .do_get(&format!("/v0/user/{}/muted", "bad_user_id")) - .await?; - assert_eq!(res.status(), 404); + invalid_get_request( + &format!("/v0/user/{}/muted", "bad_user_id"), + StatusCode::NOT_FOUND, + ) + .await?; Ok(()) } diff --git a/tests/service/utils.rs b/tests/service/utils.rs index a2115916..958d1e35 100644 --- a/tests/service/utils.rs +++ b/tests/service/utils.rs @@ -1,30 +1,77 @@ +use reqwest::{Method, StatusCode}; use serde_json::Value; +use crate::utils::TestServiceServer; + pub const HOST_URL: &str = "http://localhost:8080"; // ####################################### // ##### Endpoint requests related ####### // ####################################### -// Small unit test to test the endpoint -pub async fn make_request(endpoint: &str) -> Result { - let client = httpc_test::new_client(HOST_URL)?; +pub async fn get_request(endpoint: &str) -> Result { + let body = inner_make_request(endpoint, None, None, None).await?; + Ok(body) +} - let res = client.do_get(endpoint).await?; +pub async fn invalid_get_request( + endpoint: &str, + error_code: StatusCode, +) -> Result { + let body = inner_make_request(endpoint, None, None, Some(error_code)).await?; + Ok(body) +} - assert_eq!(res.status(), 200); - let body = res.json_body()?; +pub async fn post_request(endpoint: &str, data: Value) -> Result { + let body = inner_make_request(endpoint, Some(Method::POST), Some(data), None).await?; Ok(body) } -pub async fn make_wrong_request( +pub async fn invalid_post_request( endpoint: &str, - error_code: Option, -) -> Result<(), httpc_test::Error> { + data: Value, + error_code: StatusCode, +) -> Result { + let body = + inner_make_request(endpoint, Some(Method::POST), Some(data), Some(error_code)).await?; + Ok(body) +} + +// Small unit test to test the endpoint +async fn inner_make_request( + endpoint: &str, + method: Option, + data: Option, + error_code: Option, +) -> Result { + // make sure server is running + TestServiceServer::get_test_server().await; let client = httpc_test::new_client(HOST_URL)?; - let res = client.do_get(endpoint).await?; + let request_method = method.unwrap_or(Method::GET); + let res = match request_method { + Method::GET => client.do_get(endpoint).await?, + Method::POST => { + client + .do_post(endpoint, data.unwrap_or(Value::Null)) + .await? + } + Method::PUT => client.do_put(endpoint, data.unwrap_or(Value::Null)).await?, + Method::DELETE => client.do_delete(endpoint).await?, + _ => panic!("Unsupported method"), + }; + + match error_code { + Some(code) => assert_eq!(res.status(), code, "Expected HTTP status {}", code), + None => assert_eq!(res.status(), 200, "Expected HTTP status 200 OK"), + } - assert_eq!(res.status(), error_code.unwrap_or(404)); - Ok(()) + let body = match res.json_body() { + Ok(body) => body, + Err(e) => { + eprintln!("Error parsing response body: {:?}", e); + Value::Null + } + }; + Ok(body) } diff --git a/tests/utils.rs b/tests/utils.rs index 710fae41..ab20e21a 100644 --- a/tests/utils.rs +++ b/tests/utils.rs @@ -1,55 +1,102 @@ +use std::{process::Stdio, sync::Arc}; + use anyhow::Result; +use log::info; +use neo4rs::query; +use pubky_nexus::{ + db::connectors::redis::get_redis_conn, get_neo4j_graph, redis_is_empty, reindex, routes, setup, + Config, +}; +use tokio::{ + net::TcpListener, + sync::{Mutex, OnceCell}, +}; + // Util backend server for testing // Performs the same routine the main service server does // OnceCell is used to ensure the server is only started once -use log::info; -use pubky_nexus::{redis_is_empty, reindex, routes, setup, Config}; -use tokio::{net::TcpListener, sync::OnceCell}; - #[derive(Clone, Debug)] -pub struct TestServiceServer {} +pub struct TestServiceServer { + pub initialized: bool, +} -// static oncecell for the server -pub static TEST_SERVER: OnceCell = OnceCell::const_new(); +pub static TEST_SERVER: OnceCell>> = OnceCell::const_new(); impl TestServiceServer { - pub async fn get_test_server() -> TestServiceServer { + pub async fn get_test_server() -> Arc> { // Start the server if it hasn't been started - match TEST_SERVER.get() { - Some(server) => server.clone(), - None => { - let server = Self::start_server().await.unwrap(); - TEST_SERVER - .set(server.clone()) - .expect("Failed to set test server"); - server - } - } + TEST_SERVER + .get_or_init(|| async { + Self::start_server().await.unwrap(); + Arc::new(Mutex::new(TestServiceServer { initialized: true })) + }) + .await + .to_owned() } - async fn start_server() -> Result { - tokio::spawn(async { - let config = Config::from_env(); - setup(&config).await; + async fn sync_graph() { + let graph = get_neo4j_graph().expect("Failed to get Neo4j graph connection"); + + // drop and run the queries again + let drop_all_query = query("MATCH (n) DETACH DELETE n;"); + graph + .lock() + .await + .run(drop_all_query) + .await + .expect("Could not drop graph nodes."); - // Reindex if REINDEX is set to true or Redis is empty - let should_reindex = config.reindex || redis_is_empty().await.unwrap_or(false); + // Run the run-queries.sh script on the Docker host using docker exec + tokio::process::Command::new("docker") + .args(&["exec", "neo4j", "bash", "/db-graph/run-queries.sh"]) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .status() + .await + .expect("Failed to run run-queries.sh"); + } + + async fn sync_redis() { + // Drop all keys in Redis + let mut redis_conn = get_redis_conn() + .await + .expect("Could not get the redis connection"); + + redis::cmd("FLUSHALL") + .exec_async(&mut redis_conn) + .await + .expect("Failed to flush Redis"); - if should_reindex { - info!("Starting reindexing process."); - reindex().await; - } + // Reindex + let should_reindex = redis_is_empty().await.unwrap_or(false); + if should_reindex { + info!("Starting reindexing process."); + reindex().await; + } + } - // App router - let app = routes::routes(); + async fn start_server() -> Result<()> { + let config = Config::from_env(); + setup(&config).await; + // make sure DBs are in sync with mock data + let sync_db_env = std::env::var("SYNC_DB").unwrap_or("false".to_string()); + if sync_db_env == "true" { + Self::sync_graph().await; + Self::sync_redis().await; + } + + // App router + let app = routes::routes(); + let listener = TcpListener::bind(&config.server_binding()).await.unwrap(); + info!("Listening on {:?}\n", listener.local_addr().unwrap()); + + tokio::spawn(async { // Start server - let listener = TcpListener::bind(&config.server_binding()).await.unwrap(); - info!("Listening on {:?}\n", listener.local_addr().unwrap()); axum::serve(listener, app.into_make_service()) .await .unwrap(); }); - Ok(TestServiceServer {}) + Ok(()) } } diff --git a/tests/watcher/utils.rs b/tests/watcher/utils.rs index 79b81acd..ff0b1241 100644 --- a/tests/watcher/utils.rs +++ b/tests/watcher/utils.rs @@ -19,7 +19,6 @@ pub struct WatcherTest { pub event_processor: EventProcessor, pub config: Config, pub ensure_event_processing: bool, - pub service_server: Option, } impl WatcherTest { @@ -32,10 +31,9 @@ impl WatcherTest { let client = PubkyClient::test(&testnet); let homeserver_url = format!("http://localhost:{}", homeserver.port()); let event_processor = EventProcessor::test(&testnet, homeserver_url).await; - let service_server = match with_service_server { - true => Some(TestServiceServer::get_test_server().await), - false => None, - }; + if with_service_server { + TestServiceServer::get_test_server().await; + } Ok(Self { config, @@ -43,7 +41,6 @@ impl WatcherTest { client, event_processor, ensure_event_processing: true, - service_server, }) }