Formatting

This commit is contained in:
2026-04-19 15:35:10 +02:00
parent 041f9015ca
commit 0d5c2f5888
42 changed files with 612 additions and 357 deletions
+101 -39
View File
@@ -4,10 +4,10 @@ use std::sync::Arc;
use std::time::Duration;
use axum::body::Body;
use axum::http::{header, Request, StatusCode};
use axum::http::{Request, StatusCode, header};
use doctate_server::analyze;
use doctate_server::config::{Config, User};
use serde_json::{json, Value};
use serde_json::{Value, json};
use tower::util::ServiceExt;
use wiremock::matchers::{method, path};
use wiremock::{Mock, MockServer, ResponseTemplate};
@@ -165,7 +165,10 @@ async fn analyze_foreign_case_returns_404() {
let app = doctate_server::create_router(config);
let cookie = login(app.clone(), "dr_a").await;
let resp = app.oneshot(analyze_request(foreign_case, &cookie)).await.unwrap();
let resp = app
.oneshot(analyze_request(foreign_case, &cookie))
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
}
@@ -175,7 +178,10 @@ async fn analyze_invalid_uuid_returns_400() {
let app = doctate_server::create_router(config);
let cookie = login(app.clone(), "dr_a").await;
let resp = app.oneshot(analyze_request("not-a-uuid", &cookie)).await.unwrap();
let resp = app
.oneshot(analyze_request("not-a-uuid", &cookie))
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}
@@ -189,7 +195,10 @@ async fn analyze_case_without_recordings_returns_400() {
let app = doctate_server::create_router(config);
let cookie = login(app.clone(), "dr_a").await;
let resp = app.oneshot(analyze_request(case_id, &cookie)).await.unwrap();
let resp = app
.oneshot(analyze_request(case_id, &cookie))
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}
@@ -204,7 +213,10 @@ async fn analyze_case_with_missing_transcript_returns_400() {
let app = doctate_server::create_router(config);
let cookie = login(app.clone(), "dr_a").await;
let resp = app.oneshot(analyze_request(case_id, &cookie)).await.unwrap();
let resp = app
.oneshot(analyze_request(case_id, &cookie))
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}
@@ -218,7 +230,10 @@ async fn analyze_case_without_llm_returns_503() {
let app = doctate_server::create_router(config);
let cookie = login(app.clone(), "dr_a").await;
let resp = app.oneshot(analyze_request(case_id, &cookie)).await.unwrap();
let resp = app
.oneshot(analyze_request(case_id, &cookie))
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::SERVICE_UNAVAILABLE);
}
@@ -232,15 +247,26 @@ async fn analyze_case_happy_path_writes_input_and_redirects() {
let case_id = "11111111-1111-1111-1111-111111111111";
let case_dir = seed_case(&config.data_path, "dr_a", case_id);
seed_recording(&case_dir, "10-00-00", Some("Patient klagt über Knie."));
seed_recording(&case_dir, "10-05-00", Some("Korrektur: links, nicht rechts."));
seed_recording(
&case_dir,
"10-05-00",
Some("Korrektur: links, nicht rechts."),
);
let app = doctate_server::create_router(config);
let cookie = login(app.clone(), "dr_a").await;
let resp = app.oneshot(analyze_request(case_id, &cookie)).await.unwrap();
let resp = app
.oneshot(analyze_request(case_id, &cookie))
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::SEE_OTHER);
assert_eq!(
resp.headers().get(header::LOCATION).unwrap().to_str().unwrap(),
resp.headers()
.get(header::LOCATION)
.unwrap()
.to_str()
.unwrap(),
"/web/cases"
);
@@ -267,10 +293,17 @@ async fn analyze_case_second_time_returns_409() {
let app = doctate_server::create_router(config);
let cookie = login(app.clone(), "dr_a").await;
let first = app.clone().oneshot(analyze_request(case_id, &cookie)).await.unwrap();
let first = app
.clone()
.oneshot(analyze_request(case_id, &cookie))
.await
.unwrap();
assert_eq!(first.status(), StatusCode::SEE_OTHER);
let second = app.oneshot(analyze_request(case_id, &cookie)).await.unwrap();
let second = app
.oneshot(analyze_request(case_id, &cookie))
.await
.unwrap();
assert_eq!(second.status(), StatusCode::CONFLICT);
}
@@ -286,7 +319,10 @@ async fn analyze_case_skips_blank_transcript_from_recordings() {
let app = doctate_server::create_router(config);
let cookie = login(app.clone(), "dr_a").await;
let resp = app.oneshot(analyze_request(case_id, &cookie)).await.unwrap();
let resp = app
.oneshot(analyze_request(case_id, &cookie))
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::SEE_OTHER);
let raw = std::fs::read_to_string(case_dir.join("analysis_input.json")).unwrap();
@@ -515,7 +551,10 @@ async fn recovery_skips_completed_analysis() {
let (tx, mut rx) = analyze::channel();
analyze::recovery::scan_and_enqueue(&tmp, &tx).await;
assert!(rx.try_recv().is_err(), "completed analysis must not re-enqueue");
assert!(
rx.try_recv().is_err(),
"completed analysis must not re-enqueue"
);
}
// ---------------------------------------------------------------------
@@ -543,7 +582,9 @@ async fn document_view_reads_document() {
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
let body = axum::body::to_bytes(resp.into_body(), usize::MAX).await.unwrap();
let body = axum::body::to_bytes(resp.into_body(), usize::MAX)
.await
.unwrap();
let body_str = String::from_utf8(body.to_vec()).unwrap();
assert!(body_str.contains("der Inhalt"), "expected content in body");
assert!(body_str.contains("Dokument"));
@@ -565,7 +606,10 @@ async fn analyze_deletes_old_document_and_writes_fresh_input() {
let app = doctate_server::create_router(config);
let cookie = login(app.clone(), "dr_a").await;
let resp = app.oneshot(analyze_request(case_id, &cookie)).await.unwrap();
let resp = app
.oneshot(analyze_request(case_id, &cookie))
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::SEE_OTHER);
assert!(
@@ -574,11 +618,11 @@ async fn analyze_deletes_old_document_and_writes_fresh_input() {
);
let input_path = case_dir.join("analysis_input.json");
assert!(input_path.exists(), "analysis_input.json missing");
let parsed: Value = serde_json::from_str(&std::fs::read_to_string(&input_path).unwrap()).unwrap();
let parsed: Value =
serde_json::from_str(&std::fs::read_to_string(&input_path).unwrap()).unwrap();
assert_eq!(parsed["recordings"].as_array().unwrap().len(), 2);
}
// ---------------------------------------------------------------------
// Soft-delete + Undo
// ---------------------------------------------------------------------
@@ -596,7 +640,11 @@ async fn delete_writes_marker_and_redirects() {
let resp = app.oneshot(delete_request(case_id, &cookie)).await.unwrap();
assert_eq!(resp.status(), StatusCode::SEE_OTHER);
assert_eq!(
resp.headers().get(header::LOCATION).unwrap().to_str().unwrap(),
resp.headers()
.get(header::LOCATION)
.unwrap()
.to_str()
.unwrap(),
"/web/cases"
);
let marker = case_dir.join(".deleted");
@@ -604,7 +652,10 @@ async fn delete_writes_marker_and_redirects() {
let raw = std::fs::read_to_string(&marker).unwrap();
let parsed: Value = serde_json::from_str(&raw).unwrap();
assert!(parsed["batch"].is_string(), "batch must be a UUID string");
assert!(parsed["deleted_at"].is_string(), "deleted_at must be a string");
assert!(
parsed["deleted_at"].is_string(),
"deleted_at must be a string"
);
}
#[tokio::test]
@@ -617,7 +668,11 @@ async fn deleted_case_returns_404_on_detail() {
let app = doctate_server::create_router(config);
let cookie = login(app.clone(), "dr_a").await;
let resp = app.clone().oneshot(delete_request(case_id, &cookie)).await.unwrap();
let resp = app
.clone()
.oneshot(delete_request(case_id, &cookie))
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::SEE_OTHER);
let resp = app
@@ -647,12 +702,20 @@ async fn undo_delete_restores_latest_batch_only() {
let cookie = login(app.clone(), "dr_a").await;
// Two separate delete clicks → two distinct batches.
let _ = app.clone().oneshot(delete_request(case_a, &cookie)).await.unwrap();
let _ = app
.clone()
.oneshot(delete_request(case_a, &cookie))
.await
.unwrap();
// Batch IDs derive from `now_rfc3339()`, which rounds to whole
// seconds — so the sleep must cross a second boundary for the two
// deletes to land in distinct batches.
tokio::time::sleep(Duration::from_millis(1100)).await;
let _ = app.clone().oneshot(delete_request(case_b, &cookie)).await.unwrap();
let _ = app
.clone()
.oneshot(delete_request(case_b, &cookie))
.await
.unwrap();
let undo = app
.clone()
@@ -669,7 +732,10 @@ async fn undo_delete_restores_latest_batch_only() {
assert_eq!(undo.status(), StatusCode::SEE_OTHER);
// case_b (latest delete) restored, case_a still deleted.
assert!(!dir_b.join(".deleted").exists(), "case_b marker should be gone");
assert!(
!dir_b.join(".deleted").exists(),
"case_b marker should be gone"
);
assert!(dir_a.join(".deleted").exists(), "case_a marker must remain");
}
@@ -701,9 +767,14 @@ async fn bulk_delete_shares_one_batch_uuid() {
.unwrap();
assert_eq!(resp.status(), StatusCode::SEE_OTHER);
let m_a: Value = serde_json::from_str(&std::fs::read_to_string(dir_a.join(".deleted")).unwrap()).unwrap();
let m_b: Value = serde_json::from_str(&std::fs::read_to_string(dir_b.join(".deleted")).unwrap()).unwrap();
assert_eq!(m_a["batch"], m_b["batch"], "bulk-delete must share batch UUID");
let m_a: Value =
serde_json::from_str(&std::fs::read_to_string(dir_a.join(".deleted")).unwrap()).unwrap();
let m_b: Value =
serde_json::from_str(&std::fs::read_to_string(dir_b.join(".deleted")).unwrap()).unwrap();
assert_eq!(
m_a["batch"], m_b["batch"],
"bulk-delete must share batch UUID"
);
}
#[tokio::test]
@@ -814,15 +885,9 @@ async fn reset_case_clears_derived_and_unfails_audio() {
let app = doctate_server::create_router(config);
let cookie = login(app.clone(), "dr_a").await;
let resp = app
.oneshot(reset_request(case_id, &cookie))
.await
.unwrap();
let resp = app.oneshot(reset_request(case_id, &cookie)).await.unwrap();
assert_eq!(resp.status(), StatusCode::SEE_OTHER);
assert_eq!(
resp.headers().get(header::LOCATION).unwrap(),
"/web/cases"
);
assert_eq!(resp.headers().get(header::LOCATION).unwrap(), "/web/cases");
// Audio preserved, .failed renamed to .m4a.
assert!(dir.join("2026-04-15T09-00-00Z.m4a").exists());
@@ -848,10 +913,7 @@ async fn reset_case_requires_admin() {
let app = doctate_server::create_router(config);
let cookie = login(app.clone(), "dr_a").await;
let resp = app
.oneshot(reset_request(case_id, &cookie))
.await
.unwrap();
let resp = app.oneshot(reset_request(case_id, &cookie)).await.unwrap();
assert_eq!(resp.status(), StatusCode::FORBIDDEN);
// Nothing touched.