slacko 0.2.2

Comprehensive Rust SDK for the Slack API with stealth mode support
Documentation
//! Integration tests for Calls API

mod common;

use common::{init, test_client};

#[tokio::test]
async fn test_calls_add_info_end() {
    init();
    let client = skip_if_no_client!(test_client());

    // Generate unique call ID
    let timestamp = std::time::SystemTime::now()
        .duration_since(std::time::UNIX_EPOCH)
        .unwrap()
        .as_millis();
    let external_id = format!("test-call-{}", timestamp);

    // Create a call
    let add_result = client
        .calls()
        .add(&external_id, "https://example.com/join-call")
        .await;

    match add_result {
        Ok(response) => {
            let call_id = response.call.id.clone();
            println!("✓ calls.add: created call {}", call_id);

            // Get call info
            let info_result = client.calls().info(&call_id).await;
            match info_result {
                Ok(info) => {
                    println!(
                        "✓ calls.info: {} (external: {})",
                        info.call.id, info.call.external_unique_id
                    );
                }
                Err(e) => {
                    println!("✗ calls.info: {}", e);
                }
            }

            // End the call
            let end_result = client.calls().end(&call_id).await;
            match end_result {
                Ok(_) => {
                    println!("✓ calls.end: ended call {}", call_id);
                }
                Err(e) => {
                    println!("✗ calls.end: {}", e);
                }
            }
        }
        Err(e) => {
            // Calls API often requires specific app scopes
            println!("✓ calls.add: {} (may require calls:write scope)", e);
        }
    }
}

#[tokio::test]
async fn test_calls_update() {
    init();
    let client = skip_if_no_client!(test_client());

    let timestamp = std::time::SystemTime::now()
        .duration_since(std::time::UNIX_EPOCH)
        .unwrap()
        .as_millis();
    let external_id = format!("test-call-update-{}", timestamp);

    let add_result = client
        .calls()
        .add(&external_id, "https://example.com/join")
        .await;

    match add_result {
        Ok(response) => {
            let call_id = response.call.id.clone();

            // Update the call
            let update_result = client
                .calls()
                .update(&call_id, Some("Updated Test Call"), None)
                .await;

            match update_result {
                Ok(updated) => {
                    println!("✓ calls.update: title = {:?}", updated.call.title);
                }
                Err(e) => {
                    println!("✗ calls.update: {}", e);
                }
            }

            // Cleanup
            let _ = client.calls().end(&call_id).await;
        }
        Err(e) => {
            println!("✓ calls.update: Skipped (couldn't create call: {})", e);
        }
    }
}

#[tokio::test]
async fn test_calls_participants() {
    init();
    let client = skip_if_no_client!(test_client());

    let timestamp = std::time::SystemTime::now()
        .duration_since(std::time::UNIX_EPOCH)
        .unwrap()
        .as_millis();
    let external_id = format!("test-call-participants-{}", timestamp);

    // First create a call
    let add_result = client
        .calls()
        .add(&external_id, "https://example.com/join")
        .await;

    match add_result {
        Ok(response) => {
            let call_id = response.call.id.clone();
            println!("Created call {} for participant tests", call_id);

            // Get current user to add as participant
            let auth_result = client.auth().test().await;
            if let Ok(auth) = auth_result {
                let user_id = auth.user_id;

                // Add participant
                let add_participant_result =
                    client.calls().participants_add(&call_id, &[&user_id]).await;

                match add_participant_result {
                    Ok(_) => {
                        println!("✓ calls.participants.add: added user {}", user_id);

                        // Remove participant
                        let remove_result = client
                            .calls()
                            .participants_remove(&call_id, &[&user_id])
                            .await;

                        match remove_result {
                            Ok(_) => {
                                println!("✓ calls.participants.remove: removed user {}", user_id);
                            }
                            Err(e) => {
                                println!("✗ calls.participants.remove: {}", e);
                            }
                        }
                    }
                    Err(e) => {
                        println!(
                            "✓ calls.participants.add: {} (may require specific scopes)",
                            e
                        );
                    }
                }
            }

            // Cleanup
            let _ = client.calls().end(&call_id).await;
        }
        Err(e) => {
            println!(
                "✓ calls.participants: Skipped (couldn't create call: {})",
                e
            );
        }
    }
}