-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update minor version in package.json, 2
- Loading branch information
Showing
6 changed files
with
121 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Pinecone } from "@pinecone-database/pinecone"; | ||
import { getPineconeClient } from "../client.js"; | ||
|
||
describe("Tests for getPineconeClient", () => { | ||
test("Happy path for getPineconeClient with and without `config` obj passed", async () => { | ||
const client = getPineconeClient(); | ||
expect(client).toBeInstanceOf(Pinecone); | ||
expect(client).toHaveProperty("config"); // Config is always set to *at least* the user's api key | ||
|
||
const clientWithConfig = getPineconeClient({ | ||
// eslint-disable-next-line no-process-env | ||
apiKey: process.env.PINECONE_API_KEY!, | ||
additionalHeaders: { header: "value" }, | ||
}); | ||
expect(clientWithConfig).toBeInstanceOf(Pinecone); | ||
expect(client).toHaveProperty("config"); // Unfortunately cannot assert on contents of config b/c it's a private | ||
// attribute of the Pinecone class | ||
}); | ||
|
||
test("Unhappy path: expect getPineconeClient to throw error if reset PINECONE_API_KEY to empty string", async () => { | ||
// eslint-disable-next-line no-process-env | ||
const originalApiKey = process.env.PINECONE_API_KEY; | ||
try { | ||
// eslint-disable-next-line no-process-env | ||
process.env.PINECONE_API_KEY = ""; | ||
const errorThrown = async () => { | ||
getPineconeClient(); | ||
}; | ||
await expect(errorThrown).rejects.toThrow(Error); | ||
await expect(errorThrown).rejects.toThrow( | ||
"PINECONE_API_KEY must be set in environment" | ||
); | ||
} finally { | ||
// Restore the original value of PINECONE_API_KEY | ||
// eslint-disable-next-line no-process-env | ||
process.env.PINECONE_API_KEY = originalApiKey; | ||
} | ||
}); | ||
}); |
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,43 @@ | ||
import { Pinecone, PineconeConfiguration } from "@pinecone-database/pinecone"; | ||
import { jest } from "@jest/globals"; | ||
import { getPineconeClient } from "../client.js"; | ||
|
||
// Mock the Pinecone class | ||
jest.mock("@pinecone-database/pinecone", () => ({ | ||
Pinecone: jest.fn().mockImplementation((config) => ({ | ||
config, | ||
inference: { embed: jest.fn() }, | ||
})), | ||
})); | ||
|
||
describe("Tests for getPineconeClient", () => { | ||
test("Confirm getPineconeClient throws error when PINECONE_API_KEY is not set", async () => { | ||
/* eslint-disable-next-line no-process-env */ | ||
process.env.PINECONE_API_KEY = ""; | ||
const errorThrown = async () => { | ||
getPineconeClient(); | ||
}; | ||
await expect(errorThrown).rejects.toThrow(Error); | ||
await expect(errorThrown).rejects.toThrow( | ||
"PINECONE_API_KEY must be set in environment" | ||
); | ||
}); | ||
|
||
test("Confirm getPineconeClient calls Pinecone class (mocked) with and without config", async () => { | ||
/* eslint-disable-next-line no-process-env */ | ||
process.env.PINECONE_API_KEY = "some-valid-api-key"; | ||
|
||
// With config | ||
// Note: cannot assert on config contents themselves b/c `config` is a private attribute of the Pinecone class | ||
const config: PineconeConfiguration = { | ||
apiKey: "some-valid-api-key", | ||
additionalHeaders: { header: "value" }, | ||
}; | ||
getPineconeClient(config); | ||
expect(Pinecone).toHaveBeenCalledWith(config); | ||
|
||
// Without config | ||
getPineconeClient(); | ||
expect(Pinecone).toHaveBeenCalledWith(); | ||
}); | ||
}); |
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