Lines
99.53 %
Functions
100 %
Branches
use axum::{
Router,
body::Body,
http::Request,
routing::{get, post},
};
use serde_json::json;
use tower::ServiceExt;
use crate::common::{create_mock_jwt_auth, create_mock_user, create_test_app_state};
#[tokio::test]
async fn test_tag_create_without_auth() {
let app_state = create_test_app_state().await;
let app = Router::new()
.route(
"/tag/create/submit",
post(web::pages::tag::create::create_tag),
)
.with_state(app_state);
let tag_data = json!({
"tag_name": "Test Tag",
"tag_value": "test_value",
"description": null
});
let response = app
.oneshot(
Request::builder()
.method("POST")
.uri("/tag/create/submit")
.header("content-type", "application/json")
.body(Body::from(tag_data.to_string()))
.unwrap(),
.await
.unwrap();
assert!(response.status().is_client_error() || response.status().is_server_error());
}
async fn test_tag_create_with_invalid_json() {
.body(Body::from("invalid json"))
async fn test_tag_create_with_mock_auth() {
let mock_user = create_mock_user();
let jwt_auth = create_mock_jwt_auth(mock_user);
.layer(axum::middleware::from_fn_with_state(
app_state.clone(),
move |mut req: axum::http::Request<Body>, next: axum::middleware::Next| {
let jwt_auth = jwt_auth.clone();
async move {
req.extensions_mut().insert(jwt_auth);
next.run(req).await
},
))
.with_state(app_state.clone());
assert!(
response.status().is_success() || response.status().is_server_error(),
"Expected success or server error, got: {}",
response.status()
);
async fn test_tag_create_with_description() {
"tag_name": "Category",
"tag_value": "category1",
"description": "Test description"
async fn test_tag_list_without_auth() {
.route("/tag/list", get(web::pages::tag::list::tag_table))
.method("GET")
.uri("/tag/list")
.body(Body::empty())
async fn test_tag_list_with_mock_auth() {
if let Some(content_type) = response.headers().get("content-type") {
let content_type_str = content_type.to_str().unwrap_or("");
content_type_str.contains("text/") || content_type_str.is_empty(),
"Expected text content type, got: {}",
content_type_str
async fn test_tag_edit_without_auth() {
.route("/tag/edit/submit", post(web::pages::tag::edit::edit_tag))
"id": "550e8400-e29b-41d4-a716-446655440000",
"tag_name": "Updated Tag",
"tag_value": "updated_value",
"description": "Updated description"
.uri("/tag/edit/submit")
async fn test_tag_edit_with_mock_auth() {
async fn test_tag_delete_without_auth() {
.route("/tag/delete/{id}", post(web::pages::tag::edit::delete_tag))
.uri("/tag/delete/550e8400-e29b-41d4-a716-446655440000")
async fn test_tag_delete_with_mock_auth() {
async fn test_tag_edit_remove_description() {
"tag_name": "Tag Name",
"tag_value": "tag_value",
async fn test_transaction_tag_create_without_auth() {
"/transaction/{id}/tag/create/submit",
post(web::pages::tag::create::create_transaction_tag),
"tag_value": "expense",
"description": "Transaction category"
.uri("/transaction/550e8400-e29b-41d4-a716-446655440000/tag/create/submit")
async fn test_transaction_tag_create_with_mock_auth() {
async fn test_transaction_tag_create_invalid_uuid() {
.uri("/transaction/invalid-uuid/tag/create/submit")
assert_eq!(response.status(), axum::http::StatusCode::BAD_REQUEST);