|
| 1 | +use axum::{ |
| 2 | + body::Body, |
| 3 | + http::{self, Request, StatusCode}, |
| 4 | +}; |
| 5 | +use f5a_services::om::UserDetail; |
| 6 | +use tower::ServiceExt; |
| 7 | + |
| 8 | +use crate::{setup::TestContext, test_ext::IntoValue, users::migrations}; |
| 9 | + |
| 10 | +#[tokio::test] |
| 11 | +async fn test_read_user_detail() { |
| 12 | + let ctx = TestContext::new().await; |
| 13 | + ctx.setup_schema().await; |
| 14 | + |
| 15 | + migrations::insert_idesoft_user(ctx.db.as_ref()) |
| 16 | + .await |
| 17 | + .unwrap(); |
| 18 | + |
| 19 | + let app = ctx.configure(); |
| 20 | + |
| 21 | + let req = Request::get("/api/users/1") |
| 22 | + .header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref()) |
| 23 | + .body(Body::empty()) |
| 24 | + .unwrap(); |
| 25 | + |
| 26 | + let res = app.oneshot(req).await.unwrap(); |
| 27 | + assert_eq!(res.status(), StatusCode::OK); |
| 28 | + |
| 29 | + let value = res.into_value::<UserDetail>().await; |
| 30 | + assert_eq!(value.id, 1); |
| 31 | + assert_eq!(value.username, "idesoftd"); |
| 32 | + assert_eq!(value.disabled, true); |
| 33 | +} |
| 34 | + |
| 35 | +#[tokio::test] |
| 36 | +async fn it_returns_not_found_for_missing_user() { |
| 37 | + let ctx = TestContext::new().await; |
| 38 | + ctx.setup_schema().await; |
| 39 | + |
| 40 | + migrations::insert_idesoft_user(ctx.db.as_ref()) |
| 41 | + .await |
| 42 | + .unwrap(); |
| 43 | + |
| 44 | + let app = ctx.configure(); |
| 45 | + |
| 46 | + let req = Request::get("/api/users/2") |
| 47 | + .header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref()) |
| 48 | + .body(Body::empty()) |
| 49 | + .unwrap(); |
| 50 | + |
| 51 | + let res = app.oneshot(req).await.unwrap(); |
| 52 | + assert_eq!(res.status(), StatusCode::NOT_FOUND); |
| 53 | +} |
0 commit comments