-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathindex.test.ts
61 lines (53 loc) · 1.74 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import MindsDB from '../src/index';
import axios from 'axios';
import Constants from '../src/constants';
jest.mock('axios');
const mockedAxios = axios as jest.Mocked<typeof axios>;
describe('Testing root SDK functions', () => {
afterEach(() => {
mockedAxios.post.mockClear();
});
test('connect should authenticate for Cloud endpoint', async () => {
mockedAxios.post.mockResolvedValue({
headers: {
// MindsDB Cloud login always returns a session cookie in response headers.
'set-cookie': ['session=test-session; Domain=.mindsdb.com; Path=/'],
},
});
await MindsDB.connect({
user: 'test-user',
password: 'test-password',
httpClient: mockedAxios,
});
expect(mockedAxios.post).toHaveBeenCalled();
const loginURL = new URL(
Constants.BASE_LOGIN_URI,
Constants.BASE_CLOUD_API_ENDPOINT
).toString();
const argURL = mockedAxios.post.mock.calls[0][0];
expect(argURL).toEqual(loginURL);
const argData = mockedAxios.post.mock.calls[0][1];
expect(argData).toMatchObject({
email: 'test-user',
password: 'test-password',
});
expect(MindsDB.SQL.authenticator.session).toEqual('test-session');
});
test('connect should not authenticate for custom endpoint', async () => {
await MindsDB.connect({
host: 'https://test-url.com',
user: 'test-user',
password: 'test-password',
httpClient: mockedAxios,
});
expect(mockedAxios.post).not.toHaveBeenCalled();
});
test('connect should override module default axios instance', async () => {
await MindsDB.connect({
user: 'test-user',
password: 'test-password',
httpClient: mockedAxios,
});
expect(MindsDB.SQL.client).toBe(mockedAxios);
});
});