Skip to main content

raps_da/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2#![allow(clippy::uninlined_format_args)]
3// Copyright 2024-2025 Dmytro Yemelianov
4
5//! Design Automation API module
6//!
7//! Handles automation of CAD processing with engines like AutoCAD, Revit, Inventor, 3ds Max.
8
9// API response structs may contain fields we don't use - this is expected for external API contracts
10#![allow(dead_code)]
11
12mod activities;
13mod appbundles;
14mod engines;
15pub mod types;
16mod workitems;
17
18pub use types::*;
19
20use raps_kernel::auth::AuthClient;
21use raps_kernel::config::Config;
22use raps_kernel::http::HttpClientConfig;
23
24/// Design Automation API client
25#[derive(Clone)]
26pub struct DesignAutomationClient {
27    pub(crate) config: Config,
28    pub(crate) auth: AuthClient,
29    pub(crate) http_client: reqwest::Client,
30}
31
32impl DesignAutomationClient {
33    /// Create a new Design Automation client
34    pub fn new(config: Config, auth: AuthClient) -> Self {
35        Self::new_with_http_config(config, auth, HttpClientConfig::default())
36    }
37
38    /// Create a new Design Automation client with custom HTTP config
39    pub fn new_with_http_config(
40        config: Config,
41        auth: AuthClient,
42        http_config: HttpClientConfig,
43    ) -> Self {
44        // Create HTTP client with configured timeouts
45        let http_client = http_config
46            .create_client()
47            .unwrap_or_else(|_| reqwest::Client::new()); // Fallback to default if config fails
48
49        Self {
50            config,
51            auth,
52            http_client,
53        }
54    }
55}
56
57/// Integration tests using raps-mock
58#[cfg(test)]
59mod integration_tests {
60    use super::*;
61    use raps_kernel::auth::AuthClient;
62    use raps_kernel::config::Config;
63
64    fn create_mock_da_client(mock_url: &str) -> DesignAutomationClient {
65        let config = Config {
66            client_id: "test-client-id".to_string(),
67            client_secret: "test-client-secret".to_string(),
68            base_url: mock_url.to_string(),
69            callback_url: "http://localhost:8080/callback".to_string(),
70            da_nickname: Some("test-nickname".to_string()),
71            http_config: HttpClientConfig::default(),
72        };
73        let auth = AuthClient::new(config.clone());
74        DesignAutomationClient::new(config, auth)
75    }
76
77    #[tokio::test]
78    async fn test_client_creation() {
79        let server = raps_mock::TestServer::start_default().await.unwrap();
80        let client = create_mock_da_client(&server.url);
81        assert!(client.auth.config().base_url.starts_with("http://"));
82    }
83
84    #[tokio::test]
85    async fn test_list_workitems() {
86        let server = raps_mock::TestServer::start_default().await.unwrap();
87        let client = create_mock_da_client(&server.url);
88        let result = client.list_workitems().await;
89        let _ = result;
90    }
91}