Skip to content

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

Nick: tests

Nicolase6779aff6824
diff --git a/apps/api/src/__tests__/e2e_noAuth/index.test.ts b/apps/api/src/__tests__/e2e_noAuth/index.test.ts
index e0aca36ff..dfe6aebac 100644
--- a/apps/api/src/__tests__/e2e_noAuth/index.test.ts
+++ b/apps/api/src/__tests__/e2e_noAuth/index.test.ts
@@ -102,6 +102,33 @@ describe("E2E Tests for API Routes with No Authentication", () => {
});
});
+ describe("POST /v0/search", () => {
+ it("should require not authorization", async () => {
+ const response = await request(TEST_URL).post("/v0/search");
+ expect(response.statusCode).not.toBe(401);
+ });
+
+ it("should return no error response with an invalid API key", async () => {
+ const response = await request(TEST_URL)
+ .post("/v0/search")
+ .set("Authorization", `Bearer invalid-api-key`)
+ .set("Content-Type", "application/json")
+ .send({ query: "test" });
+ expect(response.statusCode).not.toBe(401);
+ });
+
+ it("should return a successful response with a valid API key", async () => {
+ const response = await request(TEST_URL)
+ .post("/v0/search")
+ .set("Content-Type", "application/json")
+ .send({ query: "test" });
+ expect(response.statusCode).toBe(200);
+ expect(response.body).toHaveProperty("success");
+ expect(response.body.success).toBe(true);
+ expect(response.body).toHaveProperty("data");
+ });
+ });
+
describe("GET /v0/crawl/status/:jobId", () => {
it("should not require authorization", async () => {
const response = await request(TEST_URL).get("/v0/crawl/status/123");
diff --git a/apps/api/src/__tests__/e2e_withAuth/index.test.ts b/apps/api/src/__tests__/e2e_withAuth/index.test.ts
index ba01a7ca4..f0887ebae 100644
--- a/apps/api/src/__tests__/e2e_withAuth/index.test.ts
+++ b/apps/api/src/__tests__/e2e_withAuth/index.test.ts
@@ -133,6 +133,34 @@ const TEST_URL = "http://127.0.0.1:3002";
});
});
+ describe("POST /v0/search", () => {
+ it("should require authorization", async () => {
+ const response = await request(TEST_URL).post("/v0/search");
+ expect(response.statusCode).toBe(401);
+ });
+
+ it("should return an error response with an invalid API key", async () => {
+ const response = await request(TEST_URL)
+ .post("/v0/search")
+ .set("Authorization", `Bearer invalid-api-key`)
+ .set("Content-Type", "application/json")
+ .send({ query: "test" });
+ expect(response.statusCode).toBe(401);
+ });
+
+ it("should return a successful response with a valid API key", async () => {
+ const response = await request(TEST_URL)
+ .post("/v0/search")
+ .set("Authorization", `Bearer ${process.env.TEST_API_KEY}`)
+ .set("Content-Type", "application/json")
+ .send({ query: "test" });
+ expect(response.statusCode).toBe(200);
+ expect(response.body).toHaveProperty("success");
+ expect(response.body.success).toBe(true);
+ expect(response.body).toHaveProperty("data");
+ }, 20000);
+ });
+
describe("GET /v0/crawl/status/:jobId", () => {
it("should require authorization", async () => {
const response = await request(TEST_URL).get("/v0/crawl/status/123");