From 95e4616b15eec3393c990282cae452f50667c784 Mon Sep 17 00:00:00 2001 From: Scott Lyons Date: Sat, 10 Aug 2024 19:35:07 -0700 Subject: [PATCH] test(integration-test): adding comment tests --- szurubooru-integration-test/src/main.rs | 89 ++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/szurubooru-integration-test/src/main.rs b/szurubooru-integration-test/src/main.rs index 1ede1a7..9849b65 100644 --- a/szurubooru-integration-test/src/main.rs +++ b/szurubooru-integration-test/src/main.rs @@ -4,7 +4,7 @@ use std::path::Path; use std::process::Stdio; use std::time::Duration; use szurubooru_client::models::*; -use szurubooru_client::tokens::QueryToken; +use szurubooru_client::tokens::{CommentNamedToken, QueryToken}; use szurubooru_client::*; use tokio::process::Command; use tracing::level_filters::LevelFilter; @@ -53,6 +53,7 @@ async fn main() -> Result<(), Box> { test_creating_posts(&auth_client).await; test_pool_categories(&auth_client).await; test_pools(&auth_client).await; + test_comments(&auth_client).await; Command::new("sh") .current_dir(env!("CARGO_MANIFEST_DIR")) @@ -668,3 +669,89 @@ async fn test_pools(client: &SzurubooruClient) { .await .expect("Unable to merge pools"); } + +#[instrument(skip(client))] +async fn test_comments(client: &SzurubooruClient) { + info!("Testing comments"); + + info!("Listing comments"); + let comment_list = client + .request() + .list_comments(None) + .await + .expect("Unable to list comments"); + + let f4_results = client + .request() + .list_posts(Some(&vec![QueryToken::anonymous("cat")])) + .await + .expect("Could not list posts by tag cat"); + let post_ids = f4_results + .results + .into_iter() + .map(|p| p.id.unwrap()) + .collect::>(); + let post_id = *post_ids.first().unwrap(); + + info!("Creating comment"); + let create_comment = CreateUpdateCommentBuilder::default() + .text("Excellent cat!".to_string()) + .post_id(post_id) + .build() + .expect("Unable to create comment object"); + let comment = client + .request() + .create_comment(&create_comment) + .await + .expect("Unable to create comment"); + + info!("Updating comment"); + let update_comment = CreateUpdateCommentBuilder::default() + .text("Beautiful cat!".to_string()) + .version(comment.version.unwrap()) + .build() + .expect("Unable to create comment update object"); + let comment = client + .request() + .update_comment(comment.id.unwrap(), &update_comment) + .await + .expect("Unable to update comment"); + + info!("Getting comment"); + let comment = client + .request() + .get_comment(comment.id.unwrap()) + .await + .expect("Unable to fetch comment"); + + info!("Getting all comments for post"); + let query_vec = vec![QueryToken::token( + CommentNamedToken::Post, + post_id.to_string(), + )]; + let comment_list = client + .request() + //.list_comments(None) + .list_comments(Some(&vec![QueryToken::token( + CommentNamedToken::Post, + post_id.to_string(), + )])) + .await + .expect("Unable to fetch comments for post"); + assert_ne!(comment_list.total, 0); + + info!("Rating comment"); + let comment = client + .request() + .rate_comment(comment.id.unwrap(), -1) + .await + .expect("Could not rate comment"); + assert_eq!(comment.own_score, Some(-1)); + + info!("Deleting comment"); + client + .request() + .delete_comment(comment.id.unwrap(), comment.version.unwrap()) + .await + .expect("Could not delete comment"); +}