|
1 | 1 | import weaviate from '../index.js'; |
| 2 | +import { connectToWeaviateCloud } from './helpers.js'; |
2 | 3 |
|
3 | 4 | const WCD_URL = 'https://piblpmmdsiknacjnm1ltla.c1.europe-west3.gcp.weaviate.cloud'; |
4 | 5 | const WCD_KEY = 'cy4ua772mBlMdfw3YnclqAWzFhQt0RLIN0sl'; |
@@ -29,4 +30,57 @@ describe('Testing of the connection helper methods', () => { |
29 | 30 | throw new Error('it should not have errord: ' + e); |
30 | 31 | }); |
31 | 32 | }); |
| 33 | + |
| 34 | + describe('adds Weaviate Embedding Service headers', () => { |
| 35 | + it('to empty headers', async () => { |
| 36 | + const clientMakerMock = jest.fn().mockResolvedValue(undefined); |
| 37 | + |
| 38 | + await connectToWeaviateCloud(WCD_URL, clientMakerMock, { |
| 39 | + authCredentials: new weaviate.ApiKey(WCD_KEY), |
| 40 | + }); |
| 41 | + |
| 42 | + expect(clientMakerMock.mock.calls[0][0].headers).toEqual({ |
| 43 | + 'X-Weaviate-Api-Key': WCD_KEY, |
| 44 | + 'X-Weaviate-Cluster-Url': WCD_URL, |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + it('to existing headers', async () => { |
| 49 | + const clientMakerMock = jest.fn().mockResolvedValue(undefined); |
| 50 | + |
| 51 | + await connectToWeaviateCloud(WCD_URL, clientMakerMock, { |
| 52 | + authCredentials: new weaviate.ApiKey(WCD_KEY), |
| 53 | + headers: { existingHeader: 'existingValue' }, |
| 54 | + }); |
| 55 | + |
| 56 | + expect(clientMakerMock.mock.calls[0][0].headers).toEqual({ |
| 57 | + existingHeader: 'existingValue', |
| 58 | + 'X-Weaviate-Api-Key': WCD_KEY, |
| 59 | + 'X-Weaviate-Cluster-Url': WCD_URL, |
| 60 | + }); |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + describe('does not add Weaviate Embedding Service headers when not using API key', () => { |
| 65 | + it('to empty headers', async () => { |
| 66 | + const clientMakerMock = jest.fn().mockResolvedValue(undefined); |
| 67 | + |
| 68 | + await connectToWeaviateCloud(WCD_URL, clientMakerMock, { |
| 69 | + authCredentials: new weaviate.AuthUserPasswordCredentials({ username: 'test' }), |
| 70 | + }); |
| 71 | + |
| 72 | + expect(clientMakerMock.mock.calls[0][0].headers).toBe(undefined); |
| 73 | + }); |
| 74 | + |
| 75 | + it('to existing headers', async () => { |
| 76 | + const clientMakerMock = jest.fn().mockResolvedValue(undefined); |
| 77 | + |
| 78 | + await connectToWeaviateCloud(WCD_URL, clientMakerMock, { |
| 79 | + authCredentials: new weaviate.AuthUserPasswordCredentials({ username: 'test' }), |
| 80 | + headers: { existingHeader: 'existingValue' }, |
| 81 | + }); |
| 82 | + |
| 83 | + expect(clientMakerMock.mock.calls[0][0].headers).toEqual({ existingHeader: 'existingValue' }); |
| 84 | + }); |
| 85 | + }); |
32 | 86 | }); |
0 commit comments