Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #38 from SciPhi-AI/Nolan/UpdateJS
Browse files Browse the repository at this point in the history
Update JS client for Auth
  • Loading branch information
NolanTrem authored Jul 18, 2024
2 parents 624a17b + f2b97f5 commit 4439c5e
Show file tree
Hide file tree
Showing 11 changed files with 797 additions and 343 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
dist/
.DS_Store
.DS_Store
**/.DS_Store
15 changes: 10 additions & 5 deletions __tests__/r2rClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ describe("R2RClient", () => {

beforeEach(() => {
mockAxiosInstance = {
get: jest.fn(),
post: jest.fn(),
request: jest.fn(),
defaults: { baseURL: "http://0.0.0.0:8000/v1" },
};

Expand All @@ -26,13 +26,18 @@ describe("R2RClient", () => {
);
});

test("healthCheck should return data from the /health endpoint", async () => {
test("health should return data from the /health endpoint", async () => {
const mockResponse = { response: "ok" };
mockAxiosInstance.get.mockResolvedValue({ data: mockResponse });
mockAxiosInstance.request.mockResolvedValue({ data: mockResponse });

const result = await client.healthCheck();
const result = await client.health();
expect(result).toEqual(mockResponse);
expect(mockAxiosInstance.get).toHaveBeenCalledWith("/health");
expect(mockAxiosInstance.request).toHaveBeenCalledWith({
method: "GET",
url: "health",
headers: {},
responseType: "json",
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ describe("r2rClient Integration Tests", () => {
});

test("Health check", async () => {
await expect(client.healthCheck()).resolves.not.toThrow();
await expect(client.health()).resolves.not.toThrow();
});

test("Login", async () => {
await expect(
client.login("[email protected]", "change_me_immediately"),
).resolves.not.toThrow();
});

test("Ingest file", async () => {
Expand All @@ -37,11 +43,11 @@ describe("r2rClient Integration Tests", () => {

test("Update files", async () => {
const updated_file = [
{ path: "examples/data/folder/myshkin.txt", name: "myshkin.txt" },
{ path: "examples/data/folder/myshkin.txt", name: "super_myshkin.txt" },
];
await expect(
client.updateFiles(updated_file, {
document_ids: ["48e29904-3010-54fe-abe5-a4f3fba59110"],
document_ids: ["f3c6afa5-fc58-58b7-b797-f7148e5253c3"],
metadatas: [{ title: "updated_karamozov.txt" }],
}),
).resolves.not.toThrow();
Expand All @@ -53,19 +59,19 @@ describe("r2rClient Integration Tests", () => {

test("Generate RAG response", async () => {
await expect(client.rag({ query: "test" })).resolves.not.toThrow();
});
}, 10000);

test("Delete document", async () => {
await expect(
client.delete(["document_id"], ["153a0857-efc4-57dd-b629-1c7d58c24a93"]),
client.delete(["document_id"], ["cb6e55f3-cb3e-5646-ad52-42f06eb321f5"]),
).resolves.not.toThrow();
});

test("Get logs", async () => {
await expect(client.logs()).resolves.not.toThrow();
});

test("Get app settings", async () => {
test("App settings", async () => {
await expect(client.appSettings()).resolves.not.toThrow();
});

Expand Down Expand Up @@ -97,18 +103,21 @@ describe("r2rClient Integration Tests", () => {

test("Get document chunks", async () => {
await expect(
client.documentChunks("48e29904-3010-54fe-abe5-a4f3fba59110"),
client.documentChunks("43eebf9c-c2b4-59e5-993a-054bf4a5c423"),
).resolves.not.toThrow();
});

afterAll(async () => {
// Clean up
await client.delete(
["document_id", "document_id"],
[
"48e29904-3010-54fe-abe5-a4f3fba59110",
"102e815f-3998-5373-8d7d-a07795266ed6",
],
);
test("Clean up remaining documents", async () => {
await expect(
client.delete(["document_id"], ["43eebf9c-c2b4-59e5-993a-054bf4a5c423"]),
).resolves.not.toThrow();

await expect(
client.delete(["document_id"], ["f3c6afa5-fc58-58b7-b797-f7148e5253c3"]),
).resolves.not.toThrow;
});

test("Logout", async () => {
await expect(client.logout()).resolves.not.toThrow();
});
});
120 changes: 120 additions & 0 deletions __tests__/r2rClientIntegrationUser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { r2rClient } from "../src/index";
import { FilterCriteria, AnalysisTypes } from "../src/models";
const fs = require("fs");

const baseUrl = "http://localhost:8000";

describe("r2rClient Integration Tests", () => {
let client: r2rClient;

beforeAll(async () => {
client = new r2rClient(baseUrl);
});

test("Health check", async () => {
await expect(client.health()).resolves.not.toThrow();
});

test("Register user", async () => {
await expect(
client.register("[email protected]", "password"),
).resolves.not.toThrow();
});

test("Verify Email throws a 400 error", async () => {
await expect(client.verifyEmail("verification_code")).rejects.toThrow(
"Status 400: Email verification is not required",
);
});

test("Login", async () => {
await expect(
client.login("[email protected]", "password"),
).resolves.not.toThrow();
});

test("Ingest file", async () => {
const files = [
{ path: "examples/data/raskolnikov.txt", name: "raskolnikov.txt" },
];

await expect(
client.ingestFiles(files, {
metadatas: [{ title: "myshkin.txt" }, { title: "karamozov.txt" }],
skip_document_info: false,
}),
).resolves.not.toThrow();
});

test("Ingest files in folder", async () => {
const files = ["examples/data/folder"];

await expect(client.ingestFiles(files)).resolves.not.toThrow();
});

test("Update files", async () => {
const updated_file = [
{ path: "examples/data/folder/myshkin.txt", name: "myshkin.txt" },
];
await expect(
client.updateFiles(updated_file, {
document_ids: ["06f6aab5-daa1-5b22-809c-d73a378600ed"],
metadatas: [{ title: "updated_karamozov.txt" }],
}),
).resolves.not.toThrow();
});

test("Search documents", async () => {
await expect(client.search("test")).resolves.not.toThrow();
});

test("Generate RAG response", async () => {
await expect(client.rag({ query: "test" })).resolves.not.toThrow();
}, 10000);

test("Delete document", async () => {
await expect(
client.delete(["document_id"], ["c621c119-e21d-5d11-a099-bab1993f76d0"]),
).resolves.not.toThrow();
});

test("Only a superuser can call app settings", async () => {
await expect(client.appSettings()).rejects.toThrow(
"Status 403: Only a superuser can call the `app_settings` endpoint.",
);
});

test("Get documents overview", async () => {
await expect(client.documentsOverview()).resolves.not.toThrow();
});

test("Logout", async () => {
await expect(client.logout()).resolves.not.toThrow();
});

test("Login after logout", async () => {
await expect(
client.login("[email protected]", "password"),
).resolves.not.toThrow();
});

test("Clean up remaining documents", async () => {
await expect(
client.delete(["document_id"], ["f58d4ec4-0274-56fa-b1ce-16aa3ba9ce3c"]),
).resolves.not.toThrow();

await expect(
client.delete(["document_id"], ["06f6aab5-daa1-5b22-809c-d73a378600ed"]),
).resolves.not.toThrow;
});

test("Change password", async () => {
await expect(
client.changePassword("password", "new_password"),
).resolves.not.toThrow();
});

test("Delete User", async () => {
await expect(client.deleteUser("new_password")).resolves.not.toThrow();
});
});
Binary file removed examples/.DS_Store
Binary file not shown.
Binary file removed examples/data/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "r2r-js",
"version": "1.1.1",
"version": "1.2.0",
"description": "",
"main": "dist/index.js",
"browser": "dist/index.browser.js",
Expand All @@ -26,17 +26,17 @@
"dependencies": {
"axios": "^1.7.2",
"form-data": "^4.0.0",
"posthog-js": "^1.144.0",
"posthog-js": "^1.148.0",
"posthog-node": "^4.0.1",
"uuid": "^10.0.0"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^20.14.9",
"@types/node": "^20.14.11",
"@types/uuid": "^10.0.0",
"jest": "^29.7.0",
"prettier": "^3.3.2",
"ts-jest": "^29.1.5",
"prettier": "^3.3.3",
"ts-jest": "^29.2.3",
"ts-node": "^10.9.2",
"typescript": "^5.5.3"
}
Expand Down
Loading

0 comments on commit 4439c5e

Please sign in to comment.