Skip to content

Commit 758911d

Browse files
Eprince-hubporsager
authored andcommitted
Add json and jsonb primitve test
1 parent fa66c5e commit 758911d

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
@@ -612,13 +612,36 @@ t('Transform nested json in arrays', async() => {
612612
return ['aBcD', (await sql`select '[{"a_b":1},{"c_d":2}]'::jsonb as x`)[0].x.map(Object.keys).join('')]
613613
})
614614

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

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

0 commit comments

Comments
 (0)