@pinecone-database/pinecone
Version:
This is the official Node.js SDK for [Pinecone](https://www.pinecone.io), written in TypeScript.
63 lines • 3.11 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const namespacesOperationsProvider_1 = require("../../namespaces/namespacesOperationsProvider");
const indexHostSingleton_1 = require("../../indexHostSingleton");
const db_data_1 = require("../../../pinecone-generated-ts-fetch/db_data");
jest.mock('../../../pinecone-generated-ts-fetch/db_data', () => ({
...jest.requireActual('../../../pinecone-generated-ts-fetch/db_data'),
Configuration: jest.fn(),
}));
describe('NamespacesOperationsProvider', () => {
let real;
const config = {
apiKey: 'test-api-key',
};
beforeAll(() => {
real = indexHostSingleton_1.IndexHostSingleton.getHostUrl;
});
afterAll(() => {
indexHostSingleton_1.IndexHostSingleton.getHostUrl = real;
});
beforeEach(() => {
indexHostSingleton_1.IndexHostSingleton.getHostUrl = jest.fn();
});
afterEach(() => {
indexHostSingleton_1.IndexHostSingleton._reset();
});
test('makes no API calls on instantiation', async () => {
const config = {
apiKey: 'test-api-key',
};
new namespacesOperationsProvider_1.NamespaceOperationsProvider(config, 'index-name');
expect(indexHostSingleton_1.IndexHostSingleton.getHostUrl).not.toHaveBeenCalled();
});
test('api calls occur only the first time the provide method is called', async () => {
const config = {
apiKey: 'test-api-key',
};
const provider = new namespacesOperationsProvider_1.NamespaceOperationsProvider(config, 'index-name');
expect(indexHostSingleton_1.IndexHostSingleton.getHostUrl).not.toHaveBeenCalled();
const api = await provider.provide();
expect(indexHostSingleton_1.IndexHostSingleton.getHostUrl).toHaveBeenCalled();
const api2 = await provider.provide();
expect(indexHostSingleton_1.IndexHostSingleton.getHostUrl).toHaveBeenCalledTimes(1);
expect(api).toEqual(api2);
});
test('passing indexHostUrl skips hostUrl resolution', async () => {
const indexHostUrl = 'http://index-host-url';
const provider = new namespacesOperationsProvider_1.NamespaceOperationsProvider(config, 'index-name', indexHostUrl);
jest.spyOn(provider, 'buildNamespaceOperationsConfig');
await provider.provide();
expect(indexHostSingleton_1.IndexHostSingleton.getHostUrl).not.toHaveBeenCalled();
expect(provider.buildNamespaceOperationsConfig).toHaveBeenCalled();
});
test('passing additionalHeaders applies them to the API Configuration', async () => {
const additionalHeaders = { 'x-custom-header': 'custom-value' };
const provider = new namespacesOperationsProvider_1.NamespaceOperationsProvider(config, 'index-name', undefined, additionalHeaders);
await provider.provide();
expect(db_data_1.Configuration).toHaveBeenCalledWith(expect.objectContaining({
headers: expect.objectContaining(additionalHeaders),
}));
});
});
//# sourceMappingURL=namespacesOperationsProvider.test.js.map
;