forked from chroma-core/chroma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: JS Client Static Token support
- Authorization and X-Chroma-Token auths supported - Tests and integration tests updated Refs: chroma-core#1083
- Loading branch information
Showing
7 changed files
with
229 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {expect, test} from "@jest/globals"; | ||
import {ChromaClient} from "../src/ChromaClient"; | ||
import {chromaTokenDefault, chromaTokenBearer, chromaTokenXToken} from "./initClientWithAuth"; | ||
import chromaNoAuth from "./initClient"; | ||
|
||
test("it should get the version without auth needed", async () => { | ||
const version = await chromaNoAuth.version(); | ||
expect(version).toBeDefined(); | ||
expect(version).toMatch(/^[0-9]+\.[0-9]+\.[0-9]+$/); | ||
}); | ||
|
||
test("it should get the heartbeat without auth needed", async () => { | ||
const heartbeat = await chromaNoAuth.heartbeat(); | ||
expect(heartbeat).toBeDefined(); | ||
expect(heartbeat).toBeGreaterThan(0); | ||
}); | ||
|
||
test("it should raise error when non authenticated", async () => { | ||
await expect(chromaNoAuth.listCollections()).rejects.toMatchObject({ | ||
status: 401 | ||
}); | ||
}); | ||
|
||
if (!process.env.XTOKEN_TEST) { | ||
test('it should list collections with default token config', async () => { | ||
await chromaTokenDefault.reset() | ||
let collections = await chromaTokenDefault.listCollections() | ||
expect(collections).toBeDefined() | ||
expect(collections).toBeInstanceOf(Array) | ||
expect(collections.length).toBe(0) | ||
const collection = await chromaTokenDefault.createCollection({name: "test"}); | ||
collections = await chromaTokenDefault.listCollections() | ||
expect(collections.length).toBe(1) | ||
}) | ||
|
||
test('it should list collections with explicit bearer token config', async () => { | ||
await chromaTokenBearer.reset() | ||
let collections = await chromaTokenBearer.listCollections() | ||
expect(collections).toBeDefined() | ||
expect(collections).toBeInstanceOf(Array) | ||
expect(collections.length).toBe(0) | ||
const collection = await chromaTokenBearer.createCollection({name: "test"}); | ||
collections = await chromaTokenBearer.listCollections() | ||
expect(collections.length).toBe(1) | ||
}) | ||
} else { | ||
|
||
test('it should list collections with explicit x-token token config', async () => { | ||
await chromaTokenXToken.reset() | ||
let collections = await chromaTokenXToken.listCollections() | ||
expect(collections).toBeDefined() | ||
expect(collections).toBeInstanceOf(Array) | ||
expect(collections.length).toBe(0) | ||
const collection = await chromaTokenXToken.createCollection({name: "test"}); | ||
collections = await chromaTokenXToken.listCollections() | ||
expect(collections.length).toBe(1) | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters