From 21a828c452c472dcbd30459ac28da7cd7733c1cc Mon Sep 17 00:00:00 2001 From: slvrtrn Date: Fri, 17 May 2024 17:58:16 +0200 Subject: [PATCH] Update CHANGELOG and the JSON result tests --- CHANGELOG.md | 3 +- .../integration/select_result.test.ts | 73 +++++-------------- 2 files changed, 21 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1bb445b..b21da4f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ -# 1.0.2 (Common, Node.js) +# 1.0.2 (Common, Node.js, Web) ## Bug fixes - (Node.js only) The `command` method now drains the response stream properly, as the previous implementation could cause the Keep-Alive socket to close after each request. +- Added missing `rows_before_limit_at_least` to the ResponseJSON type ([@0237h](https://github.com/0237h), [#267](https://github.com/ClickHouse/clickhouse-js/issues/267)). # 1.0.1 (Common, Node.js, Web) diff --git a/packages/client-common/__tests__/integration/select_result.test.ts b/packages/client-common/__tests__/integration/select_result.test.ts index 2bc28a13..636980fa 100644 --- a/packages/client-common/__tests__/integration/select_result.test.ts +++ b/packages/client-common/__tests__/integration/select_result.test.ts @@ -1,4 +1,4 @@ -import type { ClickHouseClient, ResponseJSON } from '@clickhouse/client-common' +import type { ClickHouseClient } from '@clickhouse/client-common' import { createTestClient } from '../utils' describe('Select ResultSet', () => { @@ -10,7 +10,7 @@ describe('Select ResultSet', () => { client = createTestClient() }) - describe('text()', function () { + describe('text() method', function () { it('returns values from SELECT query in specified format', async () => { const rs = await client.query({ query: 'SELECT number FROM system.numbers LIMIT 3', @@ -19,6 +19,7 @@ describe('Select ResultSet', () => { expect(await rs.text()).toBe('0\n1\n2\n') }) + it('returns values from SELECT query in specified format', async () => { const rs = await client.query({ query: 'SELECT number FROM system.numbers LIMIT 3', @@ -31,63 +32,27 @@ describe('Select ResultSet', () => { }) }) - describe('json()', () => { - it('returns an array of values in data property', async () => { - const rs = await client.query({ - query: 'SELECT number FROM system.numbers LIMIT 5', - format: 'JSON', - }) - - const { data: nums } = await rs.json<{ number: string }>() - expect(Array.isArray(nums)).toBe(true) - expect(nums.length).toEqual(5) - const values = nums.map((i) => i.number) - expect(values).toEqual(['0', '1', '2', '3', '4']) - }) + describe('json() method', () => { + type Data = { number: string } - it('returns columns data in response', async () => { + it('should have correct fields in the response for JSON format', async () => { const rs = await client.query({ - query: 'SELECT number FROM system.numbers LIMIT 5', - format: 'JSON', - }) - - const { meta } = await rs.json<{ number: string }>() - - expect(meta?.length).toBe(1) - const column = meta ? meta[0] : undefined - expect(column).toEqual({ - name: 'number', - type: 'UInt64', - }) - }) - - it('returns number of rows in response', async () => { - const rs = await client.query({ - query: 'SELECT number FROM system.numbers LIMIT 5', + query: 'SELECT number FROM system.numbers LIMIT 3', format: 'JSON', }) - - const response = await rs.json>() - - expect(response.rows).toBe(5) - }) - - it('returns statistics in response', async () => { - const rs = await client.query({ - query: 'SELECT number FROM system.numbers LIMIT 5', - format: 'JSON', + const responseJSON = await rs.json() + expect(Array.isArray(responseJSON.data)).toBe(true) + expect(responseJSON).toEqual({ + data: [{ number: '0' }, { number: '1' }, { number: '2' }], + meta: [{ name: 'number', type: 'UInt64' }], + rows: 3, + rows_before_limit_at_least: 3, + statistics: { + elapsed: jasmine.any(Number), + rows_read: jasmine.any(Number), + bytes_read: jasmine.any(Number), + }, }) - - const response = await rs.json>() - expect(response).toEqual( - jasmine.objectContaining({ - statistics: { - elapsed: jasmine.any(Number), - rows_read: jasmine.any(Number), - bytes_read: jasmine.any(Number), - }, - }), - ) }) }) })