Refactor test
Rust Build / Test Suite (pull_request) Successful in 1m8s
Rust Build / Rustfmt (pull_request) Successful in 1m10s
Rust Build / Check (pull_request) Successful in 1m40s
Rust Build / Clippy (pull_request) Successful in 2m9s
Rust Build / build (pull_request) Successful in 3m0s
Rust Build / Test Suite (pull_request) Successful in 1m8s
Rust Build / Rustfmt (pull_request) Successful in 1m10s
Rust Build / Check (pull_request) Successful in 1m40s
Rust Build / Clippy (pull_request) Successful in 2m9s
Rust Build / build (pull_request) Successful in 3m0s
This commit is contained in:
+24
-16
@@ -170,16 +170,20 @@ const TEST_SERVICE_USERNAME: &str = "swoon";
|
||||
/// Test service passphrase
|
||||
const TEST_SERVICE_PASSPHRASE: &str = "4n5cf349tfy34w857ty39wq45nfdq23";
|
||||
|
||||
async fn convert_response<T>(response: axum::response::Response) -> Result<T, std::io::Error>
|
||||
where
|
||||
T: serde::de::DeserializeOwned,
|
||||
{
|
||||
match axum::body::to_bytes(response.into_body(), usize::MAX).await {
|
||||
Ok(body) => {
|
||||
let resp: T = serde_json::from_slice(&body).unwrap();
|
||||
Ok(resp)
|
||||
mod util {
|
||||
pub async fn convert_response<T>(
|
||||
response: axum::response::Response,
|
||||
) -> Result<T, std::io::Error>
|
||||
where
|
||||
T: serde::de::DeserializeOwned,
|
||||
{
|
||||
match axum::body::to_bytes(response.into_body(), usize::MAX).await {
|
||||
Ok(body) => {
|
||||
let resp: T = serde_json::from_slice(&body).unwrap();
|
||||
Ok(resp)
|
||||
}
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
}
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +198,9 @@ async fn register_user(
|
||||
response.status()
|
||||
)))
|
||||
} else {
|
||||
match convert_response::<callers::register::response::Response>(response).await {
|
||||
match util::convert_response::<callers::register::response::Response>(response)
|
||||
.await
|
||||
{
|
||||
Ok(response) => {
|
||||
if response.data.len() > 0 {
|
||||
let user = response.data[0].clone();
|
||||
@@ -224,7 +230,9 @@ async fn login_user(
|
||||
response.status()
|
||||
)))
|
||||
} else {
|
||||
match convert_response::<callers::login::response::LoginResponse>(response).await {
|
||||
match util::convert_response::<callers::login::response::LoginResponse>(response)
|
||||
.await
|
||||
{
|
||||
Ok(response) => {
|
||||
if response.data.len() > 0 {
|
||||
let user = response.data[0].clone();
|
||||
@@ -252,9 +260,9 @@ async fn register_service_user(
|
||||
response.status()
|
||||
)))
|
||||
} else {
|
||||
match convert_response::<callers::register::response::RegisterServiceUserResponse>(
|
||||
response,
|
||||
)
|
||||
match util::convert_response::<
|
||||
callers::register::response::RegisterServiceUserResponse,
|
||||
>(response)
|
||||
.await
|
||||
{
|
||||
Ok(response) => {
|
||||
@@ -286,7 +294,7 @@ async fn login_service_user(
|
||||
response.status()
|
||||
)))
|
||||
} else {
|
||||
match convert_response::<callers::login::response::ServiceUserLoginResponse>(
|
||||
match util::convert_response::<callers::login::response::ServiceUserLoginResponse>(
|
||||
response,
|
||||
)
|
||||
.await
|
||||
@@ -415,7 +423,7 @@ async fn test_register_service_user() {
|
||||
|
||||
match requests::register_service_user(&app).await {
|
||||
Ok(response) => {
|
||||
match convert_response::<callers::register::response::RegisterServiceUserResponse>(
|
||||
match util::convert_response::<callers::register::response::RegisterServiceUserResponse>(
|
||||
response,
|
||||
)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user