mindsdb / mindsdb-js-sdk

Official JavaScript SDK for MindsDB
MIT License
20 stars 24 forks source link

Prettier Issue and Existing Test Case Failure #61

Open md-abid-hussain opened 1 month ago

md-abid-hussain commented 1 month ago

Prettier issue image

and failing test cases image

md-abid-hussain commented 1 month ago

The fix is simple

The prettier issue is caused by a redundant import in src/models/modelsRestApiClient.ts at line 14. This is also causing 4 test case failures.

The one test case is failing due to logic error in the connect method, which is inside src/index.ts

const connect = async function (options: ConnectionOptions): Promise<void> {
  ...
  const baseURL =
    httpClient.defaults.baseURL || Constants.BASE_CLOUD_API_ENDPOINT;
  // Need to authenticate if we're using the Cloud API endpoints.
  if (isMindsDbCloudEndpoint(baseURL) || !isLocalEndpoint(baseURL)) {
    ...
  }
};

isMindsDbCloudEndpoint method

function isMindsDbCloudEndpoint(url: string): boolean {
  // Cloud endpoints:
  // - https://cloud.mindsdb.com
  // - https://alpha.mindsdb.com
  // - https://beta.mindsdb.com
  return url.includes('mindsdb.com');
}

isLocalEndpoint

function isLocalEndpoint(url: string): boolean {
  return url.includes('localhost') || url.includes('127.0.0.1');
}

And test case is

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();
  });

https://test-url.com will give true for

if (isMindsDbCloudEndpoint(baseURL) || !isLocalEndpoint(baseURL))

and hence test case will fail