Skip to content

Commit

Permalink
Modified ibisAdaptor test for MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
ongdisheng committed Jan 3, 2025
1 parent f7e01a2 commit 4f2081a
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions wren-ui/src/apollo/server/adaptors/tests/ibisAdaptor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
IbisQueryResponse,
ValidationRules,
} from '../ibisAdaptor';
import { DataSourceName } from '../../types';
import { DataSourceName, SSLMode } from '../../types';
import { Manifest } from '../../mdl/type';
import {
BIG_QUERY_CONNECTION_INFO,
Expand Down Expand Up @@ -45,6 +45,8 @@ describe('IbisAdaptor', () => {
database: 'my-database',
user: 'my-user',
password: 'my-password',
sslMode: SSLMode.VERIFY_CA,
sslCA: 'encrypted-certificate-string',
};

const mockPostgresConnectionInfo: POSTGRES_CONNECTION_INFO = {
Expand Down Expand Up @@ -176,17 +178,28 @@ describe('IbisAdaptor', () => {
mockedAxios.post.mockResolvedValue(mockResponse);
// mock decrypt method in Encryptor to return the same password
mockedEncryptor.prototype.decrypt.mockReturnValue(
JSON.stringify({ password: mockMySQLConnectionInfo.password }),
JSON.stringify({
password: mockMySQLConnectionInfo.password,
...(mockMySQLConnectionInfo.sslCA && { sslCA: mockMySQLConnectionInfo.sslCA })
}),
);

const result = await ibisAdaptor.getConstraints(
DataSourceName.MYSQL,
mockMySQLConnectionInfo,
);
const expectConnectionInfo = Object.entries(mockMySQLConnectionInfo).reduce(
(acc, [key, value]) => ((acc[snakeCase(key)] = value), acc),
{},
);
const expectConnectionInfo = Object.entries(
mockMySQLConnectionInfo,
).reduce((acc, [key, value]) => {
if (key === 'sslCA') {
acc['sslCA'] = Buffer
.from(mockMySQLConnectionInfo.sslCA)
.toString('base64');
} else {
acc[key] = value;
}
return acc;
}, {});

expect(result).toEqual([]);
expect(mockedAxios.post).toHaveBeenCalledWith(
Expand Down

0 comments on commit 4f2081a

Please sign in to comment.