Skip to content

Commit 15e0e47

Browse files
authored
Additional integration tests for boolean params (#480)
1 parent 8e552d4 commit 15e0e47

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

packages/client-common/__tests__/integration/select_query_binding.test.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,4 +448,88 @@ describe('select with query binding', () => {
448448
expect(response).toBe('0\n1\n2\n')
449449
})
450450
})
451+
452+
describe('Nested boolean types', () => {
453+
it('handles boolean in an array', async () => {
454+
const params = {
455+
foo: [true, false, true],
456+
bar: [true, null, false],
457+
}
458+
const rs = await client.query({
459+
query: `
460+
SELECT {foo: Array(Boolean)} AS foo,
461+
{bar: Array(Nullable(Boolean))} AS bar
462+
`,
463+
format: 'JSONEachRow',
464+
query_params: params,
465+
})
466+
467+
const response = await rs.json()
468+
expect(response).toEqual([params])
469+
})
470+
471+
it('handles boolean in a tuple', async () => {
472+
const foo = [1, true, 'foo']
473+
const bar = [null, 42]
474+
const params = {
475+
foo: new TupleParam(foo),
476+
bar: new TupleParam(bar),
477+
}
478+
479+
const rs = await client.query({
480+
query: `
481+
SELECT {foo: Tuple(Int32, Boolean, String)} AS foo,
482+
{bar: Tuple(Nullable(Boolean), Int16)} AS bar
483+
`,
484+
format: 'JSONEachRow',
485+
query_params: params,
486+
})
487+
488+
const response = await rs.json()
489+
expect(response).toEqual([{ foo, bar }])
490+
})
491+
492+
it('handles boolean in a map', async () => {
493+
const foo = { item1: true, item2: false }
494+
const bar = { item1: null, item2: true }
495+
const params = {
496+
foo: new Map(Object.entries(foo)),
497+
bar: new Map(Object.entries(bar)),
498+
}
499+
500+
const rs = await client.query({
501+
query: `
502+
SELECT {foo: Map(String, Boolean)} AS foo,
503+
{bar: Map(String, Nullable(Boolean))} AS bar
504+
`,
505+
format: 'JSONEachRow',
506+
query_params: params,
507+
})
508+
509+
const response = await rs.json()
510+
expect(response).toEqual([{ foo, bar }])
511+
})
512+
513+
it('handles boolean in a mixed nested structure', async () => {
514+
const rs = await client.query({
515+
query: `
516+
SELECT {val: Array(Map(String, Tuple(Int32, Boolean)))} AS result
517+
`,
518+
format: 'JSONEachRow',
519+
query_params: {
520+
val: [
521+
{ item1: new TupleParam([1, true]) },
522+
{ item2: new TupleParam([2, false]) },
523+
],
524+
},
525+
})
526+
527+
const response = await rs.json()
528+
expect(response).toEqual([
529+
{
530+
result: [{ item1: [1, true] }, { item2: [2, false] }],
531+
},
532+
])
533+
})
534+
})
451535
})

0 commit comments

Comments
 (0)