/
json.js
44 lines (36 loc) · 770 Bytes
/
json.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// @flow
import test from 'ava';
import createSqlTag from '../../../../src/factories/createSqlTag';
import {
SqlToken,
} from '../../../../src/tokens';
const sql = createSqlTag();
test('creates a value list', (t) => {
const query = sql`SELECT ${sql.json({foo: 'bar'})}`;
t.deepEqual(query, {
sql: 'SELECT $1',
type: SqlToken,
values: [
'{"foo":"bar"}',
],
});
});
test('passes null unstringified', (t) => {
const query = sql`SELECT ${sql.json(null)}`;
t.deepEqual(query, {
sql: 'SELECT $1',
type: SqlToken,
values: [
null,
],
});
});
test('the resulting object is immutable', (t) => {
const token = sql.json({
foo: 'bar',
});
t.throws(() => {
// $FlowFixMe
token.foo = 'bar';
});
});