|
| 1 | +import { QdrantContainer } from "./qdrant-container"; |
| 2 | +import { QdrantClient } from "@qdrant/js-client-rest"; |
| 3 | +import crypto from "crypto"; |
| 4 | +import path from "path"; |
| 5 | + |
| 6 | +describe("QdrantContainer", () => { |
| 7 | + jest.setTimeout(100_000); |
| 8 | + |
| 9 | + // connectQdrantSimple { |
| 10 | + it("should connect to the client", async () => { |
| 11 | + const container = await new QdrantContainer().start(); |
| 12 | + |
| 13 | + const client = new QdrantClient({ url: `http://${container.getRestHostAddress()}` }); |
| 14 | + |
| 15 | + expect((await client.getCollections()).collections.length).toBe(0); |
| 16 | + |
| 17 | + await container.stop(); |
| 18 | + }); |
| 19 | + // } |
| 20 | + |
| 21 | + // connectQdrantWithApiKey { |
| 22 | + it("should work with valid API keys", async () => { |
| 23 | + const apiKey = crypto.randomUUID(); |
| 24 | + |
| 25 | + const container = await new QdrantContainer().withApiKey(apiKey).start(); |
| 26 | + |
| 27 | + const client = new QdrantClient({ url: `http://${container.getRestHostAddress()}`, apiKey }); |
| 28 | + |
| 29 | + expect((await client.getCollections()).collections.length).toBe(0); |
| 30 | + |
| 31 | + await container.stop(); |
| 32 | + }); |
| 33 | + // } |
| 34 | + |
| 35 | + it("should fail for invalid API keys", async () => { |
| 36 | + const apiKey = crypto.randomUUID(); |
| 37 | + |
| 38 | + const container = await new QdrantContainer().withApiKey(apiKey).start(); |
| 39 | + |
| 40 | + const client = new QdrantClient({ |
| 41 | + url: `http://${container.getRestHostAddress()}`, |
| 42 | + apiKey: "INVALID_KEY_" + crypto.randomUUID(), |
| 43 | + }); |
| 44 | + |
| 45 | + expect(client.getCollections()).rejects.toThrow("Forbidden"); |
| 46 | + |
| 47 | + await container.stop(); |
| 48 | + }); |
| 49 | + |
| 50 | + // connectQdrantWithConfig { |
| 51 | + it("should work with config files - valid API key", async () => { |
| 52 | + const container = await new QdrantContainer().withConfigFile(path.resolve(__dirname, "test_config.yaml")).start(); |
| 53 | + |
| 54 | + const client = new QdrantClient({ url: `http://${container.getRestHostAddress()}`, apiKey: "SOME_TEST_KEY" }); |
| 55 | + |
| 56 | + expect((await client.getCollections()).collections.length).toBe(0); |
| 57 | + |
| 58 | + await container.stop(); |
| 59 | + }); |
| 60 | + // } |
| 61 | + |
| 62 | + it("should work with config files - invalid API key", async () => { |
| 63 | + const container = await new QdrantContainer().withConfigFile(path.resolve(__dirname, "test_config.yaml")).start(); |
| 64 | + |
| 65 | + const client = new QdrantClient({ |
| 66 | + url: `http://${container.getRestHostAddress()}`, |
| 67 | + apiKey: "INVALID_KEY_" + crypto.randomUUID(), |
| 68 | + }); |
| 69 | + |
| 70 | + expect(client.getCollections()).rejects.toThrow("Forbidden"); |
| 71 | + |
| 72 | + await container.stop(); |
| 73 | + }); |
| 74 | +}); |
0 commit comments