test(integration-test): testing snapshot fetching
This commit is contained in:
parent
ada4a7733c
commit
6d840de69f
3 changed files with 16 additions and 72 deletions
|
|
@ -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(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -5,6 +5,7 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4.38"
|
chrono = "0.4.38"
|
||||||
|
sha1 = "0.10.6"
|
||||||
szurubooru-client = { path = "../szurubooru-client" }
|
szurubooru-client = { path = "../szurubooru-client" }
|
||||||
tokio = { version = "1.39.2", features = ["full", "test-util", "tracing"] }
|
tokio = { version = "1.39.2", features = ["full", "test-util", "tracing"] }
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use chrono::Months;
|
use chrono::Months;
|
||||||
|
use sha1::{Digest, Sha1};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
@ -56,6 +57,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
test_pools(&auth_client).await;
|
test_pools(&auth_client).await;
|
||||||
test_comments(&auth_client).await;
|
test_comments(&auth_client).await;
|
||||||
test_users(&auth_client).await;
|
test_users(&auth_client).await;
|
||||||
|
test_snapshots(&auth_client).await;
|
||||||
|
|
||||||
Command::new("sh")
|
Command::new("sh")
|
||||||
.current_dir(env!("CARGO_MANIFEST_DIR"))
|
.current_dir(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
|
@ -869,3 +871,16 @@ async fn test_users(client: &SzurubooruClient) {
|
||||||
.await
|
.await
|
||||||
.expect("Could not delete token");
|
.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);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue