Files
Brummel af3377a6bc refactor(tests): migrate remaining batches to tests/common/
Finishes the lift of shared helpers into `tests/common/`. Covered:
- health, web, oneliners_api, upload (31 tests; upload exercises the
  new `multipart_upload_body` helper driven by doctate_common field
  constants)
- sse_integration, sse_cleanup, transcribe, oneliner_heal_decoupled,
  silent_case_empty, failed_only_case_empty_oneliner,
  transient_failure_retries (24 tests)

Also applied cargo fmt across the test tree and fixed one clippy
needless_borrows_for_generic_args warning in analyze_test.

All 387 tests pass; 3 ignored (as before).

Side effect: health_test previously used a hardcoded `/tmp/doctate-test`
data path, which parallel `cargo test` runs could collide on. The
migration replaces it with the common unique-tmpdir pattern, removing
a latent flake.
2026-04-22 10:51:33 +02:00

68 lines
1.7 KiB
Rust

mod common;
use axum::body::Body;
use axum::http::{Request, StatusCode};
use tower::util::ServiceExt;
use common::{TestConfig, test_user};
#[tokio::test]
async fn valid_api_key_returns_user() {
let app =
doctate_server::create_router(TestConfig::new().with_user(test_user("dr_test")).build());
let response = app
.oneshot(
Request::builder()
.uri("/api/debug/whoami")
.header("X-API-Key", "key-dr_test")
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let json = common::body_json(response).await;
assert_eq!(json["slug"], "dr_test");
assert_eq!(json["role"], "doctor");
}
#[tokio::test]
async fn invalid_api_key_returns_401() {
let app =
doctate_server::create_router(TestConfig::new().with_user(test_user("dr_test")).build());
let response = app
.oneshot(
Request::builder()
.uri("/api/debug/whoami")
.header("X-API-Key", "wrong-key")
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
}
#[tokio::test]
async fn missing_api_key_returns_401() {
let app =
doctate_server::create_router(TestConfig::new().with_user(test_user("dr_test")).build());
let response = app
.oneshot(
Request::builder()
.uri("/api/debug/whoami")
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
}