diff --git a/Cargo.lock b/Cargo.lock index 18fc14ca..2298e2a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1608,7 +1608,7 @@ checksum = "9171a2ea8a68358193d15dd5d70c1c10a2afc3e7e4c5bc92bc9f025cebd7359c" [[package]] name = "http-relay" version = "0.1.0" -source = "git+https://github.com/pubky/pubky?branch=v0.4.0-rc1#9b7c7c6352036001059d8e7bc3d11a94771e1cf0" +source = "git+https://github.com/pubky/pubky?branch=v0.4.0-rc1#30237c43cbd07d472cd5e5b77b64a343d832647e" dependencies = [ "anyhow", "axum 0.7.9", @@ -2699,7 +2699,7 @@ checksum = "33cb294fe86a74cbcf50d4445b37da762029549ebeea341421c7c70370f86cac" [[package]] name = "pubky" version = "0.3.0" -source = "git+https://github.com/pubky/pubky?branch=v0.4.0-rc1#9b7c7c6352036001059d8e7bc3d11a94771e1cf0" +source = "git+https://github.com/pubky/pubky?branch=v0.4.0-rc1#30237c43cbd07d472cd5e5b77b64a343d832647e" dependencies = [ "anyhow", "base64 0.22.1", @@ -2739,7 +2739,7 @@ dependencies = [ [[package]] name = "pubky-common" version = "0.1.0" -source = "git+https://github.com/pubky/pubky?branch=v0.4.0-rc1#9b7c7c6352036001059d8e7bc3d11a94771e1cf0" +source = "git+https://github.com/pubky/pubky?branch=v0.4.0-rc1#30237c43cbd07d472cd5e5b77b64a343d832647e" dependencies = [ "argon2", "base32", @@ -2759,7 +2759,7 @@ dependencies = [ [[package]] name = "pubky-homeserver" version = "0.1.0" -source = "git+https://github.com/pubky/pubky?branch=v0.4.0-rc1#9b7c7c6352036001059d8e7bc3d11a94771e1cf0" +source = "git+https://github.com/pubky/pubky?branch=v0.4.0-rc1#30237c43cbd07d472cd5e5b77b64a343d832647e" dependencies = [ "anyhow", "axum 0.7.9", diff --git a/Cargo.toml b/Cargo.toml index 861c0e8a..56192337 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ base32 = "0.5.1" blake3 = "1.5.5" url = "2.5.4" async-trait = "0.1.84" -reqwest = { version = "0.12.9", features = ["json"] } +reqwest = "0.12.9" [dev-dependencies] anyhow = "1.0.95" diff --git a/examples/new_homeserver_user.rs b/examples/new_homeserver_user.rs index 549c5893..52405561 100644 --- a/examples/new_homeserver_user.rs +++ b/examples/new_homeserver_user.rs @@ -39,9 +39,6 @@ async fn main() -> Result<()> { Some("Running Bitcoin".to_string()), ); - // Serialize the profile to JSON - let profile_json = serde_json::to_vec(&user)?; - // Put some content into the Pubky homeserver let url = format!( "{protocol}{pk}{path}", @@ -49,7 +46,7 @@ async fn main() -> Result<()> { pk = pk, path = user.create_path() ); - client.put(url.as_str()).json(&profile_json).send().await?; + client.put(url.as_str()).json(&user).send().await?; Ok(()) } diff --git a/src/db/connectors/pubky.rs b/src/db/connectors/pubky.rs index 6a1614fb..690c91e3 100644 --- a/src/db/connectors/pubky.rs +++ b/src/db/connectors/pubky.rs @@ -56,7 +56,6 @@ impl PubkyConnector { }, }; - println!("CLIEEENNNNNNNNNNNNT, {:?}", pubky_client); let manager = Self { pubky_client: Arc::new(pubky_client), }; diff --git a/src/events/handlers/file.rs b/src/events/handlers/file.rs index 75bde998..66582c4d 100644 --- a/src/events/handlers/file.rs +++ b/src/events/handlers/file.rs @@ -11,7 +11,6 @@ use crate::{ }, Config, }; -use axum::body::Bytes; use log::{debug, error}; use pubky_app_specs::{traits::Validatable, PubkyAppFile}; use tokio::{ @@ -71,6 +70,8 @@ async fn ingest( } }; + let blob = response.bytes().await?; + store_blob(file_id.to_string(), user_id.to_string(), &blob).await?; Ok(FileMeta { diff --git a/src/events/mod.rs b/src/events/mod.rs index a8279c0f..a838dcdd 100644 --- a/src/events/mod.rs +++ b/src/events/mod.rs @@ -1,14 +1,12 @@ use crate::{db::connectors::pubky::PubkyConnector, types::PubkyId}; use log::{debug, error}; +use reqwest; use uri::ParsedUri; pub mod handlers; pub mod processor; pub mod uri; -use axum::body::Bytes; -use reqwest; - #[derive(Debug, Clone)] enum ResourceType { User { diff --git a/src/events/processor.rs b/src/events/processor.rs index 0a619372..a937fc27 100644 --- a/src/events/processor.rs +++ b/src/events/processor.rs @@ -59,11 +59,10 @@ impl EventProcessor { async fn poll_events(&mut self) -> Result>, Box> { debug!("Polling new events from homeserver"); - let res: String; + let response: String; { let pubky_client = PubkyConnector::get_pubky_client()?; - debug!("BEFORE PUBKY CLIENT"); - res = pubky_client + response = pubky_client .get(format!( "https://{}/events/?cursor={}&limit={}", self.homeserver.id, self.homeserver.cursor, self.limit @@ -72,10 +71,9 @@ impl EventProcessor { .await? .text() .await?; - debug!("AFTER PUBKY CLIENT"); } - let lines: Vec = res.trim().split('\n').map(|s| s.to_string()).collect(); + let lines: Vec = response.trim().split('\n').map(|s| s.to_string()).collect(); debug!("Homeserver response lines {:?}", lines); if lines.len() == 1 && lines[0].is_empty() { diff --git a/tests/watcher/bookmarks/del.rs b/tests/watcher/bookmarks/del.rs index d65d789d..406666bd 100644 --- a/tests/watcher/bookmarks/del.rs +++ b/tests/watcher/bookmarks/del.rs @@ -46,7 +46,6 @@ async fn test_homeserver_unbookmark() -> Result<()> { uri: format!("pubky://{}/pub/pubky.app/posts/{}", author_id, post_id), created_at: chrono::Utc::now().timestamp_millis(), }; - let bookmark_blob = serde_json::to_vec(&bookmark)?; let bookmark_id = bookmark.create_id(); let bookmark_url = format!( "pubky://{}/pub/pubky.app/bookmarks/{}", @@ -54,7 +53,7 @@ async fn test_homeserver_unbookmark() -> Result<()> { ); // Put bookmark - test.put(&bookmark_url, bookmark_blob).await.unwrap(); + test.put(&bookmark_url, bookmark).await.unwrap(); // Step 4: Delete bookmark test.del(&bookmark_url).await?; diff --git a/tests/watcher/bookmarks/raw.rs b/tests/watcher/bookmarks/raw.rs index 7d78b24e..09acec28 100644 --- a/tests/watcher/bookmarks/raw.rs +++ b/tests/watcher/bookmarks/raw.rs @@ -36,7 +36,6 @@ async fn test_homeserver_bookmark() -> Result<()> { uri: format!("pubky://{}/pub/pubky.app/posts/{}", user_id, post_id), created_at: chrono::Utc::now().timestamp_millis(), }; - let bookmark_blob = serde_json::to_vec(&bookmark)?; let bookmark_id = bookmark.create_id(); let bookmark_url = format!( "pubky://{}/pub/pubky.app/bookmarks/{}", @@ -44,7 +43,7 @@ async fn test_homeserver_bookmark() -> Result<()> { ); // Put bookmark - test.put(&bookmark_url, bookmark_blob).await.unwrap(); + test.put(&bookmark_url, bookmark).await.unwrap(); // Step 4: Verify the bookmark exists in Nexus // GRAPH_OP: Assert if the event writes the graph diff --git a/tests/watcher/bookmarks/viewer.rs b/tests/watcher/bookmarks/viewer.rs index edd6923f..257ba9d5 100644 --- a/tests/watcher/bookmarks/viewer.rs +++ b/tests/watcher/bookmarks/viewer.rs @@ -46,7 +46,6 @@ async fn test_homeserver_viewer_bookmark() -> Result<()> { uri: format!("pubky://{}/pub/pubky.app/posts/{}", user_id, post_id), created_at: chrono::Utc::now().timestamp_millis(), }; - let bookmark_blob = serde_json::to_vec(&bookmark)?; let bookmark_id = bookmark.create_id(); let bookmark_url = format!( "pubky://{}/pub/pubky.app/bookmarks/{}", @@ -54,7 +53,7 @@ async fn test_homeserver_viewer_bookmark() -> Result<()> { ); // Put bookmark - test.put(&bookmark_url, bookmark_blob).await.unwrap(); + test.put(&bookmark_url, bookmark).await.unwrap(); // Step 4: Verify the bookmark exists in Nexus // GRAPH_OP: Assert if the event writes the graph diff --git a/tests/watcher/files/create.rs b/tests/watcher/files/create.rs index 3c959dbe..e3a9cb4a 100644 --- a/tests/watcher/files/create.rs +++ b/tests/watcher/files/create.rs @@ -33,7 +33,7 @@ async fn test_put_pubkyapp_file() -> Result<()> { let pubky_client = PubkyConnector::get_pubky_client()?; pubky_client .put(blob_url.as_str()) - .json(&json_data) + .json(&blob) .send() .await?; diff --git a/tests/watcher/files/delete.rs b/tests/watcher/files/delete.rs index 1315d752..2123db52 100644 --- a/tests/watcher/files/delete.rs +++ b/tests/watcher/files/delete.rs @@ -8,7 +8,6 @@ use pubky_nexus::{ models::{file::FileDetails, traits::Collection}, PubkyConnector, }; -use serde_json::to_vec; #[tokio_shared_rt::test(shared)] async fn test_delete_pubkyapp_file() -> Result<()> { @@ -29,11 +28,10 @@ async fn test_delete_pubkyapp_file() -> Result<()> { let blob = "Hello World!"; let blob_id = Timestamp::now().to_string(); let blob_url = format!("pubky://{}/pub/pubky.app/blobs/{}", user_id, blob_id); - let json_data = to_vec(blob)?; let pubky_client = PubkyConnector::get_pubky_client()?; pubky_client .put(blob_url.as_str()) - .json(&json_data) + .json(&blob) .send() .await?; diff --git a/tests/watcher/network/counts.rs b/tests/watcher/network/counts.rs index 08a9ec81..331e97b3 100644 --- a/tests/watcher/network/counts.rs +++ b/tests/watcher/network/counts.rs @@ -138,7 +138,7 @@ async fn test_large_network_scenario_counts() -> Result<()> { let pubky_client = PubkyConnector::get_pubky_client()?; pubky_client .put(mute_url.as_str()) - .json(&serde_json::to_vec(&mute)?) + .json(&mute) .send() .await?; _total_mutes += 1; @@ -171,8 +171,7 @@ async fn test_large_network_scenario_counts() -> Result<()> { bookmark.create_id() ); - test.put(&bookmark_url, serde_json::to_vec(&bookmark)?) - .await?; + test.put(&bookmark_url, &bookmark).await?; total_bookmarks += 1; } } @@ -200,7 +199,7 @@ async fn test_large_network_scenario_counts() -> Result<()> { let tag_url = format!("pubky://{}/pub/pubky.app/tags/{}", user_id, tag.create_id()); - test.put(&tag_url, serde_json::to_vec(&tag)?).await?; + test.put(&tag_url, &tag).await?; total_tags += 1; // FAILS: possibly deletes a tag twice and decrements twice in index. diff --git a/tests/watcher/posts/attachments.rs b/tests/watcher/posts/attachments.rs index 89aea7d1..b6e85e1c 100644 --- a/tests/watcher/posts/attachments.rs +++ b/tests/watcher/posts/attachments.rs @@ -30,7 +30,7 @@ async fn test_homeserver_post_attachments() -> Result<()> { let pubky_client = PubkyConnector::get_pubky_client()?; pubky_client .put(blob_url.as_str()) - .json(&json_data) + .json(&blob) .send() .await?; diff --git a/tests/watcher/posts/del_bookmarked_notification.rs b/tests/watcher/posts/del_bookmarked_notification.rs index d8e0f015..e6c4efda 100644 --- a/tests/watcher/posts/del_bookmarked_notification.rs +++ b/tests/watcher/posts/del_bookmarked_notification.rs @@ -50,13 +50,12 @@ async fn test_delete_bookmarked_post_notification() -> Result<()> { uri: format!("pubky://{}/pub/pubky.app/posts/{}", user_a_id, post_id), created_at: 0, }; - let bookmark_blob = serde_json::to_vec(&bookmark)?; let bookmark_url = format!( "pubky://{}/pub/pubky.app/bookmarks/{}", user_b_id, bookmark.create_id() ); - test.put(&bookmark_url, bookmark_blob).await?; + test.put(&bookmark_url, bookmark).await?; // User A deletes their post test.cleanup_post(&user_a_id, &post_id).await?; diff --git a/tests/watcher/posts/del_tagged_notification.rs b/tests/watcher/posts/del_tagged_notification.rs index fdc51f7f..b7f7e412 100644 --- a/tests/watcher/posts/del_tagged_notification.rs +++ b/tests/watcher/posts/del_tagged_notification.rs @@ -51,12 +51,11 @@ async fn test_delged_post_notification() -> Result<()> { label: label.to_string(), created_at: Utc::now().timestamp_millis(), }; - let tag_blob = serde_json::to_vec(&tag)?; let tag_id = tag.create_id(); let tag_url = format!("pubky://{}/pub/pubky.app/tags/{}", user_b_id, tag_id); // Put tag - test.put(&tag_url, tag_blob).await?; + test.put(&tag_url, tag).await?; // User A deletes their post test.cleanup_post(&user_a_id, &post_id).await?; diff --git a/tests/watcher/posts/del_with_relations.rs b/tests/watcher/posts/del_with_relations.rs index 339f955e..75ebe5a8 100644 --- a/tests/watcher/posts/del_with_relations.rs +++ b/tests/watcher/posts/del_with_relations.rs @@ -36,11 +36,10 @@ async fn test_delete_post_with_relationships() -> Result<()> { label: "funny".to_string(), created_at: Utc::now().timestamp_millis(), }; - let tag_blob = serde_json::to_vec(&tag)?; let tag_url = format!("pubky://{}/pub/pubky.app/tags/{}", user_id, tag.create_id()); // Put tag - test.put(&tag_url, tag_blob).await?; + test.put(&tag_url, tag).await?; // Delete the post using the event handler test.cleanup_post(&user_id, &post_id).await?; diff --git a/tests/watcher/posts/edit_bookmarked_notification.rs b/tests/watcher/posts/edit_bookmarked_notification.rs index 993eed59..4cdc30e1 100644 --- a/tests/watcher/posts/edit_bookmarked_notification.rs +++ b/tests/watcher/posts/edit_bookmarked_notification.rs @@ -51,24 +51,22 @@ async fn test_edit_bookmarked_post_notification() -> Result<()> { uri: format!("pubky://{}/pub/pubky.app/posts/{}", user_a_id, post_id), created_at: 0, }; - let bookmark_blob = serde_json::to_vec(&bookmark)?; let bookmark_url = format!( "pubky://{}/pub/pubky.app/bookmarks/{}", user_b_id, bookmark.create_id() ); - test.put(&bookmark_url, bookmark_blob).await?; + test.put(&bookmark_url, bookmark).await?; // User A edits their post post.content = "Edited post by User A".to_string(); - let edited_post_blob = serde_json::to_vec(&post)?; let edited_url = format!("pubky://{}/pub/pubky.app/posts/{}", user_a_id, post_id); // Overwrite existing post in the homeserver for the edited one let pubky_client = PubkyConnector::get_pubky_client()?; pubky_client .put(edited_url.as_str()) - .json(&edited_post_blob) + .json(&post) .send() .await?; test.ensure_event_processing_complete().await?; diff --git a/tests/watcher/posts/edit_reply_parent_notification.rs b/tests/watcher/posts/edit_reply_parent_notification.rs index 2659d2ab..d919ba4f 100644 --- a/tests/watcher/posts/edit_reply_parent_notification.rs +++ b/tests/watcher/posts/edit_reply_parent_notification.rs @@ -59,14 +59,13 @@ async fn test_edit_parent_post_notification() -> Result<()> { // User A edits their original post post.content = "Edited post by User A".to_string(); - let edited_post_blob = serde_json::to_vec(&post)?; let edited_url = format!("pubky://{}/pub/pubky.app/posts/{}", user_a_id, post_id); // Overwrite existing post in the homeserver with the edited one let pubky_client = PubkyConnector::get_pubky_client()?; pubky_client .put(edited_url.as_str()) - .json(&edited_post_blob) + .json(&post) .send() .await?; test.ensure_event_processing_complete().await?; diff --git a/tests/watcher/posts/edit_reposted_notification.rs b/tests/watcher/posts/edit_reposted_notification.rs index ac8cf498..c82569b3 100644 --- a/tests/watcher/posts/edit_reposted_notification.rs +++ b/tests/watcher/posts/edit_reposted_notification.rs @@ -59,14 +59,13 @@ async fn test_edit_reposted_post_notification() -> Result<()> { // User A edits their post post.content = "Edited post by User A".to_string(); - let edited_post_blob = serde_json::to_vec(&post)?; let edited_url = format!("pubky://{}/pub/pubky.app/posts/{}", user_a_id, post_id); // Overwrite existing post in the homeserver for the edited one let pubky_client = PubkyConnector::get_pubky_client()?; pubky_client .put(edited_url.as_str()) - .json(&edited_post_blob) + .json(&post) .send() .await?; test.ensure_event_processing_complete().await?; diff --git a/tests/watcher/posts/edit_tagged_notification.rs b/tests/watcher/posts/edit_tagged_notification.rs index a4d33dd3..d6b7b9a4 100644 --- a/tests/watcher/posts/edit_tagged_notification.rs +++ b/tests/watcher/posts/edit_tagged_notification.rs @@ -52,23 +52,21 @@ async fn test_edit_tagged_post_notification() -> Result<()> { label: label.to_string(), created_at: Utc::now().timestamp_millis(), }; - let tag_blob = serde_json::to_vec(&tag)?; let tag_id = tag.create_id(); let tag_url = format!("pubky://{}/pub/pubky.app/tags/{}", user_b_id, tag_id); // Put tag - test.put(&tag_url, tag_blob).await?; + test.put(&tag_url, tag).await?; // User A edits their post post.content = "Edited post by User A".to_string(); - let edited_post_blob = serde_json::to_vec(&post)?; let edited_url = format!("pubky://{}/pub/pubky.app/posts/{}", user_a_id, post_id); // Overwrite existing post in the homeserver with the edited one let pubky_client = PubkyConnector::get_pubky_client()?; pubky_client .put(edited_url.as_str()) - .json(&edited_post_blob) + .json(&post) .send() .await?; test.ensure_event_processing_complete().await?; diff --git a/tests/watcher/posts/reply_engagement.rs b/tests/watcher/posts/reply_engagement.rs index a36525eb..af188a1c 100644 --- a/tests/watcher/posts/reply_engagement.rs +++ b/tests/watcher/posts/reply_engagement.rs @@ -139,7 +139,6 @@ async fn test_homeserver_reply_engagement_control() -> Result<()> { label: label.to_string(), created_at: Utc::now().timestamp_millis(), }; - let tag_blob = serde_json::to_vec(&tag)?; let tag_url = format!( "pubky://{}/pub/pubky.app/tags/{}", @@ -147,7 +146,7 @@ async fn test_homeserver_reply_engagement_control() -> Result<()> { tag.create_id() ); - test.put(&tag_url, tag_blob).await?; + test.put(&tag_url, tag).await?; // Check if reply post is not in total engagement index: Sorted:Posts:Global:TotalEngagement:user_id:post_id let total_engagement = check_member_total_engagement_user_posts(&[&author_id, &reply_id]) diff --git a/tests/watcher/tags/post_del.rs b/tests/watcher/tags/post_del.rs index 96b5b6af..04ab2570 100644 --- a/tests/watcher/tags/post_del.rs +++ b/tests/watcher/tags/post_del.rs @@ -58,7 +58,6 @@ async fn test_homeserver_del_tag_post() -> Result<()> { label: label.to_string(), created_at: Utc::now().timestamp_millis(), }; - let tag_blob = serde_json::to_vec(&tag)?; let tag_url = format!( "pubky://{}/pub/pubky.app/tags/{}", tagger_user_id, @@ -66,7 +65,7 @@ async fn test_homeserver_del_tag_post() -> Result<()> { ); // Step 3: Creat & Delete the tag - test.put(&tag_url, tag_blob).await?; + test.put(&tag_url, tag).await?; test.del(&tag_url).await?; diff --git a/tests/watcher/tags/post_muti_user.rs b/tests/watcher/tags/post_muti_user.rs index f5a43a9e..c076cd9b 100644 --- a/tests/watcher/tags/post_muti_user.rs +++ b/tests/watcher/tags/post_muti_user.rs @@ -86,14 +86,13 @@ async fn test_homeserver_multi_user() -> Result<()> { label: label_water.to_string(), created_at: Utc::now().timestamp_millis(), }; - let tag_blob = serde_json::to_vec(&tag)?; let tag_url = format!( "pubky://{}/pub/pubky.app/tags/{}", tagger_id, tag.create_id() ); // Put tag - test.put(&tag_url, tag_blob).await?; + test.put(&tag_url, tag).await?; tag_urls.push(tag_url) } @@ -105,14 +104,13 @@ async fn test_homeserver_multi_user() -> Result<()> { label: label_fire.to_string(), created_at: Utc::now().timestamp_millis(), }; - let tag_blob = serde_json::to_vec(&tag)?; let tag_url = format!( "pubky://{}/pub/pubky.app/tags/{}", tagger_id, tag.create_id() ); // Put tag - test.put(&tag_url, tag_blob).await?; + test.put(&tag_url, tag).await?; tag_urls.push(tag_url) } diff --git a/tests/watcher/tags/post_notification.rs b/tests/watcher/tags/post_notification.rs index 70d0d7e6..6c9ef8b1 100644 --- a/tests/watcher/tags/post_notification.rs +++ b/tests/watcher/tags/post_notification.rs @@ -57,7 +57,6 @@ async fn test_homeserver_tag_post_notification() -> Result<()> { created_at: Utc::now().timestamp_millis(), }; - let tag_blob = serde_json::to_vec(&tag)?; let tag_url = format!( "pubky://{}/pub/pubky.app/tags/{}", tagger_id, @@ -65,7 +64,7 @@ async fn test_homeserver_tag_post_notification() -> Result<()> { ); // Put tag - test.put(tag_url.as_str(), tag_blob).await?; + test.put(tag_url.as_str(), tag).await?; // GRAPH_OP let post_tag = find_post_tag(&author_id, &post_id, label) diff --git a/tests/watcher/tags/post_put.rs b/tests/watcher/tags/post_put.rs index 95ba3c46..2940aa29 100644 --- a/tests/watcher/tags/post_put.rs +++ b/tests/watcher/tags/post_put.rs @@ -49,7 +49,6 @@ async fn test_homeserver_put_tag_post() -> Result<()> { label: label.to_string(), created_at: Utc::now().timestamp_millis(), }; - let tag_blob = serde_json::to_vec(&tag)?; let tag_url = format!( "pubky://{}/pub/pubky.app/tags/{}", tagger_user_id, @@ -63,7 +62,7 @@ async fn test_homeserver_put_tag_post() -> Result<()> { .unwrap_or_default(); // Put tag - test.put(&tag_url, tag_blob).await?; + test.put(&tag_url, tag).await?; // Step 4: Verify tag existence and data consistency diff --git a/tests/watcher/tags/user_notification.rs b/tests/watcher/tags/user_notification.rs index 2f973d2f..b6755f53 100644 --- a/tests/watcher/tags/user_notification.rs +++ b/tests/watcher/tags/user_notification.rs @@ -44,7 +44,6 @@ async fn test_homeserver_put_tag_user_notification() -> Result<()> { label: label.to_string(), created_at: Utc::now().timestamp_millis(), }; - let tag_blob = serde_json::to_vec(&tag)?; let tag_url = format!( "pubky://{}/pub/pubky.app/tags/{}", tagger_user_id, @@ -52,7 +51,7 @@ async fn test_homeserver_put_tag_user_notification() -> Result<()> { ); // Put tag - test.put(tag_url.as_str(), tag_blob).await?; + test.put(tag_url.as_str(), tag).await?; // Check if the tagged user received a notification let notifications = Notification::get_by_id(&tagged_user_id, Pagination::default()) diff --git a/tests/watcher/tags/user_to_self_put.rs b/tests/watcher/tags/user_to_self_put.rs index c60645e0..39b3f60f 100644 --- a/tests/watcher/tags/user_to_self_put.rs +++ b/tests/watcher/tags/user_to_self_put.rs @@ -32,11 +32,10 @@ async fn test_homeserver_put_tag_user_self() -> Result<()> { created_at: Utc::now().timestamp_millis(), }; - let tag_blob = serde_json::to_vec(&tag)?; let tag_url = format!("pubky://{}/pub/pubky.app/tags/{}", user_id, tag.create_id()); // Put tag - test.put(tag_url.as_str(), tag_blob).await?; + test.put(tag_url.as_str(), tag).await?; // Step 3: Verify tag existence and data consistency diff --git a/tests/watcher/tags/user_to_user_del.rs b/tests/watcher/tags/user_to_user_del.rs index c9d4e22c..f33a647a 100644 --- a/tests/watcher/tags/user_to_user_del.rs +++ b/tests/watcher/tags/user_to_user_del.rs @@ -45,7 +45,6 @@ async fn test_homeserver_del_tag_to_another_user() -> Result<()> { created_at: Utc::now().timestamp_millis(), }; - let tag_blob = serde_json::to_vec(&tag)?; let tag_url = format!( "pubky://{}/pub/pubky.app/tags/{}", tagger_user_id, @@ -53,7 +52,7 @@ async fn test_homeserver_del_tag_to_another_user() -> Result<()> { ); // Put tag - test.put(tag_url.as_str(), tag_blob).await?; + test.put(tag_url.as_str(), tag).await?; // Step 3: Delete the tag test.del(&tag_url).await?; diff --git a/tests/watcher/tags/user_to_user_put.rs b/tests/watcher/tags/user_to_user_put.rs index be6cd27d..f0eb3dc1 100644 --- a/tests/watcher/tags/user_to_user_put.rs +++ b/tests/watcher/tags/user_to_user_put.rs @@ -45,7 +45,6 @@ async fn test_homeserver_put_tag_user_another() -> Result<()> { created_at: Utc::now().timestamp_millis(), }; - let tag_blob = serde_json::to_vec(&tag)?; let tag_url = format!( "pubky://{}/pub/pubky.app/tags/{}", tagger_user_id, @@ -53,7 +52,7 @@ async fn test_homeserver_put_tag_user_another() -> Result<()> { ); // PUT post tag - test.put(tag_url.as_str(), tag_blob).await?; + test.put(tag_url.as_str(), tag).await?; // Step 3: Verify tag existence and data consistency diff --git a/tests/watcher/users/del_with_relations.rs b/tests/watcher/users/del_with_relations.rs index d57bea8d..4bd71a71 100644 --- a/tests/watcher/users/del_with_relations.rs +++ b/tests/watcher/users/del_with_relations.rs @@ -127,7 +127,7 @@ async fn test_delete_user_with_relationships() -> Result<()> { let pubky_client = PubkyConnector::get_pubky_client()?; pubky_client .put(blob_url.as_str()) - .json(&json_data) + .json(&blob) .send() .await?; diff --git a/tests/watcher/utils/watcher.rs b/tests/watcher/utils/watcher.rs index 03582f16..5125d985 100644 --- a/tests/watcher/utils/watcher.rs +++ b/tests/watcher/utils/watcher.rs @@ -8,7 +8,6 @@ use pubky_app_specs::{ use pubky_common::crypto::Keypair; use pubky_homeserver::Homeserver; use pubky_nexus::{events::Event, setup, types::DynError, Config, EventProcessor, PubkyConnector}; -use serde_json::to_vec; /// Struct to hold the setup environment for tests pub struct WatcherTest { @@ -70,19 +69,26 @@ impl WatcherTest { Ok(()) } - /// Sends a PUT request to the homeserver with the provided blob of data. + /// Sends a PUT request to the homeserver with the provided object of data. /// /// This function performs the following steps: /// 1. Retrieves the Pubky client from the PubkyConnector. - /// 2. Sends the blob data to the specified homeserver URI using a PUT request. + /// 2. Sends the object data to the specified homeserver URI using a PUT request. /// 3. Ensures that all event processing is complete after the PUT operation. /// /// # Parameters /// - `homeserver_uri`: The URI of the homeserver to write the data to. - /// - `blob`: A vector of bytes representing the data to be sent. - pub async fn put(&mut self, homeserver_uri: &str, blob: Vec) -> Result<()> { + /// - `object`: A generic type representing the data to be sent, which must implement `serde::Serialize`. + pub async fn put(&mut self, homeserver_uri: &str, object: T) -> Result<()> + where + T: serde::Serialize, + { let pubky_client = PubkyConnector::get_pubky_client()?; - pubky_client.put(homeserver_uri).json(&blob).send().await?; + pubky_client + .put(homeserver_uri) + .json(&object) + .send() + .await?; self.ensure_event_processing_complete().await?; Ok(()) } @@ -123,16 +129,10 @@ impl WatcherTest { pubky_client .signup(keypair, &self.homeserver.public_key()) .await?; - - let profile_json = to_vec(user)?; let url = format!("pubky://{}/pub/pubky.app/profile.json", user_id); // Write the user profile in the pubky.app repository - pubky_client - .put(url.as_str()) - .json(&profile_json) - .send() - .await?; + pubky_client.put(url.as_str()).json(&user).send().await?; // Index to Nexus from Homeserver using the events processor self.ensure_event_processing_complete().await?; @@ -141,12 +141,11 @@ impl WatcherTest { pub async fn create_post(&mut self, user_id: &str, post: &PubkyAppPost) -> Result { let post_id = post.create_id(); - let post_json = to_vec(post)?; let url = format!("pubky://{}/pub/pubky.app/posts/{}", user_id, post_id); // Write the post in the pubky.app repository PubkyConnector::get_pubky_client()? .put(url.as_str()) - .json(&post_json) + .json(&post) .send() .await?; @@ -181,11 +180,10 @@ impl WatcherTest { file: &PubkyAppFile, ) -> Result<(String, String)> { let file_id = file.create_id(); - let file_json = to_vec(file)?; let url = format!("pubky://{}/pub/pubky.app/files/{}", user_id, file_id); PubkyConnector::get_pubky_client()? .put(url.as_str()) - .json(&file_json) + .json(&file) .send() .await?; @@ -207,14 +205,13 @@ impl WatcherTest { let follow_relationship = PubkyAppFollow { created_at: Utc::now().timestamp_millis(), }; - let blob = serde_json::to_vec(&follow_relationship)?; let follow_url = format!( "pubky://{}/pub/pubky.app/follows/{}", follower_id, followee_id ); PubkyConnector::get_pubky_client()? .put(follow_url.as_str()) - .json(&blob) + .json(&follow_relationship) .send() .await?; // Process the event @@ -226,11 +223,10 @@ impl WatcherTest { let mute_relationship = PubkyAppFollow { created_at: Utc::now().timestamp_millis(), }; - let blob = serde_json::to_vec(&mute_relationship)?; let mute_url = format!("pubky://{}/pub/pubky.app/mutes/{}", muter_id, mutee_id); PubkyConnector::get_pubky_client()? .put(mute_url.as_str()) - .json(&blob) + .json(&mute_relationship) .send() .await?; // Process the event