use assert_matches::assert_matches; use dotenv::dotenv; use firecrawl_rs::FirecrawlApp; use serde_json::json; use std::env; use std::time::Duration; use tokio::time::sleep; #[tokio::test] async fn test_no_api_key() { dotenv().ok(); let api_url = env::var("API_URL").expect("API_URL environment variable is not set"); assert_matches!(FirecrawlApp::new(None, Some(api_url)), Err(e) if e.to_string() == "API key not provided"); } #[tokio::test] async fn test_blocklisted_url() { dotenv().ok(); let api_url = env::var("API_URL").unwrap(); let api_key = env::var("TEST_API_KEY").unwrap(); let app = FirecrawlApp::new(Some(api_key), Some(api_url)).unwrap(); let blocklisted_url = "https://facebook.com/fake-test"; let result = app.scrape_url(blocklisted_url, None).await; assert_matches!( result, Err(e) if e.to_string().contains("Firecrawl currently does not support social media scraping due to policy restrictions") ); } #[tokio::test] async fn test_successful_response_with_valid_preview_token() { dotenv().ok(); let api_url = env::var("API_URL").unwrap(); let app = FirecrawlApp::new( Some("this_is_just_a_preview_token".to_string()), Some(api_url), ) .unwrap(); let result = app .scrape_url("https://roastmywebsite.ai", None) .await .unwrap(); assert!(result.as_object().unwrap().contains_key("content")); assert!(result["content"].as_str().unwrap().contains("_Roast_")); } #[tokio::test] async fn test_scrape_url_e2e() { dotenv().ok(); let api_url = env::var("API_URL").unwrap(); let api_key = env::var("TEST_API_KEY").unwrap(); let app = FirecrawlApp::new(Some(api_key), Some(api_url)).unwrap(); let result = app .scrape_url("https://roastmywebsite.ai", None) .await .unwrap(); assert!(result.as_object().unwrap().contains_key("content")); assert!(result.as_object().unwrap().contains_key("markdown")); assert!(result.as_object().unwrap().contains_key("metadata")); assert!(!result.as_object().unwrap().contains_key("html")); assert!(result["content"].as_str().unwrap().contains("_Roast_")); } #[tokio::test] async fn test_successful_response_with_valid_api_key_and_include_html() { dotenv().ok(); let api_url = env::var("API_URL").unwrap(); let api_key = env::var("TEST_API_KEY").unwrap(); let app = FirecrawlApp::new(Some(api_key), Some(api_url)).unwrap(); let params = json!({ "pageOptions": { "includeHtml": true } }); let result = app .scrape_url("https://roastmywebsite.ai", Some(params)) .await .unwrap(); assert!(result.as_object().unwrap().contains_key("content")); assert!(result.as_object().unwrap().contains_key("markdown")); assert!(result.as_object().unwrap().contains_key("html")); assert!(result.as_object().unwrap().contains_key("metadata")); assert!(result["content"].as_str().unwrap().contains("_Roast_")); assert!(result["markdown"].as_str().unwrap().contains("_Roast_")); assert!(result["html"].as_str().unwrap().contains("