Skip to content

Commit 14c00d9

Browse files
committed
Add tests for long inside objects/arrays
1 parent 6296e6d commit 14c00d9

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/long.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,45 @@ test(`render a long as JSON`, (t) => {
2020
t.equal(output, '18446744073709551615')
2121
t.ok(validate(JSON.parse(output)), 'valid schema')
2222
})
23+
24+
test(`render an object with long as JSON`, (t) => {
25+
t.plan(2)
26+
27+
const schema = {
28+
title: 'object with long',
29+
type: 'object',
30+
properties: {
31+
id: {
32+
type: 'integer'
33+
}
34+
}
35+
}
36+
37+
const validate = validator(schema)
38+
const stringify = build(schema)
39+
const output = stringify({
40+
id: Long.fromString('18446744073709551615', true)
41+
})
42+
43+
t.equal(output, '{"id":18446744073709551615}')
44+
t.ok(validate(JSON.parse(output)), 'valid schema')
45+
})
46+
47+
test(`render aan array with long as JSON`, (t) => {
48+
t.plan(2)
49+
50+
const schema = {
51+
title: 'array with long',
52+
type: 'array',
53+
items: {
54+
type: 'integer'
55+
}
56+
}
57+
58+
const validate = validator(schema)
59+
const stringify = build(schema)
60+
const output = stringify([Long.fromString('18446744073709551615', true)])
61+
62+
t.equal(output, '[18446744073709551615]')
63+
t.ok(validate(JSON.parse(output)), 'valid schema')
64+
})

0 commit comments

Comments
 (0)