use assert_matches::assert_matches; use dotenvy::dotenv; use firecrawl::scrape::{ExtractOptions, ScrapeFormats, ScrapeOptions}; use firecrawl::FirecrawlApp; use serde_json::json; use std::env; #[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").ok(); let app = FirecrawlApp::new_selfhosted(api_url, api_key).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_selfhosted( api_url, Some("this_is_just_a_preview_token"), ) .unwrap(); let result = app .scrape_url("https://roastmywebsite.ai", None) .await .unwrap(); assert!(result.markdown.is_some()); assert!(result.markdown.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").ok(); let app = FirecrawlApp::new_selfhosted(api_url, api_key).unwrap(); let result = app .scrape_url("https://roastmywebsite.ai", None) .await .unwrap(); assert!(result.markdown.is_some()); assert!(result.markdown.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").ok(); let app = FirecrawlApp::new_selfhosted(api_url, api_key).unwrap(); let params = ScrapeOptions { formats: vec! [ ScrapeFormats::Markdown, ScrapeFormats::HTML ].into(), ..Default::default() }; let result = app .scrape_url("https://roastmywebsite.ai", params) .await .unwrap(); assert!(result.markdown.is_some()); assert!(result.html.is_some()); assert!(result.markdown.unwrap().contains("_Roast_")); assert!(result.html.unwrap().contains("