use crate::integration::framework::ApiTest;
use serde_json::{json, Value};
use uuid::Uuid;
use super::crud_test_base::{CrudTestConfig, GenericCrudTest, TestDataGenerator};
use crate::integration::helpers::CommonUtils;
pub struct IntegrationEventTestData;
impl TestDataGenerator for IntegrationEventTestData {
fn generate_create_payload(&self, _utils: &CommonUtils) -> Value {
json!({
"id": Uuid::new_v4().to_string(),
"connector_id": Uuid::new_v4().to_string(),
"event_type": format!("Test {}", Uuid::new_v4().to_string().split('-').next().unwrap()),
"external_id": format!("Test {}", Uuid::new_v4().to_string().split('-').next().unwrap()),
"business_key": format!("Test {}", Uuid::new_v4().to_string().split('-').next().unwrap()),
"status": "received",
"payload": format!("Test {}", Uuid::new_v4().to_string().split('-').next().unwrap()),
"mapped_ref_type": null,
"mapped_ref_id": null,
"error_detail": null,
"metadata": json!({}),
})
}
fn generate_update_payload(&self, id: &str, _utils: &CommonUtils) -> Value {
json!({
"id": id,
"connector_id": Uuid::new_v4().to_string(),
"event_type": format!("Test {}", Uuid::new_v4().to_string().split('-').next().unwrap()),
"external_id": format!("Test {}", Uuid::new_v4().to_string().split('-').next().unwrap()),
"business_key": format!("Test {}", Uuid::new_v4().to_string().split('-').next().unwrap()),
"status": "received",
"payload": format!("Test {}", Uuid::new_v4().to_string().split('-').next().unwrap()),
"mapped_ref_type": null,
"mapped_ref_id": null,
"error_detail": null,
"metadata": json!({}),
})
}
fn generate_invalid_payload(&self) -> Value {
json!({
})
}
async fn seed_dependencies(&self, api: &ApiTest) -> Vec<(String, String)> {
let mut deps: Vec<(String, String)> = Vec::new();
if let Some(id) = super::crud_test_base::create_and_get_id(api, "/api/v1/integration_connectors", &super::integration_connector_api_test::IntegrationConnectorTestData).await {
deps.push(("connector_id".to_string(), id));
}
deps
}
}
pub struct IntegrationEventApiTest {
inner: GenericCrudTest<IntegrationEventTestData>,
}
impl IntegrationEventApiTest {
pub fn new() -> Self {
let mut config = CrudTestConfig::new("/api/v1/integration_events", "IntegrationEvent");
config.supports_soft_delete = true;
Self {
inner: GenericCrudTest::new(config, IntegrationEventTestData),
}
}
pub async fn run_all(&mut self) -> Vec<crate::integration::framework::TestResult> {
self.inner.run_all().await
}
}
impl Default for IntegrationEventApiTest {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_integration_event_crud() {
let mut test = IntegrationEventApiTest::new();
let results = test.run_all().await;
for result in &results {
println!("{:?}", result);
}
let failed: Vec<_> = results.iter().filter(|r| !r.success).collect();
assert!(failed.is_empty(), "Some tests failed: {:?}", failed);
}
}