|
| 1 | +// eslint-disable-next-line import/no-extraneous-dependencies |
| 2 | +import { Wait, DockerComposeEnvironment, StartedDockerComposeEnvironment } from 'testcontainers'; |
| 3 | +import { MongoBIDriver, } from '../src'; |
| 4 | + |
| 5 | +describe('MongoBiDriver', () => { |
| 6 | + let driver: MongoBIDriver; |
| 7 | + let environment: StartedDockerComposeEnvironment; |
| 8 | + |
| 9 | + jest.setTimeout(2 * 60 * 1000); |
| 10 | + |
| 11 | + beforeAll(async () => { |
| 12 | + const MONGO_TAG = process.env.TEST_MONGO_TAG || '6.0'; |
| 13 | + const MONGOBI_VERSION = process.env.TEST_MONGOBI_VERSION || 'mongodb-bi-linux-x86_64-ubuntu2004-v2.14.8'; |
| 14 | + |
| 15 | + environment = await new DockerComposeEnvironment('./test', 'docker-compose.yml') |
| 16 | + .withEnvironment({ MONGO_TAG, MONGOBI_VERSION }) |
| 17 | + .withWaitStrategy('mongosqld', Wait.forLogMessage('obtained initial schema')) |
| 18 | + .up(); |
| 19 | + |
| 20 | + const container = environment.getContainer('mongosqld'); |
| 21 | + |
| 22 | + driver = new MongoBIDriver({ |
| 23 | + host: container.getHost(), |
| 24 | + port: container.getMappedPort(3307), |
| 25 | + waitForConnections: true, |
| 26 | + database: 'test', |
| 27 | + dataSource: 'default', |
| 28 | + maxPoolSize: 1, |
| 29 | + testConnectionTimeout: 10, |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + afterAll(async () => { |
| 34 | + await driver.release(); |
| 35 | + await environment.down(); |
| 36 | + }); |
| 37 | + |
| 38 | + test('should test connection', async () => { |
| 39 | + await driver.testConnection(); |
| 40 | + }); |
| 41 | + |
| 42 | + test('should select raw sql', async () => { |
| 43 | + const result = await driver.query(` |
| 44 | + SELECT number |
| 45 | + FROM mycol |
| 46 | + LIMIT 1 |
| 47 | + `, []); |
| 48 | + expect(result).toEqual([{ number: 1 }]); |
| 49 | + }); |
| 50 | +}); |
0 commit comments