Skip to content

Commit 7f27ac2

Browse files
committed
add additional tests
1 parent fc7fa6d commit 7f27ac2

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

src/connection/helpers.test.ts

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ describe('Testing of the connection helper methods', () => {
1919
});
2020
});
2121

22+
it('should connect to a local cluster', () => {
23+
return weaviate
24+
.connectToLocal()
25+
.then((client) => client.getMeta())
26+
.then((res: any) => {
27+
expect(res.version).toBeDefined();
28+
})
29+
.catch((e: any) => {
30+
throw new Error('it should not have errord: ' + e);
31+
});
32+
});
33+
2234
describe('adds Weaviate Embedding Service headers', () => {
2335
it('to empty headers', async () => {
2436
const clientMakerMock = jest.fn().mockResolvedValue(undefined);
@@ -27,11 +39,9 @@ describe('Testing of the connection helper methods', () => {
2739
authCredentials: new weaviate.ApiKey(WCD_KEY),
2840
});
2941

30-
expect(clientMakerMock.mock.calls[0][0]).toMatchObject({
31-
headers: {
32-
'X-Weaviate-Api-Key': WCD_KEY,
33-
'X-Weaviate-Cluster-Url': WCD_URL,
34-
},
42+
expect(clientMakerMock.mock.calls[0][0].headers).toEqual({
43+
'X-Weaviate-Api-Key': WCD_KEY,
44+
'X-Weaviate-Cluster-Url': WCD_URL,
3545
});
3646
});
3747

@@ -43,25 +53,34 @@ describe('Testing of the connection helper methods', () => {
4353
headers: { existingHeader: 'existingValue' },
4454
});
4555

46-
expect(clientMakerMock.mock.calls[0][0]).toMatchObject({
47-
headers: {
48-
existingHeader: 'existingValue',
49-
'X-Weaviate-Api-Key': WCD_KEY,
50-
'X-Weaviate-Cluster-Url': WCD_URL,
51-
},
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,
5260
});
5361
});
5462
});
5563

56-
it('should connect to a local cluster', () => {
57-
return weaviate
58-
.connectToLocal()
59-
.then((client) => client.getMeta())
60-
.then((res: any) => {
61-
expect(res.version).toBeDefined();
62-
})
63-
.catch((e: any) => {
64-
throw new Error('it should not have errord: ' + e);
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' },
6581
});
82+
83+
expect(clientMakerMock.mock.calls[0][0].headers).toEqual({ existingHeader: 'existingValue' });
84+
});
6685
});
6786
});

0 commit comments

Comments
 (0)