From 25dd1901a3764ff0bc113619a0c868225e3cae20 Mon Sep 17 00:00:00 2001 From: Mika Date: Tue, 17 Jun 2025 14:28:45 +0200 Subject: [PATCH] cleanup tests --- crates/backend/tests/endpoints/auth.rs | 40 ----------------------- crates/backend/tests/endpoints/mod.rs | 2 +- crates/backend/tests/endpoints/user.rs | 45 ++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 41 deletions(-) create mode 100644 crates/backend/tests/endpoints/user.rs diff --git a/crates/backend/tests/endpoints/auth.rs b/crates/backend/tests/endpoints/auth.rs index 4f8428d..832c4f9 100644 --- a/crates/backend/tests/endpoints/auth.rs +++ b/crates/backend/tests/endpoints/auth.rs @@ -1,47 +1,7 @@ -use actix_web::{http::header, test}; -use serde::{Deserialize, Serialize}; - use crate::create_test_app; #[cfg(test)] mod tests { - use log::debug; - use serde_json::json; use super::*; - - #[derive(Deserialize, Serialize, Debug, Clone)] - struct UserLogin { - username: String, - name: String, - password: String, - } - - #[actix_web::test] - async fn test_login() { - let app = create_test_app!(); - - let req = test::TestRequest::post() - .uri("/api/v1/user") - .insert_header(header::ContentType::json()) - .set_payload( - json!({ - "username": "testuser", - "name": "Test User", - "password": "password" - }) - .to_string(), - ) - .send_request(&app) - .await; - - let status = req.status(); - let body = test::read_body(req).await; - let body_str = String::from_utf8_lossy(&body); - - debug!("Response status: {}", status); - debug!("Response body: {}", body_str); - - assert!(status.is_success() || status.is_client_error()); - } } diff --git a/crates/backend/tests/endpoints/mod.rs b/crates/backend/tests/endpoints/mod.rs index 5618255..802424c 100644 --- a/crates/backend/tests/endpoints/mod.rs +++ b/crates/backend/tests/endpoints/mod.rs @@ -3,4 +3,4 @@ pub mod auth; // pub mod group; // pub mod project; // pub mod template; -// pub mod user; +pub mod user; diff --git a/crates/backend/tests/endpoints/user.rs b/crates/backend/tests/endpoints/user.rs new file mode 100644 index 0000000..b2b1fd2 --- /dev/null +++ b/crates/backend/tests/endpoints/user.rs @@ -0,0 +1,45 @@ +use actix_web::{http::header, test}; +use serde::{Deserialize, Serialize}; + +use crate::create_test_app; + +#[cfg(test)] +mod tests { + use serde_json::json; + + use super::*; + + #[derive(Deserialize, Serialize, Debug, Clone)] + struct RespCreateUser { + id: String, + username: String, + name: String, + } + + #[actix_web::test] + async fn test_create_user() { + let app = create_test_app!(); + + let resp = test::TestRequest::post() + .uri("/api/v1/user") + .insert_header(header::ContentType::json()) + .set_payload( + json!({ + "username": "testuser", + "name": "Test User", + "password": "password" + }) + .to_string(), + ) + .send_request(&app) + .await; + + let status = resp.status(); + let user: RespCreateUser = test::read_body_json(resp).await; + + assert!(user.name == "Test User"); + assert!(user.username == "testuser"); + + assert!(status.is_success()); + } +}