Skip to content

Commit

Permalink
Revert "fix(v1/types): fix extract -> json rename (FIR-1072) (#1195)"
Browse files Browse the repository at this point in the history
This reverts commit 586a10f.
  • Loading branch information
nickscamara committed Feb 18, 2025
1 parent 586a10f commit e28a444
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 212 deletions.
92 changes: 0 additions & 92 deletions apps/api/src/__tests__/snips/batch-scrape.test.ts

This file was deleted.

74 changes: 20 additions & 54 deletions apps/api/src/__tests__/snips/scrape.test.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
import request from "supertest";
import { configDotenv } from "dotenv";
import { Document, ScrapeRequestInput } from "../../controllers/v1/types";
import { ScrapeRequestInput } from "../../controllers/v1/types";

configDotenv();
const TEST_URL = "http://127.0.0.1:3002";

async function scrapeRaw(body: ScrapeRequestInput) {
async function scrape(body: ScrapeRequestInput) {
return await request(TEST_URL)
.post("/v1/scrape")
.set("Authorization", `Bearer ${process.env.TEST_API_KEY}`)
.set("Content-Type", "application/json")
.send(body);
}

function expectScrapeToSucceed(response: Awaited<ReturnType<typeof scrapeRaw>>) {
function expectScrapeToSucceed(response: Awaited<ReturnType<typeof scrape>>) {
expect(response.statusCode).toBe(200);
expect(response.body.success).toBe(true);
expect(typeof response.body.data).toBe("object");
}

async function scrape(body: ScrapeRequestInput): Promise<Document> {
const raw = await scrapeRaw(body);
expectScrapeToSucceed(raw);
return raw.body.data;
}

describe("Scrape tests", () => {
it("mocking works properly", async () => {
// depends on falsified mock mocking-works-properly
Expand All @@ -36,7 +30,8 @@ describe("Scrape tests", () => {
useMock: "mocking-works-properly",
});

expect(response.markdown).toBe(
expectScrapeToSucceed(response);
expect(response.body.data.markdown).toBe(
"this is fake data coming from the mocking system!",
);
}, 10000);
Expand All @@ -47,7 +42,8 @@ describe("Scrape tests", () => {
url: "https://canyoublockit.com/testing/",
});

expect(response.markdown).not.toContain(".g.doubleclick.net/");
expectScrapeToSucceed(response);
expect(response.body.data.markdown).not.toContain(".g.doubleclick.net/");
}, 10000);

it.concurrent("doesn't block ads if explicitly disabled", async () => {
Expand All @@ -56,7 +52,8 @@ describe("Scrape tests", () => {
blockAds: false,
});

expect(response.markdown).toContain(".g.doubleclick.net/");
expectScrapeToSucceed(response);
expect(response.body.data.markdown).toContain(".g.doubleclick.net/");
}, 10000);
});

Expand All @@ -65,6 +62,8 @@ describe("Scrape tests", () => {
const response = await scrape({
url: "https://iplocation.com",
});

expectScrapeToSucceed(response);
}, 10000);

it.concurrent("works with country US", async () => {
Expand All @@ -73,7 +72,8 @@ describe("Scrape tests", () => {
location: { country: "US" },
});

expect(response.markdown).toContain("| Country | United States |");
expectScrapeToSucceed(response);
expect(response.body.data.markdown).toContain("| Country | United States |");
}, 10000);
});

Expand All @@ -84,7 +84,8 @@ describe("Scrape tests", () => {
formats: ["rawHtml"],
});

const obj = JSON.parse(response.rawHtml!);
expectScrapeToSucceed(response);
const obj = JSON.parse(response.body.data.rawHtml);
expect(obj.id).toBe(1);
}, 25000); // TODO: mock and shorten
});
Expand All @@ -96,7 +97,8 @@ describe("Scrape tests", () => {
formats: ["screenshot"]
});

expect(typeof response.screenshot).toBe("string");
expectScrapeToSucceed(response);
expect(typeof response.body.data.screenshot).toBe("string");
}, 15000);

it.concurrent("screenshot@fullPage format works", async () => {
Expand All @@ -105,44 +107,8 @@ describe("Scrape tests", () => {
formats: ["screenshot@fullPage"]
});

expect(typeof response.screenshot).toBe("string");
expectScrapeToSucceed(response);
expect(typeof response.body.data.screenshot).toBe("string");
}, 15000);
});

describe("JSON format", () => {
it.concurrent("works", async () => {
const response = await scrape({
url: "http://firecrawl.dev",
formats: ["json"],
jsonOptions: {
prompt: "Based on the information on the page, find what the company's mission is and whether it supports SSO, and whether it is open source.",
schema: {
type: "object",
properties: {
company_mission: {
type: "string",
},
supports_sso: {
type: "boolean",
},
is_open_source: {
type: "boolean",
},
},
required: ["company_mission", "supports_sso", "is_open_source"],
},
},
});

expect(response).toHaveProperty("json");
expect(response.json).toHaveProperty("company_mission");
expect(typeof response.json.company_mission).toBe("string");
expect(response.json).toHaveProperty("supports_sso");
expect(response.json.supports_sso).toBe(false);
expect(typeof response.json.supports_sso).toBe("boolean");
expect(response.json).toHaveProperty("is_open_source");
expect(response.json.is_open_source).toBe(true);
expect(typeof response.json.is_open_source).toBe("boolean");
}, 30000);
});
})
});
Loading

0 comments on commit e28a444

Please sign in to comment.