Skip to content

Commit

Permalink
Added integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adeelehsan committed Jan 2, 2025
1 parent bd6731c commit e751a34
Show file tree
Hide file tree
Showing 21 changed files with 1,254 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_KEY=zut_DrBAgY0Ealb0vOu3JNVJryiQ5ViqJbmoxHK2Sw
1 change: 1 addition & 0 deletions .fernignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Specify files that shouldn't be modified by Fern

src/core/fetcher/Fetcher.ts
test/integration
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
.DS_Store
/dist
/dist

.idea/
.env
Binary file added example/resources/arxiv/2409.05865v1.pdf
Binary file not shown.
Binary file added example/resources/arxiv/2409.05866v1.pdf
Binary file not shown.
Binary file added example/resources/arxiv/2409.05867v1.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testEnvironmentOptions: {
dotenv: {
path: '.env'
}
},
testTimeout: 60000,
};
94 changes: 94 additions & 0 deletions tests/integration/apiKeys.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { VectaraClient } from "../../src";

describe('Test ApiKeys', () => {
const client = new VectaraClient({
apiKey: process.env.APIKEY,
});
let key: string;

beforeEach(async () => {
const response = await client.corpora.create({
name: "test-api-key-manager",
key: "test-document-manager"
});
if (response.key) {
key = response.key;
}

await new Promise((resolve) => setTimeout(resolve, 60000));
});

afterEach(async () => {
const corpora = await client.corpora.list();
for await (const corpus of corpora) {
await client.corpora.delete(corpus.key ?? "");
}
const apiKeys = await client.apiKeys.list();
for await (const apiKey of apiKeys) {
await client.apiKeys.delete(apiKey.id ?? "");
}
});

test('test create api key', async () => {
const response = await client.apiKeys.create({
name: "test-key",
apiKeyRole: "serving",
corpusKeys: [key]
});

expect(response.name).toBe("test-key");
expect(response.enabled).toBe(true);
expect(response.apiKeyRole).toBe("serving");
});

test('test delete api key', async () => {
const createResponse = await client.apiKeys.create({
name: "test-key",
apiKeyRole: "serving",
corpusKeys: [key]
});

const deleteResponse = await client.apiKeys.delete(createResponse.id ?? "");
expect(deleteResponse).toBeNull();
});

test('test get api key', async () => {
const createResponse = await client.apiKeys.create({
name: "test-key",
apiKeyRole: "serving",
corpusKeys: [key]
});

const getResponse = await client.apiKeys.get(createResponse.id ?? "");
expect(getResponse.name).toBe(createResponse.name);
});

test('test update api key', async () => {
const createResponse = await client.apiKeys.create({
name: "test-key",
apiKeyRole: "serving",
corpusKeys: [key]
});

const updateResponse = await client.apiKeys.update(createResponse.id ?? "", { enabled: false });
expect(updateResponse.enabled).toBe(false);
});

test('test list api keys', async () => {
const apiKeysNames: string[] = [];

for (let index = 0; index < 2; index++) {
const createResponse = await client.apiKeys.create({
name: `test-key-${index}`,
apiKeyRole: "serving",
corpusKeys: [key]
});
if (createResponse.name) apiKeysNames.push(createResponse.name);
}

const apiKeys = await client.apiKeys.list();
for await (const apiKey of apiKeys) {
expect(apiKeysNames).toContain(apiKey.name);
}
});
});
85 changes: 85 additions & 0 deletions tests/integration/appClient.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { VectaraClient } from "../../src";

describe('Test AppClient', () => {
const client = new VectaraClient({
apiKey: process.env.APIKEY,
});

afterEach(async () => {
const appClients = await client.appClients.list();
for await (const appClient of appClients) {
await client.appClients.delete(appClient.id ?? "");
}
});

test('test create app client', async () => {
const response = await client.appClients.create({ body: {
type: "client_credentials",
name: "test-client",
apiRoles: ["owner"]
}});

expect(response.name).toBe("test-client");
expect(response.clientId).not.toBeNull();
expect(response.clientSecret).not.toBeNull();
});

test('test get app client', async () => {
const createResponse = await client.appClients.create({ body: {
type: "client_credentials",
name: "test-client",
apiRoles: ["owner"]
}});

const getResponse = await client.appClients.get(createResponse.id ?? "");

expect(getResponse.clientId).toBe(createResponse.clientId);
expect(getResponse.clientSecret).toBe(createResponse.clientSecret);
});

test('test delete app client', async () => {
const createResponse = await client.appClients.create({ body: {
type: "client_credentials",
name: "test-client",
apiRoles: ["owner"]
}});

const delResponse = await client.appClients.delete(createResponse.id ?? "");

expect(delResponse).toBeNull();
});

test('test update app client', async () => {
const createResponse = await client.appClients.create({ body: {
type: "client_credentials",
name: "test-client",
apiRoles: ["owner"]
}});

const updateResponse = await client.appClients.update(createResponse.id ?? "", {
apiRoles: ["owner", "administrator"],
description: "test client"
});

expect(updateResponse.apiRoles).toEqual(["administrator"]);
expect(updateResponse.description).toBe("test client");
});

test('test list app clients', async () => {
const clientIds: string[] = [];
for (let index = 0; index < 2; index++) {
const createResponse = await client.appClients.create({ body: {
type: "client_credentials",
name: `test-client-${index}`,
apiRoles: ["owner"]
}});
if (createResponse.clientId) clientIds.push(createResponse.clientId);
}

const clients = await client.appClients.list();

for await (const client of clients) {
expect(clientIds).toContain(client.clientId);
}
});
});
37 changes: 37 additions & 0 deletions tests/integration/auth.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { VectaraClient } from "../../src";

describe('Test Auth Manager', () => {
const client = new VectaraClient({
apiKey: process.env.APIKEY,
});
let clientId: string;
let clientSecret: string;

beforeEach(async () => {
const response = await client.appClients.create({ body: {
type: "client_credentials",
name: "test-client",
apiRoles: ["owner"]
}});
clientId = response.clientId ?? "";
clientSecret = response.clientSecret ?? "";
});

afterEach(async () => {
const appClients = await client.appClients.list();
for await (const appClient of appClients) {
await client.appClients.delete(appClient.id ?? "");
}
});

test('test get access token', async () => {
const response = await client.auth.getToken({
clientId: clientId,
clientSecret: clientSecret,
});

expect(response.accessToken).not.toBeNull();
expect(response.tokenType).not.toBeNull();
expect(response.expiresIn).not.toBeNull();
});
});
Loading

0 comments on commit e751a34

Please sign in to comment.