Skip to content

Commit

Permalink
Update CHANGELOG and the JSON result tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slvrtrn committed May 17, 2024
1 parent cd19c8b commit 21a828c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 55 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
73 changes: 19 additions & 54 deletions packages/client-common/__tests__/integration/select_result.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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<ResponseJSON<{ number: string }>>()

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<Data>()
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<ResponseJSON<{ number: string }>>()
expect(response).toEqual(
jasmine.objectContaining({
statistics: {
elapsed: jasmine.any(Number),
rows_read: jasmine.any(Number),
bytes_read: jasmine.any(Number),
},
}),
)
})
})
})

0 comments on commit 21a828c

Please sign in to comment.