backbone-catalog 0.9.0

Canonical product/service identity: Item, Item Group, UOM (Indonesia-first)
Documentation
//! Attribute API Integration Tests
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! Tests the Attribute CRUD API endpoints.

use serde_json::{json, Value};
use uuid::Uuid;

use super::crud_test_base::{CrudTestConfig, GenericCrudTest, TestDataGenerator};
use crate::integration::helpers::CommonUtils;

// ============================================================================
// ATTRIBUTE TEST DATA GENERATOR
// ============================================================================

/// Test data generator for Attribute
pub struct AttributeTestData;

impl TestDataGenerator for AttributeTestData {
    fn generate_create_payload(&self, _utils: &CommonUtils) -> Value {
        json!({
            "id": Uuid::new_v4().to_string(),
            "code": format!("TEST_{}", Uuid::new_v4().to_string().split('-').next().unwrap()),
            "name": format!("Test {}", Uuid::new_v4().to_string().split('-').next().unwrap()),
            "attribute_type": "color",
            "status": "active",
            "metadata": json!({}),
        })
    }

    fn generate_update_payload(&self, id: &str, _utils: &CommonUtils) -> Value {
        json!({
            "id": id,
            "code": format!("TEST_{}", Uuid::new_v4().to_string().split('-').next().unwrap()),
            "name": format!("Test {}", Uuid::new_v4().to_string().split('-').next().unwrap()),
            "attribute_type": "color",
            "status": "active",
            "metadata": json!({}),
        })
    }

    fn generate_invalid_payload(&self) -> Value {
        json!({
            // Missing required fields
        })
    }
}

// ============================================================================
// ATTRIBUTE API TEST
// ============================================================================

/// Attribute API test suite
pub struct AttributeApiTest {
    inner: GenericCrudTest<AttributeTestData>,
}

impl AttributeApiTest {
    pub fn new() -> Self {
        let mut config = CrudTestConfig::new("/api/v1/attributes", "Attribute");
        config.supports_soft_delete = true;
        Self {
            inner: GenericCrudTest::new(config, AttributeTestData),
        }
    }

    pub async fn run_all(&mut self) -> Vec<crate::integration::framework::TestResult> {
        self.inner.run_all().await
    }
}

impl Default for AttributeApiTest {
    fn default() -> Self {
        Self::new()
    }
}

// ============================================================================
// TESTS
// ============================================================================

#[cfg(test)]
mod tests {
    use super::*;

    #[tokio::test]
    async fn test_attribute_crud() {
        let mut test = AttributeApiTest::new();
        let results = test.run_all().await;

        for result in &results {
            println!("{:?}", result);
        }

        // Check all tests passed
        let failed: Vec<_> = results.iter().filter(|r| !r.success).collect();
        assert!(failed.is_empty(), "Some tests failed: {:?}", failed);
    }
}

// ============================================================================
// CUSTOM TESTS
// ============================================================================

// Add Attribute specific tests here