|
| 1 | +import { r2rClient } from "../src/index"; |
| 2 | + |
| 3 | +const baseUrl = "http://localhost:8000"; |
| 4 | + |
| 5 | +describe("r2rClient Integration Tests", () => { |
| 6 | + let client: r2rClient; |
| 7 | + |
| 8 | + beforeAll(async () => { |
| 9 | + client = new r2rClient(baseUrl); |
| 10 | + }); |
| 11 | + |
| 12 | + test("Health check", async () => { |
| 13 | + await expect(client.healthCheck()).resolves.not.toThrow(); |
| 14 | + }); |
| 15 | + |
| 16 | + test("Ingest files", async () => { |
| 17 | + const files = [ |
| 18 | + { path: "__tests__/data/raskolnikov.txt", name: "raskolnikov.txt" }, |
| 19 | + { path: "__tests__/data/karamozov.txt", name: "karamozov.txt" }, |
| 20 | + ]; |
| 21 | + await expect( |
| 22 | + client.ingestFiles(files, { |
| 23 | + metadatas: [{ title: "raskolnikov.txt" }, { title: "karamozov.txt" }], |
| 24 | + user_ids: [ |
| 25 | + "123e4567-e89b-12d3-a456-426614174000", |
| 26 | + "123e4567-e89b-12d3-a456-426614174000", |
| 27 | + ], |
| 28 | + skip_document_info: false, |
| 29 | + }), |
| 30 | + ).resolves.not.toThrow(); |
| 31 | + }); |
| 32 | + |
| 33 | + test("Update files", async () => { |
| 34 | + const updated_file = [ |
| 35 | + { path: "__tests__/data/myshkin.txt", name: "myshkin.txt" }, |
| 36 | + ]; |
| 37 | + await expect( |
| 38 | + client.updateFiles(updated_file, { |
| 39 | + document_ids: ["48e29904-3010-54fe-abe5-a4f3fba59110"], |
| 40 | + metadatas: [{ title: "myshkin.txt" }], |
| 41 | + }), |
| 42 | + ).resolves.not.toThrow(); |
| 43 | + }); |
| 44 | + |
| 45 | + test("Search documents", async () => { |
| 46 | + await expect(client.search("test")).resolves.not.toThrow(); |
| 47 | + }); |
| 48 | + |
| 49 | + test("Generate RAG response", async () => { |
| 50 | + await expect(client.rag({ query: "test" })).resolves.not.toThrow(); |
| 51 | + }); |
| 52 | + |
| 53 | + test("Delete document", async () => { |
| 54 | + await expect( |
| 55 | + client.delete(["document_id"], ["153a0857-efc4-57dd-b629-1c7d58c24a93"]), |
| 56 | + ).resolves.not.toThrow(); |
| 57 | + }); |
| 58 | + |
| 59 | + test("Get logs", async () => { |
| 60 | + await expect(client.logs()).resolves.not.toThrow(); |
| 61 | + }); |
| 62 | + |
| 63 | + test("Get app settings", async () => { |
| 64 | + await expect(client.appSettings()).resolves.not.toThrow(); |
| 65 | + }); |
| 66 | + |
| 67 | + // test('Get analytics', async () => { |
| 68 | + // const filterCriteria = { |
| 69 | + // filters: { |
| 70 | + // "search_latencies": "search_latency" |
| 71 | + // } |
| 72 | + // }; |
| 73 | + |
| 74 | + // const analysisTypes = { |
| 75 | + // "search_latencies": ["basic_statistics", "search_latency"] |
| 76 | + // }; |
| 77 | + |
| 78 | + // await expect(client.analytics(filterCriteria, analysisTypes)).resolves.not.toThrow(); |
| 79 | + // }); |
| 80 | + |
| 81 | + test("Get users overview", async () => { |
| 82 | + await expect(client.usersOverview()).resolves.not.toThrow(); |
| 83 | + }); |
| 84 | + |
| 85 | + test("Get documents overview", async () => { |
| 86 | + await expect(client.documentsOverview()).resolves.not.toThrow(); |
| 87 | + }); |
| 88 | + |
| 89 | + test("Get document chunks", async () => { |
| 90 | + await expect( |
| 91 | + client.documentChunks("48e29904-3010-54fe-abe5-a4f3fba59110"), |
| 92 | + ).resolves.not.toThrow(); |
| 93 | + }); |
| 94 | + |
| 95 | + afterAll(async () => { |
| 96 | + // Clean up |
| 97 | + await client.delete( |
| 98 | + ["document_id"], |
| 99 | + ["48e29904-3010-54fe-abe5-a4f3fba59110"], |
| 100 | + ); |
| 101 | + }); |
| 102 | +}); |
0 commit comments