Skip to content

Commit 12cbc1b

Browse files
Eprince-hubporsager
authored andcommitted
Add json and jsonb primitve test
1 parent 015f7b0 commit 12cbc1b

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

tests/index.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -611,13 +611,36 @@ t('Transform nested json in arrays', async() => {
611611
return ['aBcD', (await sql`select '[{"a_b":1},{"c_d":2}]'::jsonb as x`)[0].x.map(Object.keys).join('')]
612612
})
613613

614-
t('Bypass transform for json primitive', async() => {
614+
t('Bypass transform for json primitive', async () => {
615615
const sql = postgres({
616616
...options,
617-
transform: postgres.camel
618-
})
619-
return [null, false, 'a', '1', (await sql`select '${ null }'::jsonb as x, '${ false }'::jsonb as x, '${ "a" }'::json as x, '${ 1 }'::json as x`)[0].x]
620-
})
617+
transform: postgres.camel,
618+
});
619+
620+
const x = (
621+
await sql`select 'null'::json as a, 'false'::json as b, '"a"'::json as c, '1'::json as d`
622+
)[0];
623+
624+
return [
625+
JSON.stringify({ a: null, b: false, c: { 0: 'a' }, d: {} }),
626+
JSON.stringify(x),
627+
];
628+
});
629+
630+
t('Bypass transform for jsonb primitive', async () => {
631+
const sql = postgres({
632+
...options,
633+
transform: postgres.camel,
634+
});
635+
const x = (
636+
await sql`select 'null'::jsonb as a, 'false'::jsonb as b, '"a"'::jsonb as c, '1'::jsonb as d`
637+
)[0];
638+
639+
return [
640+
JSON.stringify({ a: null, b: false, c: { 0: 'a' }, d: {} }),
641+
JSON.stringify(x),
642+
];
643+
});
621644

622645
t('unsafe', async() => {
623646
await sql`create table test (x int)`

0 commit comments

Comments
 (0)