diff --git a/apps/js-sdk/firecrawl/src/__tests__/v1/e2e_withAuth/index.test.ts b/apps/js-sdk/firecrawl/src/__tests__/v1/e2e_withAuth/index.test.ts index e5c04209..2e601dc4 100644 --- a/apps/js-sdk/firecrawl/src/__tests__/v1/e2e_withAuth/index.test.ts +++ b/apps/js-sdk/firecrawl/src/__tests__/v1/e2e_withAuth/index.test.ts @@ -381,8 +381,45 @@ describe('FirecrawlApp E2E Tests', () => { expect(filteredLinks?.length).toBeGreaterThan(0); }, 30000); // 30 seconds timeout - test('should throw NotImplementedError for search on v1', async () => { + + + test('should search with string query', async () => { const app = new FirecrawlApp({ apiUrl: API_URL, apiKey: TEST_API_KEY }); - await expect(app.search("test query")).rejects.toThrow("Search is not supported in v1"); + const response = await app.search("firecrawl"); + expect(response.success).toBe(true); + console.log(response.data); + expect(response.data?.length).toBeGreaterThan(0); + expect(response.data?.[0]?.markdown).toBeDefined(); + expect(response.data?.[0]?.metadata).toBeDefined(); + expect(response.data?.[0]?.metadata?.title).toBeDefined(); + expect(response.data?.[0]?.metadata?.description).toBeDefined(); + }); + + test('should search with params object', async () => { + const app = new FirecrawlApp({ apiUrl: API_URL, apiKey: TEST_API_KEY }); + const response = await app.search("firecrawl", { + limit: 3, + lang: 'en', + country: 'us', + scrapeOptions: { + formats: ['markdown', 'html', 'links'], + onlyMainContent: true + } + }); + expect(response.success).toBe(true); + expect(response.data.length).toBeLessThanOrEqual(3); + for (const doc of response.data) { + expect(doc.markdown).toBeDefined(); + expect(doc.html).toBeDefined(); + expect(doc.links).toBeDefined(); + expect(doc.metadata).toBeDefined(); + expect(doc.metadata?.title).toBeDefined(); + expect(doc.metadata?.description).toBeDefined(); + } + }); + + test('should handle invalid API key for search', async () => { + const app = new FirecrawlApp({ apiUrl: API_URL, apiKey: "invalid_api_key" }); + await expect(app.search("test query")).rejects.toThrow("Request failed with status code 404"); }); }); diff --git a/apps/python-sdk/firecrawl/__tests__/v1/e2e_withAuth/test.py b/apps/python-sdk/firecrawl/__tests__/v1/e2e_withAuth/test.py index d25d43f3..eacec8da 100644 --- a/apps/python-sdk/firecrawl/__tests__/v1/e2e_withAuth/test.py +++ b/apps/python-sdk/firecrawl/__tests__/v1/e2e_withAuth/test.py @@ -371,4 +371,70 @@ def test_search_e2e(): # assert isinstance(llm_extraction['supports_sso'], bool) # assert isinstance(llm_extraction['is_open_source'], bool) +def test_search_with_string_query(): + app = FirecrawlApp(api_url=API_URL, api_key=TEST_API_KEY) + response = app.search("firecrawl") + assert response["success"] is True + assert len(response["data"]) > 0 + assert response["data"][0]["markdown"] is not None + assert response["data"][0]["metadata"] is not None + assert response["data"][0]["metadata"]["title"] is not None + assert response["data"][0]["metadata"]["description"] is not None + +def test_search_with_params_dict(): + app = FirecrawlApp(api_url=API_URL, api_key=TEST_API_KEY) + response = app.search("firecrawl", { + "limit": 3, + "lang": "en", + "country": "us", + "scrapeOptions": { + "formats": ["markdown", "html", "links"], + "onlyMainContent": True + } + }) + assert response["success"] is True + assert len(response["data"]) <= 3 + for doc in response["data"]: + assert doc["markdown"] is not None + assert doc["html"] is not None + assert doc["links"] is not None + assert doc["metadata"] is not None + assert doc["metadata"]["title"] is not None + assert doc["metadata"]["description"] is not None + +def test_search_with_params_object(): + app = FirecrawlApp(api_url=API_URL, api_key=TEST_API_KEY) + params = SearchParams( + query="firecrawl", + limit=3, + lang="en", + country="us", + scrapeOptions={ + "formats": ["markdown", "html", "links"], + "onlyMainContent": True + } + ) + response = app.search(params.query, params) + assert response["success"] is True + assert len(response["data"]) <= 3 + for doc in response["data"]: + assert doc["markdown"] is not None + assert doc["html"] is not None + assert doc["links"] is not None + assert doc["metadata"] is not None + assert doc["metadata"]["title"] is not None + assert doc["metadata"]["description"] is not None + +def test_search_invalid_api_key(): + app = FirecrawlApp(api_url=API_URL, api_key="invalid_api_key") + with pytest.raises(Exception) as e: + app.search("test query") + assert "404" in str(e.value) + +def test_search_with_invalid_params(): + app = FirecrawlApp(api_url=API_URL, api_key=TEST_API_KEY) + with pytest.raises(Exception) as e: + app.search("test query", {"invalid_param": "value"}) + assert "ValidationError" in str(e.value) +