Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
added unit tests
rafaelmmillereab30c474b19
diff --git a/apps/api/src/scraper/scrapeURL/transformers/llmExtract.test.ts b/apps/api/src/scraper/scrapeURL/transformers/llmExtract.test.tsnew file mode 100644index 000000000..f23f506f0--- /dev/null+++ b/apps/api/src/scraper/scrapeURL/transformers/llmExtract.test.ts@@ -0,0 +1,33 @@+import { removeDefaultProperty } from "./llmExtract";++describe("removeDefaultProperty", () => {+ it("should remove the default property from a simple object", () => {+ const input = { default: "test", test: "test" };+ const expectedOutput = { test: "test" };+ expect(removeDefaultProperty(input)).toEqual(expectedOutput);+ });++ it("should remove the default property from a nested object", () => {+ const input = { default: "test", nested: { default: "nestedTest", test: "nestedTest" } };+ const expectedOutput = { nested: { test: "nestedTest" } };+ expect(removeDefaultProperty(input)).toEqual(expectedOutput);+ });++ it("should remove the default property from an array of objects", () => {+ const input = { array: [{ default: "test1", test: "test1" }, { default: "test2", test: "test2" }] };+ const expectedOutput = { array: [{ test: "test1" }, { test: "test2" }] };+ expect(removeDefaultProperty(input)).toEqual(expectedOutput);+ });++ it("should handle objects without a default property", () => {+ const input = { test: "test" };+ const expectedOutput = { test: "test" };+ expect(removeDefaultProperty(input)).toEqual(expectedOutput);+ });++ it("should handle null and non-object inputs", () => {+ expect(removeDefaultProperty(null)).toBeNull();+ expect(removeDefaultProperty("string")).toBe("string");+ expect(removeDefaultProperty(123)).toBe(123);+ });+});\ No newline at end of filediff --git a/apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts b/apps/api/src/scraper/scrapeURL/transformers/llmExtract.tsindex 71a464060..c35e20c13 100644--- a/apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts+++ b/apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts@@ -199,7 +199,7 @@ export async function performLLMExtract(meta: Meta, document: Document): Promisereturn document;}-function removeDefaultProperty(schema: any): any {+export function removeDefaultProperty(schema: any): any {if (typeof schema !== 'object' || schema === null) return schema;const { default: _, ...rest } = schema;