From 6d840de69f2c0c6c1e708b43ea4960ce02c488f3 Mon Sep 17 00:00:00 2001 From: Scott Lyons Date: Sun, 11 Aug 2024 13:38:05 -0700 Subject: [PATCH] test(integration-test): testing snapshot fetching --- szurubooru-client/src/tests.rs | 72 ------------------------- szurubooru-integration-test/Cargo.toml | 1 + szurubooru-integration-test/src/main.rs | 15 ++++++ 3 files changed, 16 insertions(+), 72 deletions(-) delete mode 100644 szurubooru-client/src/tests.rs diff --git a/szurubooru-client/src/tests.rs b/szurubooru-client/src/tests.rs deleted file mode 100644 index 5a8e15a..0000000 --- a/szurubooru-client/src/tests.rs +++ /dev/null @@ -1,72 +0,0 @@ -#[cfg(test)] -mod tests { - use crate::client::SzurubooruClient; - use crate::errors::*; - use crate::models::*; - use mockito::Server; - use serde_json::{json, to_string}; - - static TEST_AUTH: &str = "Token dGVzdDp0ZXN0"; - static TEST2_AUTH: &str = "Token dGVzdDI6dGVzdAo="; - static ADMIN_AUTH: &str = "Token YWRtaW46dGVzdA=="; - - #[tokio::test] - async fn test_tag_categories() -> SzurubooruResult<()> { - let mut server = Server::new_async().await; - - let test_client = SzurubooruClient::new_with_token(&server.url(), "admin", "test", true)?; - let admin_get_tcs = server - .mock("GET", "/tag-categories") - .match_header("Authorization", ADMIN_AUTH) - .with_body( - to_string(&json!({ - "results": [ - { - "version": 0, - "name": "my-tag-category", - "color": "blue", - "usages": 1, - "order": "asc", - "default": false - } - ] - })) - .unwrap(), - ) - .create_async() - .await; - let tc_res = test_client.request().list_tag_categories().await?; - admin_get_tcs.assert_async().await; - assert_eq!(tc_res.results.len(), 1); - assert_eq!( - tc_res.results.first().unwrap().color, - Some("blue".to_string()) - ); - - let fail_tcs = server - .mock("GET", "/tag-categories") - .match_header("Authorization", TEST_AUTH) - .with_body( - to_string(&json!({ - "name": "AuthError", - "title": "Auth Error", - "description": "Authentication error" - })) - .unwrap(), - ) - .create_async() - .await; - - let test_client = SzurubooruClient::new_with_token(&server.url(), "test", "test", true)?; - let failed_tc_res = test_client.request().list_tag_categories().await; - fail_tcs.assert_async().await; - match failed_tc_res { - Err(SzurubooruClientError::SzurubooruServerError(e)) => { - assert_eq!(e.name, SzurubooruServerErrorType::AuthError) - } - _ => assert!(false), - } - - Ok(()) - } -} diff --git a/szurubooru-integration-test/Cargo.toml b/szurubooru-integration-test/Cargo.toml index 7801f51..fa4c48f 100644 --- a/szurubooru-integration-test/Cargo.toml +++ b/szurubooru-integration-test/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] chrono = "0.4.38" +sha1 = "0.10.6" szurubooru-client = { path = "../szurubooru-client" } tokio = { version = "1.39.2", features = ["full", "test-util", "tracing"] } tracing = "0.1.40" diff --git a/szurubooru-integration-test/src/main.rs b/szurubooru-integration-test/src/main.rs index fa337ea..10d5e03 100644 --- a/szurubooru-integration-test/src/main.rs +++ b/szurubooru-integration-test/src/main.rs @@ -1,4 +1,5 @@ use chrono::Months; +use sha1::{Digest, Sha1}; use std::error::Error; use std::fs::File; use std::path::Path; @@ -56,6 +57,7 @@ async fn main() -> Result<(), Box> { test_pools(&auth_client).await; test_comments(&auth_client).await; test_users(&auth_client).await; + test_snapshots(&auth_client).await; Command::new("sh") .current_dir(env!("CARGO_MANIFEST_DIR")) @@ -869,3 +871,16 @@ async fn test_users(client: &SzurubooruClient) { .await .expect("Could not delete token"); } + +#[instrument(skip(client))] +async fn test_snapshots(client: &SzurubooruClient) { + info!("Testing snapshots"); + + info!("Listing snapshots"); + let snap_list = client + .request() + .list_snapshots(None) + .await + .expect("Could not list snapshots"); + assert!(snap_list.total > 0); +}