Update unit test

This commit is contained in:
2022-09-24 10:17:05 +00:00
committed by GitHub
parent 2597b41220
commit 7774b1d4e7
2 changed files with 21 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
use super::UnitTestContext;
use crate::error::PixivDownloaderError;
use bytes::BytesMut;
use hyper::{Body, Request};
/// Test authentification methods
/// Returns token
pub async fn test(ctx: &UnitTestContext) -> Result<BytesMut, PixivDownloaderError> {
let re = Request::builder().uri("/auth").body(Body::empty())?;
let res = ctx.request_json(re).await?.unwrap();
assert_eq!(res["has_root_user"].as_bool(), Some(false));
let re = Request::builder().uri("/auth/pubkey").body(Body::empty())?;
let res = ctx.request_json(re).await?.unwrap();
let ok = res["ok"].as_bool().unwrap();
if !ok {
panic!("Failed to get public key.");
}
Ok(BytesMut::new())
}

View File

@@ -1,3 +1,4 @@
mod auth;
mod version;
use super::context::ServerContext;
@@ -76,5 +77,6 @@ async fn test() -> Result<(), PixivDownloaderError> {
}
let ctx = UnitTestContext::new().await;
version::test(&ctx).await?;
auth::test(&ctx).await?;
Ok(())
}