From d8fcfeea474b943293d534efcd4e04a8e3cfc20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=A1=D0=BE?= =?UTF-8?q?=D1=80=D0=BE=D0=BA=D0=B8=D0=BD?= Date: Thu, 18 Aug 2022 19:32:37 +0300 Subject: [PATCH] test --- .gitignore | 1 + test/test.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 3c90d5f..f23467a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .idea/* .vscode/ +test_config.json \ No newline at end of file diff --git a/test/test.js b/test/test.js index 80f43d0..f37b471 100644 --- a/test/test.js +++ b/test/test.js @@ -5,15 +5,21 @@ const expect = require('expect.js'); const _ = require('lodash'); const https = require('https'); const fs = require('fs'); +const path = require('path'); const { ClickHouse } = require('../.'); const database = 'test_' + _.random(1000, 100000); const + configFilepath = process.env.CLICKHOUSE_TEST_CONF_FILE || './test_config.json', + configPath = path.resolve(process.cwd(), configFilepath), + extConfig = fs.existsSync(configPath) ? JSON.parse(fs.readFileSync(configPath, { encoding: 'utf-8' })) : undefined, config = { - debug: false, + ...extConfig, + debug: false, }, + clickhouse = new ClickHouse({ ...config, database : database, @@ -305,7 +311,7 @@ describe('Select', () => { }); -describe('session', () => { +(extConfig? describe.skip : describe)('session', () => { it('use session', async () => { const sessionId = clickhouse.sessionId; clickhouse.sessionId = Date.now(); @@ -407,7 +413,8 @@ describe('session', () => { // You can use all settings from request library (https://github.com/request/request#tlsssl-protocol) // Generate ssl file with: // sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout test/cert/server.key -out test/cert/server.crt -describe('TLS/SSL Protocol', () => { + +(extConfig? describe.skip : describe)('TLS/SSL Protocol', () => { it('use TLS/SSL Protocol', async () => { let server = null; @@ -657,6 +664,42 @@ describe('queries', () => { const result4 = await clickhouse.query('SELECT int_value FROM test_int_temp').toPromise(); expect(result4).to.eql(int_value_data); }); + + it('insert with params', async () => { + const result = await clickhouse.query('DROP TABLE IF EXISTS test_par_temp').toPromise(); + expect(result).to.be.ok(); + + const result1 = await clickhouse.query(`CREATE TABLE test_par_temp ( + int_value UInt32, + str_value1 String, + str_value2 String, + date_value Date, + date_time_value DateTime, + decimal_value Decimal(10,4) + ) ENGINE=Memory`).toPromise(); + expect(result1).to.be.ok(); + + const row = { + int_value: 12345, + str_value1: 'Test for "masked" characters. It workes, isn\'t it?', + str_value2: JSON.stringify({name:'It is "something".'}), + date_value: '2022-08-18', + date_time_value: '2022-08-18 19:07:00', + decimal_value: 1234.678, + }; + const result2 = await clickhouse.insert(`INSERT INTO test_par_temp (int_value, str_value1, str_value2, date_value, date_time_value, decimal_value) + VALUES ({int_value:UInt32}, {str_value1:String}, {str_value2:String}, {date_value:Date}, {date_time_value:DateTime}, {decimal_value: Decimal(10,4)})`, + {params: { + ...row, + decimal_value: row.decimal_value.toFixed(4) + } + }).toPromise(); + expect(result2).to.be.ok(); + + const result3 = await clickhouse.query('SELECT * FROM test_par_temp').toPromise(); + expect(result3).to.eql([row]); + }); + }); describe('response codes', () => { @@ -728,7 +771,7 @@ describe('compatibility with Sequelize ORM', () => { -describe('Constructor options', () => { +(extConfig? describe.skip : describe)('Constructor options', () => { const addConfigs = [ { url: 'localhost',