2024-12-22 20:56:52 -03:00
|
|
|
pub mod router;
|
|
|
|
|
|
|
|
pub use router::{create_router, ApiState};
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
use gb_messaging::MessageProcessor;
|
|
|
|
use axum::Router;
|
|
|
|
use tower::ServiceExt;
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_api_integration() {
|
|
|
|
// Initialize message processor
|
2024-12-25 16:25:09 -03:00
|
|
|
let processor = MessageProcessor::new();
|
2024-12-22 20:56:52 -03:00
|
|
|
|
|
|
|
// Create router
|
|
|
|
let app: Router = create_router(processor);
|
|
|
|
|
|
|
|
// Test health endpoint
|
|
|
|
let response = app
|
|
|
|
.clone()
|
|
|
|
.oneshot(
|
|
|
|
axum::http::Request::builder()
|
|
|
|
.uri("/health")
|
|
|
|
.body(axum::body::Body::empty())
|
|
|
|
.unwrap(),
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_eq!(response.status(), axum::http::StatusCode::OK);
|
|
|
|
|
|
|
|
// Test message sending
|
|
|
|
let message = gb_core::models::Message {
|
|
|
|
id: Uuid::new_v4(),
|
|
|
|
customer_id: Uuid::new_v4(),
|
|
|
|
instance_id: Uuid::new_v4(),
|
|
|
|
conversation_id: Uuid::new_v4(),
|
|
|
|
sender_id: Uuid::new_v4(),
|
|
|
|
kind: "test".to_string(),
|
|
|
|
content: "integration test".to_string(),
|
|
|
|
metadata: serde_json::Value::Object(serde_json::Map::new()),
|
|
|
|
created_at: chrono::Utc::now(),
|
|
|
|
shard_key: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
let response = app
|
|
|
|
.oneshot(
|
|
|
|
axum::http::Request::builder()
|
|
|
|
.method("POST")
|
|
|
|
.uri("/messages")
|
|
|
|
.header("content-type", "application/json")
|
|
|
|
.body(axum::body::Body::from(
|
|
|
|
serde_json::to_string(&message).unwrap()
|
|
|
|
))
|
|
|
|
.unwrap(),
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_eq!(response.status(), axum::http::StatusCode::OK);
|
|
|
|
}
|
|
|
|
}
|