aboutsummaryrefslogtreecommitdiffstats
path: root/crates/configuration/src/server/http_svc/routes/routing/post_routing.rs
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2025-08-21 17:59:13 +0200
committerGitHub <noreply@github.com>2025-08-21 17:59:13 +0200
commit06421ed5455285eb5d5eb90ea689fa73ad0f3010 (patch)
treee7a56bb6ae95d9f6f84664c94fc2efb3758f6539 /crates/configuration/src/server/http_svc/routes/routing/post_routing.rs
parent441196248603a7c1aed66e4c0a4342aeb06dca8f (diff)
downloadwarden-06421ed5455285eb5d5eb90ea689fa73ad0f3010.tar.bz2
warden-06421ed5455285eb5d5eb90ea689fa73ad0f3010.zip
tests: cov (#13)
Diffstat (limited to 'crates/configuration/src/server/http_svc/routes/routing/post_routing.rs')
-rw-r--r--crates/configuration/src/server/http_svc/routes/routing/post_routing.rs99
1 files changed, 99 insertions, 0 deletions
diff --git a/crates/configuration/src/server/http_svc/routes/routing/post_routing.rs b/crates/configuration/src/server/http_svc/routes/routing/post_routing.rs
index 3578b65..ce9ba37 100644
--- a/crates/configuration/src/server/http_svc/routes/routing/post_routing.rs
+++ b/crates/configuration/src/server/http_svc/routes/routing/post_routing.rs
@@ -37,3 +37,102 @@ pub async fn post_routing(
Ok((axum::http::StatusCode::CREATED, axum::Json(response)))
}
+
+#[cfg(test)]
+mod tests {
+ use axum::{
+ body::Body,
+ http::{Request, StatusCode},
+ };
+ use sqlx::PgPool;
+ use tower::ServiceExt;
+ use warden_stack::cache::RedisManager;
+
+ use crate::{
+ server::http_svc::{build_router, routes::test_config},
+ state::{AppState, Services},
+ };
+
+ #[sqlx::test]
+ async fn create_routing(pool: PgPool) {
+ let config = test_config();
+
+ let cache = RedisManager::new(&config.cache).await.unwrap();
+ let client = async_nats::connect(&config.nats.hosts[0]).await.unwrap();
+ let jetstream = async_nats::jetstream::new(client);
+
+ let state = AppState::create(
+ Services {
+ postgres: pool,
+ cache,
+ jetstream,
+ },
+ &test_config(),
+ )
+ .await
+ .unwrap();
+ let app = build_router(state);
+
+ let routing = serde_json::json!({
+ "active": true,
+ "name": "Public Network Map",
+ "version": "1.0.0",
+ "messages": [
+ {
+ "id": "004",
+ "version": "1.0.0",
+ "tx_tp": "pacs.002.001.12",
+ "typologies": [
+ {
+ "id": "999",
+ "version": "1.0.0",
+ "rules": [
+ {
+ "id": "901",
+ "version": "1.0.0"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ });
+
+ let body = serde_json::to_vec(&routing).unwrap();
+
+ let response = app
+ .clone()
+ .oneshot(
+ Request::builder()
+ .method("POST")
+ .header("Content-Type", "application/json")
+ .uri("/api/v0/routing")
+ .body(Body::from(body))
+ .unwrap(),
+ )
+ .await
+ .unwrap();
+
+ assert_eq!(response.status(), StatusCode::CREATED);
+
+ // should have an active one
+ let response = app
+ .clone()
+ .oneshot(
+ Request::builder()
+ .method("GET")
+ .header("Content-Type", "application/json")
+ .uri("/api/v0/routing")
+ .body(Body::empty())
+ .unwrap(),
+ )
+ .await
+ .unwrap();
+
+ assert_eq!(response.status(), StatusCode::OK);
+
+ // let bytes = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
+ // let routing_info: RoutingConfiguration = serde_json::from_slice(&bytes).unwrap();
+ //
+ }
+}