diff --git a/jsr.json b/jsr.json index 6caae09..6830c57 100644 --- a/jsr.json +++ b/jsr.json @@ -1,5 +1,5 @@ { "name": "@jigsawstack/jigsawstack", - "version": "0.4.2", + "version": "0.4.3", "exports": "./index.ts" } diff --git a/package.json b/package.json index 5164046..7cb0825 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "keywords": ["framework", "ai", "nextjs", "react"], "type": "module", "license": "MIT", - "version": "0.4.2", + "version": "0.4.3", "homepage": "https://jigsawstack.com", "repository": { "type": "git", diff --git a/src/web/interfaces/search.ts b/src/web/interfaces/search.ts index 8d77c4d..5d39442 100644 --- a/src/web/interfaces/search.ts +++ b/src/web/interfaces/search.ts @@ -5,7 +5,7 @@ export interface SearchParams { spell_check?: boolean; max_results?: number; safe_search?: "strict" | "moderate" | "off"; - ai_overview?: boolean; + ai_overview?: boolean; // defaults to false on api side byo_urls?: string[]; country_code?: CountryCode; auto_scrape?: boolean; diff --git a/tests/validate.test.ts b/tests/validate.test.ts index 276638b..35dcd83 100644 --- a/tests/validate.test.ts +++ b/tests/validate.test.ts @@ -104,54 +104,6 @@ describe("Profanity validation", () => { } }); - test("should handle text with special characters", async () => { - const result = await client.validate.profanity({ - text: "Special chars: !@#$%^&*()_+-=[]{}|;':\",./<>?", - censor_replacement: "***", - }); - - expectSuccess(result); - expectProperty(result, "clean_text"); - expectProperty(result, "profanities"); - expectProperty(result, "profanities_found"); - - expectType(result.clean_text, "string"); - expectArray(result.profanities); - expectType(result.profanities_found, "boolean"); // Corrected: should be boolean - }); - - test("should handle unicode characters", async () => { - const result = await client.validate.profanity({ - text: "Unicode: 你好 🌟 émojis 🚀 ñoño", - censor_replacement: "🌟", - }); - - expectSuccess(result); - expectProperty(result, "clean_text"); - expectProperty(result, "profanities"); - expectProperty(result, "profanities_found"); - - expectType(result.clean_text, "string"); - expectArray(result.profanities); - expectType(result.profanities_found, "boolean"); // Corrected: should be boolean - }); - - test("should handle very long text", async () => { - const longText = "This is a very long text. ".repeat(100); - const result = await client.validate.profanity({ - text: longText, - }); - - expectSuccess(result); - expectProperty(result, "clean_text"); - expectProperty(result, "profanities"); - expectProperty(result, "profanities_found"); - - expectType(result.clean_text, "string"); - expectArray(result.profanities); - expectType(result.profanities_found, "boolean"); // Corrected: should be boolean - }); - test("should validate profanities array structure when profanities are found", async () => { const result = await client.validate.profanity({ text: "This damn shit is fucking terrible.", @@ -222,58 +174,6 @@ describe("Profanity validation", () => { } }); }); - - test("profanity check with clean text", async () => { - const result = await client.validate.profanity({ - text: "This is a nice and clean sentence.", - censor_replacement: "*", - }); - - expectSuccess(result); - expectProperty(result, "clean_text"); - expectProperty(result, "profanities"); - expectProperty(result, "profanities_found"); - - expectType(result.clean_text, "string"); - expectArray(result.profanities); - expectType(result.profanities_found, "boolean"); - - if (result.profanities_found !== false) { - throw new Error("Expected clean text to have no profanities"); - } - }); - - test("profanity check with profane text", async () => { - const result = await client.validate.profanity({ - text: "This damn text contains actual profanity.", - censor_replacement: "*", - }); - - expectSuccess(result); - expectProperty(result, "clean_text"); - expectProperty(result, "profanities"); - expectProperty(result, "profanities_found"); - - expectType(result.clean_text, "string"); - expectArray(result.profanities); - expectType(result.profanities_found, "boolean"); - - // For profane text, we expect profanities to be found - if (result.profanities_found !== true) { - console.log("Note: No profanity detected in text with mild profanity"); - } - }); - - test("profanity check with custom replacement", async () => { - const result = await client.validate.profanity({ - text: "This is a profane sentence.", - censor_replacement: "[CENSORED]", - }); - - expectSuccess(result); - expectProperty(result, "clean_text"); - expectType(result.clean_text, "string"); - }); }); // Comprehensive NSFW API Tests @@ -402,81 +302,6 @@ describe("NSFW validation", () => { } }); - test("should handle non-image URL gracefully", async () => { - try { - await client.validate.nsfw({ - url: "https://www.google.com", - }); - throw new Error("Expected API call to fail with non-image URL"); - } catch (error) { - expectType(error, "object"); - } - }); - - test("should handle unreachable URL gracefully", async () => { - try { - await client.validate.nsfw({ - url: "https://example.com/non-existent-image.jpg", - }); - throw new Error("Expected API call to fail with unreachable URL"); - } catch (error) { - expectType(error, "object"); - } - }); - - test("should work with different image formats", async () => { - const imageUrls = [ - imageUrl, // jpg - ]; - - // Run all API calls in parallel - const results = await Promise.allSettled( - imageUrls.map(async (url) => { - try { - const result = await client.validate.nsfw({ url }); - - expectSuccess(result); - expectProperty(result, "success"); - expectProperty(result, "nsfw"); - expectProperty(result, "nudity"); - expectProperty(result, "gore"); - expectProperty(result, "nsfw_score"); - expectProperty(result, "nudity_score"); - expectProperty(result, "gore_score"); - - expectType(result.success, "boolean"); - expectType(result.nsfw, "boolean"); - expectType(result.nudity, "boolean"); - expectType(result.gore, "boolean"); - expectType(result.nsfw_score, "number"); - expectType(result.nudity_score, "number"); - expectType(result.gore_score, "number"); - - return { success: true, url }; - } catch (error) { - expectType(error, "object"); - return { success: false, url, error }; - } - }) - ); - - // Process results and log outcomes - results.forEach((result, index) => { - const url = imageUrls[index]; - const format = url.split(".").pop()?.toUpperCase(); - - if (result.status === "fulfilled") { - if (result.value.success) { - console.log(`✓ ${format} format works`); - } else { - console.log(`Note: ${url} failed - may not be accessible or supported format`); - } - } else { - console.log(`Note: ${url} failed - may not be accessible or supported format`); - } - }); - }); - test("should handle empty string URL", async () => { try { await client.validate.nsfw({ @@ -498,520 +323,4 @@ describe("NSFW validation", () => { expectType(error, "object"); } }); - - test("should prioritize url when both parameters are provided", async () => { - const result = await client.validate.nsfw({ - url: "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Logo_of_Twitter.svg/512px-Logo_of_Twitter.svg.png", - file_store_key: "test_key", // This should be ignored in favor of URL - }); - - expectSuccess(result); - expectProperty(result, "success"); - expectProperty(result, "nsfw"); - expectProperty(result, "nudity"); - expectProperty(result, "gore"); - expectProperty(result, "nsfw_score"); - expectProperty(result, "nudity_score"); - expectProperty(result, "gore_score"); - - expectType(result.success, "boolean"); - expectType(result.nsfw, "boolean"); - expectType(result.nudity, "boolean"); - expectType(result.gore, "boolean"); - expectType(result.nsfw_score, "number"); - expectType(result.nudity_score, "number"); - expectType(result.gore_score, "number"); - }); - - test("should validate response structure completely", async () => { - const result = await client.validate.nsfw({ - url: "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Logo_of_Twitter.svg/512px-Logo_of_Twitter.svg.png", - }); - - // Verify the complete response structure - expectSuccess(result); - expectType(result, "object"); - - // Check if response has expected properties - const expectedProperties = ["success", "nsfw", "nudity", "gore", "nsfw_score", "nudity_score", "gore_score"]; - const resultKeys = Object.keys(result); - - // Ensure all expected properties exist - for (const expectedProp of expectedProperties) { - expectProperty(result, expectedProp); - } - - // Log any additional properties (like _usage) - for (const key of resultKeys) { - if (!expectedProperties.includes(key)) { - console.log(`Note: Additional property '${key}' found in NSFW response`); - } - } - - // Validate all property types - expectProperty(result, "success"); - expectProperty(result, "nsfw"); - expectProperty(result, "nudity"); - expectProperty(result, "gore"); - expectProperty(result, "nsfw_score"); - expectProperty(result, "nudity_score"); - expectProperty(result, "gore_score"); - - expectType(result.success, "boolean"); - expectType(result.nsfw, "boolean"); - expectType(result.nudity, "boolean"); - expectType(result.gore, "boolean"); - expectType(result.nsfw_score, "number"); - expectType(result.nudity_score, "number"); - expectType(result.gore_score, "number"); - }); - - test("should handle very long URL", async () => { - const longUrl = - "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Logo_of_Twitter.svg/512px-Logo_of_Twitter.svg.png" + "?param=" + "a".repeat(1000); - - try { - const result = await client.validate.nsfw({ url: longUrl }); - - expectSuccess(result); - expectProperty(result, "success"); - expectProperty(result, "nsfw"); - expectProperty(result, "nudity"); - expectProperty(result, "gore"); - expectProperty(result, "nsfw_score"); - expectProperty(result, "nudity_score"); - expectProperty(result, "gore_score"); - - expectType(result.success, "boolean"); - expectType(result.nsfw, "boolean"); - expectType(result.nudity, "boolean"); - expectType(result.gore, "boolean"); - expectType(result.nsfw_score, "number"); - expectType(result.nudity_score, "number"); - expectType(result.gore_score, "number"); - } catch (error) { - console.log("Note: Very long URL failed (may be expected)"); - expectType(error, "object"); - } - }); - - test("NSFW detection with URL", async () => { - const result = await client.validate.nsfw({ - url: "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Logo_of_Twitter.svg/512px-Logo_of_Twitter.svg.png", - }); - - expectSuccess(result); - expectType(result, "object"); - expectProperty(result, "success"); - expectProperty(result, "nsfw"); - expectProperty(result, "nudity"); - expectProperty(result, "gore"); - expectProperty(result, "nsfw_score"); - expectProperty(result, "nudity_score"); - expectProperty(result, "gore_score"); - - expectType(result.success, "boolean"); - expectType(result.nsfw, "boolean"); - expectType(result.nudity, "boolean"); - expectType(result.gore, "boolean"); - expectType(result.nsfw_score, "number"); - expectType(result.nudity_score, "number"); - expectType(result.gore_score, "number"); - }); - - test("NSFW detection with safe image URL", async () => { - const result = await client.validate.nsfw({ - url: "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Logo_of_Twitter.svg/512px-Logo_of_Twitter.svg.png", - }); - - expectSuccess(result); - expectType(result, "object"); - expectProperty(result, "success"); - expectProperty(result, "nsfw"); - expectProperty(result, "nudity"); - expectProperty(result, "gore"); - expectProperty(result, "nsfw_score"); - expectProperty(result, "nudity_score"); - expectProperty(result, "gore_score"); - - expectType(result.success, "boolean"); - expectType(result.nsfw, "boolean"); - expectType(result.nudity, "boolean"); - expectType(result.gore, "boolean"); - expectType(result.nsfw_score, "number"); - expectType(result.nudity_score, "number"); - expectType(result.gore_score, "number"); - - // Safe image should return success: true (assuming this means the API processed successfully) - if (result.success !== true) { - console.log("Note: NSFW API returned success: false for safe image"); - } - - // For a safe image, we expect NSFW flags to be false - if (result.nsfw === true) { - console.log("Note: Safe image was flagged as NSFW"); - } - if (result.nudity === true) { - console.log("Note: Safe image was flagged as nudity"); - } - if (result.gore === true) { - console.log("Note: Safe image was flagged as gore"); - } - }); }); - -// Comprehensive SpellCheck API Tests -// describe("SpellCheck validation", () => { -// let client: ReturnType; - -// beforeEach(() => { -// client = createJigsawStackClient(); -// }); - -// test("should fail when text parameter is missing", async () => { -// try { -// // @ts-expect-error Testing missing required parameter -// await client.validate.spellcheck({}); -// throw new Error("Expected API call to fail with missing text parameter"); -// } catch (error) { -// // Should throw an error for missing required parameter -// expectType(error, "object"); -// } -// }); - -// test("should fail when text parameter is undefined", async () => { -// try { -// // @ts-expect-error Testing undefined required parameter -// await client.validate.spellcheck({ text: undefined }); -// throw new Error("Expected API call to fail with undefined text parameter"); -// } catch (error) { -// expectType(error, "object"); -// } -// }); - -// test("should fail when text parameter is null", async () => { -// try { -// // @ts-expect-error Testing null required parameter -// await client.validate.spellcheck({ text: null }); -// throw new Error("Expected API call to fail with null text parameter"); -// } catch (error) { -// expectType(error, "object"); -// } -// }); - -// test("should work with only required text parameter", async () => { -// const result = await client.validate.spellcheck({ -// text: "This is a correctly spelled sentence.", -// }); - -// // Verify success -// expectSuccess(result); - -// // Verify all required response properties exist -// expectProperty(result, "success"); -// expectProperty(result, "misspellings_found"); -// expectProperty(result, "misspellings"); -// expectProperty(result, "auto_correct_text"); - -// // Verify correct types -// expectType(result.success, "boolean"); -// expectType(result.misspellings_found, "boolean"); -// expectArray(result.misspellings); -// expectType(result.auto_correct_text, "string"); -// }); - -// test("should work with custom language_code parameter", async () => { -// const result = await client.validate.spellcheck({ -// text: "Hola mundo como estas", -// language_code: "es", -// }); - -// expectSuccess(result); -// expectProperty(result, "success"); -// expectProperty(result, "misspellings_found"); -// expectProperty(result, "misspellings"); -// expectProperty(result, "auto_correct_text"); - -// expectType(result.success, "boolean"); -// expectType(result.misspellings_found, "boolean"); -// expectArray(result.misspellings); -// expectType(result.auto_correct_text, "string"); -// }); - -// test("should handle empty text", async () => { -// const result = await client.validate.spellcheck({ -// text: "", -// }); - -// expectSuccess(result); -// expectProperty(result, "success"); -// expectProperty(result, "misspellings_found"); -// expectProperty(result, "misspellings"); -// expectProperty(result, "auto_correct_text"); - -// expectType(result.success, "boolean"); -// expectType(result.misspellings_found, "boolean"); -// expectArray(result.misspellings); -// expectType(result.auto_correct_text, "string"); - -// // Empty text should have no misspellings -// if (result.misspellings_found !== false) { -// console.log("Note: Misspellings found in empty text"); -// } -// }); - -// test("should handle text with intentional misspellings", async () => { -// const result = await client.validate.spellcheck({ -// text: "Ths is a mispelled sentance with erors.", -// language_code: "en", -// }); - -// expectSuccess(result); -// expectProperty(result, "success"); -// expectProperty(result, "misspellings_found"); -// expectProperty(result, "misspellings"); -// expectProperty(result, "auto_correct_text"); - -// expectType(result.success, "boolean"); -// expectType(result.misspellings_found, "boolean"); -// expectArray(result.misspellings); -// expectType(result.auto_correct_text, "string"); - -// // Should find misspellings in our intentionally misspelled text -// if (result.misspellings_found === false) { -// console.log("Note: No misspellings found in intentionally misspelled text"); -// } - -// // Validate misspellings array structure when misspellings are found -// if (result.misspellings_found === true) { -// result.misspellings.forEach((misspelling) => { -// expectType(misspelling, "object"); -// expectProperty(misspelling, "word"); -// expectProperty(misspelling, "startIndex"); -// expectProperty(misspelling, "endIndex"); -// expectProperty(misspelling, "expected"); -// expectProperty(misspelling, "auto_corrected"); -// expectType(misspelling.word, "string"); -// expectType(misspelling.startIndex, "number"); -// expectType(misspelling.endIndex, "number"); -// expectArray(misspelling.expected); -// expectType(misspelling.auto_corrected, "boolean"); -// }); -// } - -// // Auto-corrected text should be different from original -// if (result.auto_correct_text === "Ths is a mispelled sentance with erors.") { -// console.log("Note: Auto-corrected text is identical to original misspelled text"); -// } -// }); - -// test("should handle text with special characters", async () => { -// const result = await client.validate.spellcheck({ -// text: "Special chars: !@#$%^&*()_+-=[]{}|;':\",./<>?", -// language_code: "en", -// }); - -// expectSuccess(result); -// expectProperty(result, "success"); -// expectProperty(result, "misspellings_found"); -// expectProperty(result, "misspellings"); -// expectProperty(result, "auto_correct_text"); - -// expectType(result.success, "boolean"); -// expectType(result.misspellings_found, "boolean"); -// expectArray(result.misspellings); -// expectType(result.auto_correct_text, "string"); -// }); - -// test("should handle text with numbers", async () => { -// const result = await client.validate.spellcheck({ -// text: "The year 2024 has 365 days and 12 months.", -// language_code: "en", -// }); - -// expectSuccess(result); -// expectProperty(result, "success"); -// expectProperty(result, "misspellings_found"); -// expectProperty(result, "misspellings"); -// expectProperty(result, "auto_correct_text"); - -// expectType(result.success, "boolean"); -// expectType(result.misspellings_found, "boolean"); -// expectArray(result.misspellings); -// expectType(result.auto_correct_text, "string"); -// }); - -// test("should handle unicode characters", async () => { -// const result = await client.validate.spellcheck({ -// text: "Unicode: 你好 🌟 émojis 🚀 ñoño café résumé", -// language_code: "en", -// }); - -// expectSuccess(result); -// expectProperty(result, "success"); -// expectProperty(result, "misspellings_found"); -// expectProperty(result, "misspellings"); -// expectProperty(result, "auto_correct_text"); - -// expectType(result.success, "boolean"); -// expectType(result.misspellings_found, "boolean"); -// expectArray(result.misspellings); -// expectType(result.auto_correct_text, "string"); -// }); - -// test("should handle very long text", async () => { -// const longText = "This is a very long text that contains many words. ".repeat(50); -// const result = await client.validate.spellcheck({ -// text: longText, -// language_code: "en", -// }); - -// expectSuccess(result); -// expectProperty(result, "success"); -// expectProperty(result, "misspellings_found"); -// expectProperty(result, "misspellings"); -// expectProperty(result, "auto_correct_text"); - -// expectType(result.success, "boolean"); -// expectType(result.misspellings_found, "boolean"); -// expectArray(result.misspellings); -// expectType(result.auto_correct_text, "string"); -// }); - -// test("should handle different supported language codes", async () => { -// const testCases = [ -// { text: "Hello world", language_code: "en", name: "English" }, -// { text: "Hola mundo", language_code: "es", name: "Spanish" }, -// { text: "Bonjour monde", language_code: "fr", name: "French" }, -// { text: "Hallo Welt", language_code: "de", name: "German" }, -// { text: "Ciao mondo", language_code: "it", name: "Italian" }, -// ]; - -// // Run all API calls in parallel -// const results = await Promise.allSettled( -// testCases.map(async (testCase) => { -// try { -// const result = await client.validate.spellcheck({ -// text: testCase.text, -// language_code: testCase.language_code, -// }); - -// expectSuccess(result); -// expectProperty(result, "success"); -// expectProperty(result, "misspellings_found"); -// expectProperty(result, "misspellings"); -// expectProperty(result, "auto_correct_text"); - -// expectType(result.success, "boolean"); -// expectType(result.misspellings_found, "boolean"); -// expectArray(result.misspellings); -// expectType(result.auto_correct_text, "string"); - -// return { success: true, testCase }; -// } catch (error) { -// expectType(error, "object"); -// return { success: false, testCase, error }; -// } -// }) -// ); - -// // Process results and log outcomes -// results.forEach((result, index) => { -// const testCase = testCases[index]; -// if (result.status === "fulfilled") { -// if (result.value.success) { -// console.log(`✓ ${testCase.name} (${testCase.language_code}) works`); -// } else { -// console.log(`Note: ${testCase.name} (${testCase.language_code}) failed - may not be supported`); -// } -// } else { -// console.log(`Note: ${testCase.name} (${testCase.language_code}) failed - may not be supported`); -// } -// }); -// }); - -// test("should handle invalid language code", async () => { -// try { -// const result = await client.validate.spellcheck({ -// text: "This is a test sentence.", -// language_code: "invalid_code", -// }); - -// // If it doesn't throw an error, validate the response -// expectSuccess(result); -// expectProperty(result, "success"); -// expectProperty(result, "misspellings_found"); -// expectProperty(result, "auto_correct_text"); - -// console.log("Note: Invalid language code was accepted"); -// } catch (error) { -// console.log("Note: Invalid language code was rejected (expected)"); -// expectType(error, "object"); -// } -// }); - -// test("should handle empty language code", async () => { -// try { -// const result = await client.validate.spellcheck({ -// text: "This is a test sentence.", -// language_code: "", -// }); - -// expectSuccess(result); -// expectProperty(result, "success"); -// expectProperty(result, "misspellings_found"); -// expectProperty(result, "auto_correct_text"); -// } catch (error) { -// console.log("Note: Empty language code was rejected"); -// expectType(error, "object"); -// } -// }); - -// test("should validate response structure completely", async () => { -// const result = await client.validate.spellcheck({ -// text: "This is a test sentence with some mispellings.", -// language_code: "en", -// }); - -// // Verify the complete response structure -// expectSuccess(result); -// expectType(result, "object"); - -// // Check if response has expected properties -// const expectedProperties = ["success", "misspellings_found", "misspellings", "auto_correct_text"]; -// const resultKeys = Object.keys(result); - -// // Ensure all expected properties exist -// for (const expectedProp of expectedProperties) { -// expectProperty(result, expectedProp); -// } - -// // Log any unexpected properties (might be from documentation but not in interface) -// for (const key of resultKeys) { -// if (!expectedProperties.includes(key)) { -// console.log(`Note: Additional property '${key}' found in SpellCheck response`); -// } -// } - -// // Validate types -// expectType(result.success, "boolean"); -// expectType(result.misspellings_found, "boolean"); -// expectArray(result.misspellings); -// expectType(result.auto_correct_text, "string"); - -// // Validate misspellings array structure -// result.misspellings.forEach((misspelling) => { -// expectType(misspelling, "object"); -// expectProperty(misspelling, "word"); -// expectProperty(misspelling, "startIndex"); -// expectProperty(misspelling, "endIndex"); -// expectProperty(misspelling, "expected"); -// expectProperty(misspelling, "auto_corrected"); -// expectType(misspelling.word, "string"); -// expectType(misspelling.startIndex, "number"); -// expectType(misspelling.endIndex, "number"); -// expectArray(misspelling.expected); -// expectType(misspelling.auto_corrected, "boolean"); -// }); -// }); -// }); diff --git a/tests/vision.test.ts b/tests/vision.test.ts index 940f442..4ae8de7 100644 --- a/tests/vision.test.ts +++ b/tests/vision.test.ts @@ -162,19 +162,6 @@ describe("VOCR (Visual OCR) API", () => { } }); - test("should work with array of prompts and URL", async () => { - const result = await client.vision.vocr({ - prompt: ["Extract all text", "Identify key information", "Find phone numbers"], - url: TEST_URLS.textImage, - }); - - expectSuccess(result); - expectProperty(result, "success"); - expectProperty(result, "context"); - expectProperty(result, "sections"); - expectArray(result.sections); - }); - test("should work with file_store_key parameter", async () => { try { const result = await client.vision.vocr({ @@ -258,28 +245,6 @@ describe("VOCR (Visual OCR) API", () => { } }); - // Test different prompt types - test("should work with complex single prompt", async () => { - const result = await client.vision.vocr({ - prompt: "Extract all visible text including headers, body text, captions, and any metadata. Also identify the main topics discussed.", - url: TEST_URLS.textImage, - }); - - expectSuccess(result); - expectProperty(result, "context"); - expectType(result.context, "string"); - }); - - test("should work with multiple specific prompts", async () => { - const result = await client.vision.vocr({ - prompt: ["Find all email addresses", "Extract phone numbers", "Identify dates", "Get website URLs", "Extract names and titles"], - url: TEST_URLS.textImage, - }); - - expectSuccess(result); - expectArray(result.sections); - }); - // Edge cases and error handling test("should handle invalid URL gracefully", async () => { try { @@ -293,18 +258,6 @@ describe("VOCR (Visual OCR) API", () => { } }); - test("should handle unreachable URL gracefully", async () => { - try { - await client.vision.vocr({ - prompt: "Extract text", - url: "https://example.com/non-existent-image.jpg", - }); - throw new Error("Expected API call to fail with unreachable URL"); - } catch (error) { - expectType(error, "object"); - } - }); - test("should handle empty file_store_key gracefully", async () => { try { await client.vision.vocr({ @@ -546,16 +499,6 @@ describe("Object Detection API", () => { expectType(result, "object"); }); - test("should work with multiple prompts", async () => { - const result = await client.vision.object_detection({ - url: TEST_URLS.image, - prompts: ["find people", "detect vehicles", "identify buildings"], - }); - - expectSuccess(result); - expectType(result, "object"); - }); - test("should work with empty prompts array", async () => { const result = await client.vision.object_detection({ url: TEST_URLS.image, @@ -660,17 +603,6 @@ describe("Object Detection API", () => { } }); - test("should handle unreachable URL gracefully", async () => { - try { - await client.vision.object_detection({ - url: "https://example.com/non-existent-image.jpg", - }); - throw new Error("Expected API call to fail with unreachable URL"); - } catch (error) { - expectType(error, "object"); - } - }); - test("should handle empty file_store_key gracefully", async () => { try { await client.vision.object_detection({ @@ -682,48 +614,6 @@ describe("Object Detection API", () => { } }); - test("should work with different image formats", async () => { - const imageUrls = [ - "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png", // PNG - "https://upload.wikimedia.org/wikipedia/commons/a/a7/React-icon.svg", // SVG - ]; - - // Run all API calls in parallel - const results = await Promise.allSettled( - imageUrls.map(async (url) => { - try { - const result = await client.vision.object_detection({ - url: url, - }); - - expectSuccess(result); - expectType(result, "object"); - - return { success: true, url }; - } catch (error) { - expectType(error, "object"); - return { success: false, url, error }; - } - }) - ); - - // Process results and log outcomes - results.forEach((result, index) => { - const url = imageUrls[index]; - const format = url.split(".").pop()?.toUpperCase(); - - if (result.status === "fulfilled") { - if (result.value.success) { - console.log(`✓ ${format} format works`); - } else { - console.log(`Note: ${url} failed - may not be accessible or supported format`); - } - } else { - console.log(`Note: ${url} failed - may not be accessible or supported format`); - } - }); - }); - // Complex scenario tests test("should work with comprehensive configuration", async () => { const result = await client.vision.object_detection({ diff --git a/tests/web-scraper.test.ts b/tests/web-scraper.test.ts index ab58596..dd75c21 100644 --- a/tests/web-scraper.test.ts +++ b/tests/web-scraper.test.ts @@ -2,14 +2,10 @@ import { beforeEach, describe, test } from "node:test"; import { createJigsawStackClient, expectArray, expectProperty, expectSuccess, expectType } from "./test-helpers.js"; const TEST_URLS = { - image: "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png", - pdf: "https://www.w3.org/WAI/WCAG21/working-examples/pdf-table/table.pdf", - audio: "https://jigsawstack.com/preview/stt-example.wav", - webpage: "https://www.wikipedia.org", + webpage: "https://news.ycombinator.com/show", newsWebpage: "https://news.ycombinator.com", }; -// Comprehensive AI Scrape API Tests describe("AI Scrape API", () => { let client: ReturnType; @@ -171,17 +167,6 @@ describe("AI Scrape API", () => { expectArray(result.data); }); - test("should work with custom root_element_selector", async () => { - const result = await client.web.ai_scrape({ - url: TEST_URLS.webpage, - element_prompts: ["Find content"], - root_element_selector: "main", - }); - - expectSuccess(result); - expectArray(result.data); - }); - // Test page_position parameter test("should work with page_position parameter", async () => { const result = await client.web.ai_scrape({ @@ -238,47 +223,6 @@ describe("AI Scrape API", () => { expectArray(result.data); }); - test("should work with different wait_until options", async () => { - const waitOptions = ["load", "domcontentloaded", "networkidle0", "networkidle2"] as const; - - // Run all API calls in parallel - const results = await Promise.allSettled( - waitOptions.map(async (waitOption) => { - try { - const result = await client.web.ai_scrape({ - url: TEST_URLS.webpage, - element_prompts: ["test"], - goto_options: { - timeout: 30000, - wait_until: waitOption, - }, - }); - - expectSuccess(result); - return { success: true, waitOption }; - } catch (error) { - expectType(error, "object"); - return { success: false, waitOption, error }; - } - }) - ); - - // Process results and log outcomes - results.forEach((result, index) => { - const waitOption = waitOptions[index]; - - if (result.status === "fulfilled") { - if (result.value.success) { - console.log(`✓ wait_until: ${waitOption} works`); - } else { - console.log(`Note: wait_until: ${waitOption} failed - may not be supported`); - } - } else { - console.log(`Note: wait_until: ${waitOption} failed - may not be supported`); - } - }); - }); - // Test wait_for parameter test("should work with wait_for timeout mode", async () => { const result = await client.web.ai_scrape({ @@ -294,34 +238,6 @@ describe("AI Scrape API", () => { expectArray(result.data); }); - test("should work with wait_for selector mode", async () => { - const result = await client.web.ai_scrape({ - url: TEST_URLS.webpage, - element_prompts: ["Get content"], - wait_for: { - mode: "selector", - value: "body", - }, - }); - - expectSuccess(result); - expectArray(result.data); - }); - - test("should work with wait_for function mode", async () => { - const result = await client.web.ai_scrape({ - url: TEST_URLS.webpage, - element_prompts: ["Get content"], - wait_for: { - mode: "function", - value: "() => document.querySelector('body')", - }, - }); - - expectSuccess(result); - expectArray(result.data); - }); - // Test viewport parameters test("should work with custom viewport dimensions", async () => { const result = await client.web.ai_scrape({ @@ -336,76 +252,6 @@ describe("AI Scrape API", () => { expectArray(result.data); }); - test("should work with mobile viewport", async () => { - const result = await client.web.ai_scrape({ - url: TEST_URLS.webpage, - element_prompts: ["Get main content"], - is_mobile: true, - width: 375, - height: 667, - scale: 2, - }); - - expectSuccess(result); - expectArray(result.data); - }); - - test("should work with size_preset", async () => { - const presets = ["HD", "FHD", "4K UHD"] as const; - - // Run all API calls in parallel - const results = await Promise.allSettled( - presets.map(async (preset) => { - try { - const result = await client.web.ai_scrape({ - url: TEST_URLS.webpage, - element_prompts: ["test"], - size_preset: preset, - }); - - expectSuccess(result); - return { success: true, preset }; - } catch (error) { - expectType(error, "object"); - return { success: false, preset, error }; - } - }) - ); - - // Process results and log outcomes - results.forEach((result, index) => { - const preset = presets[index]; - - if (result.status === "fulfilled") { - if (result.value.success) { - console.log(`✓ size_preset: ${preset} works`); - } else { - console.log(`Note: size_preset: ${preset} failed`); - } - } else { - console.log(`Note: size_preset: ${preset} failed`); - } - }); - }); - - // Test cookies parameter - // test("should work with cookies", async () => { - // const result = await client.web.ai_scrape({ - // url: TEST_URLS.webpage, - // element_prompts: ["Get content"], - // cookies: [ - // { - // name: "test_cookie", - // value: "test_value", - // domain: "example.com", - // }, - // ], - // }); - - // expectSuccess(result); - // expectArray(result.data); - // }); - // Test reject_request_pattern parameter test("should work with reject_request_pattern", async () => { const result = await client.web.ai_scrape({ @@ -437,42 +283,6 @@ describe("AI Scrape API", () => { } }); - test("should work with advance_config network tracking", async () => { - const result = await client.web.ai_scrape({ - url: TEST_URLS.webpage, - element_prompts: ["Get content"], - advance_config: { - network: true, - }, - }); - - expectSuccess(result); - expectArray(result.data); - - if (result.advance_config) { - expectProperty(result.advance_config, "network"); - expectArray(result.advance_config.network); - } - }); - - // test("should work with advance_config cookies tracking", async () => { - // const result = await client.web.ai_scrape({ - // url: TEST_URLS.webpage, - // element_prompts: ["Get content"], - // advance_config: { - // cookies: true, - // }, - // }); - - // expectSuccess(result); - // expectArray(result.data); - - // if (result.advance_config) { - // expectProperty(result.advance_config, "cookies"); - // expectArray(result.advance_config.cookies); - // } - // }); - test("should work with all advance_config options", async () => { const result = await client.web.ai_scrape({ url: TEST_URLS.webpage,