aboutsummaryrefslogtreecommitdiffstats
path: root/crates/configuration/src/server/http_svc/routes/rule/create.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/configuration/src/server/http_svc/routes/rule/create.rs')
-rw-r--r--crates/configuration/src/server/http_svc/routes/rule/create.rs90
1 files changed, 90 insertions, 0 deletions
diff --git a/crates/configuration/src/server/http_svc/routes/rule/create.rs b/crates/configuration/src/server/http_svc/routes/rule/create.rs
index 809c00b..f7aba5b 100644
--- a/crates/configuration/src/server/http_svc/routes/rule/create.rs
+++ b/crates/configuration/src/server/http_svc/routes/rule/create.rs
@@ -36,3 +36,93 @@ pub async fn create_rule(
.into_inner();
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 post_rule(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 rule = serde_json::json!({
+ "id": "901",
+ "version": "1.0.0",
+ "description": "Number of outgoing transactions - debtor",
+ "configuration": {
+ "parameters": {
+ "max_query_range": 86400000
+ },
+ "exit_conditions": [
+ {
+ "sub_rule_ref": ".x00",
+ "reason": "Incoming transaction is unsuccessful"
+ }
+ ],
+ "bands": [
+ {
+ "sub_rule_ref": ".01",
+ "upper_limit": 2,
+ "reason": "The debtor has performed one transaction to date"
+ },
+ {
+ "sub_rule_ref": ".02",
+ "lower_limit": 2,
+ "upper_limit": 3,
+ "reason": "The debtor has performed two transactions to date"
+ },
+ {
+ "sub_rule_ref": ".03",
+ "lower_limit": 3,
+ "reason": "The debtor has performed three or more transactions to date"
+ }
+ ]
+ }
+ });
+
+ let body = serde_json::to_vec(&rule).unwrap();
+
+ let response = app
+ .clone()
+ .oneshot(
+ Request::builder()
+ .method("POST")
+ .header("Content-Type", "application/json")
+ .uri("/api/v0/rule")
+ .body(Body::from(body))
+ .unwrap(),
+ )
+ .await
+ .unwrap();
+
+ assert_eq!(response.status(), StatusCode::CREATED);
+ }
+}