Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

test: merge request shape cases and cover the gov category

PhantomInTheWire7ab8ef305e87
diff --git a/apps/js-sdk/firecrawl/src/__tests__/unit/v2/legal-regulatory.test.ts b/apps/js-sdk/firecrawl/src/__tests__/unit/v2/legal-regulatory.test.ts
index f3412b49f..4ea77d18a 100644
--- a/apps/js-sdk/firecrawl/src/__tests__/unit/v2/legal-regulatory.test.ts
+++ b/apps/js-sdk/firecrawl/src/__tests__/unit/v2/legal-regulatory.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, jest, test } from "@jest/globals";
import { FirecrawlClient } from "../../../v2/client";
+import { search } from "../../../v2/methods/search";
import { SdkError } from "../../../v2/types";
const response = {
@@ -26,35 +27,23 @@ function clientWith(http: any) {
}
describe("legalRegulatorySearch", () => {
- test("posts query and k and returns web results", async () => {
+ test.each([
+ [{ k: 5 }, { query: "food labeling requirements", k: 5 }],
+ [undefined, { query: "food labeling requirements" }],
+ ])("posts %p and returns web results", async (options, body) => {
const http = {
post: jest.fn(async () => ({ status: 200, data: response })),
} as any;
const result = await clientWith(http).legalRegulatorySearch(
"food labeling requirements",
- { k: 5 },
+ options,
);
- expect(http.post).toHaveBeenCalledWith("/v2/search/gov", {
- query: "food labeling requirements",
- k: 5,
- });
+ expect(http.post).toHaveBeenCalledWith("/v2/search/gov", body);
expect(result).toEqual(response);
});
- test("omits k when not provided", async () => {
- const http = {
- post: jest.fn(async () => ({ status: 200, data: response })),
- } as any;
-
- await clientWith(http).legalRegulatorySearch("zoning variance");
-
- expect(http.post).toHaveBeenCalledWith("/v2/search/gov", {
- query: "zoning variance",
- });
- });
-
test("rejects an empty query", async () => {
const http = { post: jest.fn() } as any;
@@ -93,3 +82,27 @@ describe("legalRegulatorySearch", () => {
).rejects.toBeInstanceOf(SdkError);
});
});
+
+describe("search gov category", () => {
+ test("forwards the gov category and returns results inside web", async () => {
+ const web = [{ ...response.data.web[0], category: "gov" }];
+ const http = {
+ post: jest.fn(async () => ({
+ status: 200,
+ data: { success: true, data: { web } },
+ })),
+ } as any;
+
+ const result = await search(http, {
+ query: "zoning variance",
+ categories: [{ type: "gov" }],
+ });
+
+ expect(http.post).toHaveBeenCalledWith(
+ "/v2/search",
+ { query: "zoning variance", categories: [{ type: "gov" }] },
+ {},
+ );
+ expect(result.web).toEqual(web);
+ });
+});
diff --git a/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_legal_regulatory_search.py b/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_legal_regulatory_search.py
index 8e1a12f71..507f0f6f8 100644
--- a/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_legal_regulatory_search.py
+++ b/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_legal_regulatory_search.py
@@ -4,6 +4,8 @@ import pytest
from firecrawl.v2.client import FirecrawlClient
from firecrawl.v2.client_async import AsyncFirecrawlClient
+from firecrawl.v2.methods.search import search
+from firecrawl.v2.types import SearchRequest
from firecrawl.v2.utils.error_handler import FirecrawlError
@@ -32,34 +34,26 @@ def _response(body=RESPONSE):
return response
-def test_legal_regulatory_search_posts_query_and_k_and_parses_web_results():
+ "kwargs, body",
+ [
+ ({"k": 5}, {"query": "food labeling requirements", "k": 5}),
+ ({}, {"query": "food labeling requirements"}),
+ ],
+)
+def test_legal_regulatory_search_posts_body_and_parses_web_results(kwargs, body):
transport = Mock()
transport.post.return_value = _response()
client = FirecrawlClient.__new__(FirecrawlClient)
client.http_client = transport
- result = client.legal_regulatory_search("food labeling requirements", k=5)
+ result = client.legal_regulatory_search("food labeling requirements", **kwargs)
- transport.post.assert_called_once_with(
- "/v2/search/gov", {"query": "food labeling requirements", "k": 5}
- )
+ transport.post.assert_called_once_with("/v2/search/gov", body)
assert result.data.web[0].title == "21 CFR Part 101 -- Food Labeling"
assert result.data.web[0].position == 1
-def test_legal_regulatory_search_omits_k_when_not_provided():
- transport = Mock()
- transport.post.return_value = _response()
- client = FirecrawlClient.__new__(FirecrawlClient)
- client.http_client = transport
-
- client.legal_regulatory_search("zoning variance")
-
- transport.post.assert_called_once_with(
- "/v2/search/gov", {"query": "zoning variance"}
- )
-
-
def test_legal_regulatory_search_rejects_empty_query():
transport = Mock()
client = FirecrawlClient.__new__(FirecrawlClient)
@@ -104,3 +98,15 @@ async def test_async_legal_regulatory_search_raises_on_unsuccessful_body():
with pytest.raises(FirecrawlError, match="Search failed"):
await client.legal_regulatory_search("zoning variance")
+
+
+def test_search_gov_category_is_forwarded_and_parsed_inside_web():
+ web = [{**RESPONSE["data"]["web"][0], "category": "gov"}]
+ client = Mock()
+ client.post.return_value = _response({"success": True, "data": {"web": web}})
+
+ result = search(client, SearchRequest(query="zoning variance", categories=["gov"]))
+
+ assert client.post.call_args.args[1]["categories"] == [{"type": "gov"}]
+ assert result.web[0].category == "gov"
+ assert not hasattr(result, "gov")