use std::time::Duration;
use dotenv::dotenv;
use super::*;
#[tokio::test]
async fn test_get_bot() {
dotenv().ok();
let api_key = std::env::var("SARUFI_API_KEY").expect("API_KEY env required to run test");
let api = Sarufi::new(api_key).unwrap();
let bot = api.get_bot(1205).await.unwrap();
println!("Name: {:?}", bot.name);
println!("ID: {:?}", bot.id);
println!("Description: {:?}", bot.description);
println!("Industry: {:?}", bot.industry);
}
#[tokio::test]
async fn test_get_all_bot() {
dotenv().ok();
let api_key = std::env::var("SARUFI_API_KEY").expect("API_KEY env required to run test");
let api = Sarufi::new(api_key).unwrap();
let bots = api.get_all_bots().await.unwrap();
println!("Result: {:?}", bots.len());
}
#[tokio::test]
async fn test_create_bot() -> Result<(), ApiError> {
dotenv().ok();
let api_key = std::env::var("SARUFI_API_KEY").expect("API_KEY env required to run test");
let api = Sarufi::new(api_key).unwrap();
let name = "My Rusty Chatbot";
let description = Some("A rusty chatbot created using Sarufi API");
let industry = Some("Technology");
let flow: Option<HashMap<String, Value>> = None;
let intents: Option<HashMap<String, Vec<String>>> = None;
let webhook_url = Some("https://example.com/webhook");
let webhook_trigger_intents: Option<Vec<String>> = None;
let visible_on_community = Some(true);
let bot = api.create_bot(
name,
description,
industry,
flow,
intents,
webhook_url,
webhook_trigger_intents,
visible_on_community,
).await?;
println!("Result: {:?}", bot);
println!("ID: {:?}", bot.id);
assert_eq!(bot.name, name);
assert_eq!(bot.description, description.unwrap());
assert_eq!(bot.industry, industry.unwrap());
Ok(())
}
#[tokio::test]
async fn test_update_bot() {
dotenv().ok();
let api_key = std::env::var("SARUFI_API_KEY").expect("API_KEY env required to run test");
let api = Sarufi::new(api_key).unwrap();
let id = 1112;
let prev_bot = api.get_bot(id).await.unwrap();
let name = "My Other Rusty Chatbot";
let description = Some("A rusty chatbot created using Sarufi API");
let industry = Some("Technology");
let flow: Option<HashMap<String, Value>> = None;
let intents: Option<HashMap<String, Vec<String>>> = None;
let webhook_url = Some("https://example.com/webhook");
let webhook_trigger_intents: Option<Vec<String>> = None;
let visible_on_community = Some(true);
let bot = api.update_bot(
id,
name,
description,
industry,
flow,
intents,
webhook_url,
webhook_trigger_intents,
visible_on_community,
).await.unwrap();
println!("Result: {:?}", bot.id);
assert_eq!(bot.name, name);
assert_eq!(bot.description, description.unwrap());
assert_eq!(bot.industry, industry.unwrap());
}
#[tokio::test]
async fn test_fetch () {
dotenv().ok();
let api_key = std::env::var("SARUFI_API_KEY").expect("API_KEY env required to run test");
let api = Sarufi::new(api_key).unwrap();
let bot_id = 1145; let chat_id = "123456789";
let message = "Hello";
let message_type = "text";
let channel = "other";
let response = api._fetch_response(bot_id, chat_id, message, message_type, channel).await.unwrap();
println!("Result: {:?}", response);
}
#[tokio::test]
async fn test_chat () {
dotenv().ok();
let api_key = std::env::var("SARUFI_API_KEY").expect("API_KEY env required to run test");
let api = Sarufi::new(api_key).unwrap();
let bot_id = 1145; let response = api.chat(bot_id).await.unwrap();
println!("Result: {:?}", response.as_str());
}