feat: DEFAULT_LANGUAGE/DEFAULT_TIMEZONE config + public GET /api/config
This commit is contained in:
@@ -13,6 +13,8 @@ fn state(pool: PgPool) -> AppState {
|
||||
app_name: "Test".into(),
|
||||
cookie_secure: false,
|
||||
search: None,
|
||||
default_language: "sv".into(),
|
||||
default_timezone: "Europe/Stockholm".into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ fn state(pool: PgPool) -> AppState {
|
||||
app_name: "Test".into(),
|
||||
cookie_secure: false,
|
||||
search: None,
|
||||
default_language: "sv".into(),
|
||||
default_timezone: "Europe/Stockholm".into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ fn state(pool: PgPool) -> AppState {
|
||||
app_name: "Test".into(),
|
||||
cookie_secure: false,
|
||||
search: None,
|
||||
default_language: "sv".into(),
|
||||
default_timezone: "Europe/Stockholm".into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ fn state(pool: PgPool) -> AppState {
|
||||
app_name: "Test".into(),
|
||||
cookie_secure: false,
|
||||
search: None,
|
||||
default_language: "sv".into(),
|
||||
default_timezone: "Europe/Stockholm".into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ fn state(pool: PgPool, search: Option<SearchClient>) -> AppState {
|
||||
app_name: "Test".into(),
|
||||
cookie_secure: false,
|
||||
search,
|
||||
default_language: "sv".into(),
|
||||
default_timezone: "Europe/Stockholm".into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
use api::{AppState, build_app};
|
||||
use axum::body::Body;
|
||||
use axum::http::{Request, StatusCode};
|
||||
use http_body_util::BodyExt;
|
||||
use sqlx::PgPool;
|
||||
use tower::ServiceExt;
|
||||
|
||||
fn state(pool: PgPool) -> AppState {
|
||||
AppState {
|
||||
db: db::Db::from_pool(pool),
|
||||
app_name: "Test Museum".into(),
|
||||
cookie_secure: false,
|
||||
search: None,
|
||||
default_language: "sv".into(),
|
||||
default_timezone: "Europe/Stockholm".into(),
|
||||
}
|
||||
}
|
||||
|
||||
#[sqlx::test(migrations = "../db/migrations")]
|
||||
async fn config_is_public_and_reflects_state(pool: PgPool) {
|
||||
let app = build_app(state(pool));
|
||||
|
||||
let resp = app
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.uri("/api/config")
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
|
||||
let body: serde_json::Value =
|
||||
serde_json::from_slice(&resp.into_body().collect().await.unwrap().to_bytes()).unwrap();
|
||||
|
||||
assert_eq!(body["app_name"], "Test Museum");
|
||||
assert_eq!(body["default_language"], "sv");
|
||||
assert_eq!(body["default_timezone"], "Europe/Stockholm");
|
||||
}
|
||||
@@ -11,6 +11,8 @@ fn state(pool: PgPool, app_name: &str) -> AppState {
|
||||
app_name: app_name.to_string(),
|
||||
cookie_secure: false,
|
||||
search: None,
|
||||
default_language: "sv".into(),
|
||||
default_timezone: "Europe/Stockholm".into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ fn state(pool: PgPool) -> AppState {
|
||||
app_name: "Test".to_string(),
|
||||
cookie_secure: false,
|
||||
search: None,
|
||||
default_language: "sv".into(),
|
||||
default_timezone: "Europe/Stockholm".into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ fn state(pool: PgPool, search: SearchClient) -> AppState {
|
||||
app_name: "Test".into(),
|
||||
cookie_secure: false,
|
||||
search: Some(search),
|
||||
default_language: "sv".into(),
|
||||
default_timezone: "Europe/Stockholm".into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user