Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | /** |
| 2 | * Search API integration tests. |
| 3 | * |
| 4 | * Validates that the search endpoint returns relevant results for key terms. |
| 5 | */ |
| 6 | import { describe, test, expect } from "bun:test"; |
| 7 | import { fetchPage } from "./helpers"; |
| 8 | |
| 9 | describe("Search API", () => { |
| 10 | test("server-renders unified knowledge results", async () => { |
| 11 | const res = await fetchPage("/kb/search?q=authentication"); |
| 12 | expect(res.status).toBe(200); |
| 13 | |
| 14 | const html = (await res.text()).replaceAll("<!-- -->", ""); |
| 15 | expect(html).toContain("Results for “authentication”"); |
| 16 | expect(html).toContain("<ol"); |
| 17 | expect(html).toMatch(/(?:Documentation|Support|Toolkit|API Reference)/); |
| 18 | expect(html).not.toContain("Loading search results"); |
| 19 | }); |
| 20 | |
| 21 | test("returns results for 'authentication'", async () => { |
| 22 | const res = await fetchPage("/api/search?query=authentication"); |
| 23 | expect(res.status).toBe(200); |
| 24 | |
| 25 | const data = await res.json(); |
| 26 | expect(Array.isArray(data)).toBe(true); |
| 27 | expect(data.length).toBeGreaterThan(0); |
| 28 | |
| 29 | // At least one result should have a URL and title |
| 30 | const first = data[0]; |
| 31 | expect(first).toHaveProperty("url"); |
| 32 | expect(first).toHaveProperty("content"); |
| 33 | }); |
| 34 | |
| 35 | test("returns results for 'quickstart'", async () => { |
| 36 | const res = await fetchPage("/api/search?query=quickstart"); |
| 37 | expect(res.status).toBe(200); |
| 38 | |
| 39 | const data = await res.json(); |
| 40 | expect(data.length).toBeGreaterThan(0); |
| 41 | }); |
| 42 | |
| 43 | test("returns results for 'tools'", async () => { |
| 44 | const res = await fetchPage("/api/search?query=tools"); |
| 45 | expect(res.status).toBe(200); |
| 46 | |
| 47 | const data = await res.json(); |
| 48 | expect(data.length).toBeGreaterThan(0); |
| 49 | }); |
| 50 | |
| 51 | test("returns empty array for nonsense query", async () => { |
| 52 | const res = await fetchPage("/api/search?query=xyzzy123nonexistent"); |
| 53 | expect(res.status).toBe(200); |
| 54 | |
| 55 | const data = await res.json(); |
| 56 | expect(Array.isArray(data)).toBe(true); |
| 57 | // Should return no results (or very few) for gibberish |
| 58 | expect(data.length).toBeLessThan(3); |
| 59 | }); |
| 60 | |
| 61 | test("returns 400 or empty for missing query", async () => { |
| 62 | const res = await fetchPage("/api/search"); |
| 63 | // Fumadocs returns 400 for missing query param |
| 64 | expect([200, 400]).toContain(res.status); |
| 65 | }); |
| 66 | }); |