cleanup tests
This commit is contained in:
parent
cc58c15c71
commit
25dd1901a3
3 changed files with 46 additions and 41 deletions
|
@ -1,47 +1,7 @@
|
||||||
use actix_web::{http::header, test};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::create_test_app;
|
use crate::create_test_app;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use log::debug;
|
|
||||||
use serde_json::json;
|
|
||||||
|
|
||||||
use super::*;
|
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,4 @@ pub mod auth;
|
||||||
// pub mod group;
|
// pub mod group;
|
||||||
// pub mod project;
|
// pub mod project;
|
||||||
// pub mod template;
|
// pub mod template;
|
||||||
// pub mod user;
|
pub mod user;
|
||||||
|
|
45
crates/backend/tests/endpoints/user.rs
Normal file
45
crates/backend/tests/endpoints/user.rs
Normal file
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue