Skip to content

Commit 3998190

Browse files
committed
add two test for allOf
1 parent 6a2c90d commit 3998190

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

test/allof.test.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
const test = require('tap').test
44
const build = require('..')
55

6-
test('object with multiple types field', (t) => {
6+
test('object with allOf and multiple schema on the allOf', (t) => {
77
t.plan(2)
88

99
const schema = {
10-
title: 'object with multiple types field',
10+
title: 'object with allOf and multiple schema on the allOf',
1111
type: 'object',
1212
allOf: [
1313
{
@@ -60,3 +60,52 @@ test('object with multiple types field', (t) => {
6060
t.fail()
6161
}
6262
})
63+
64+
test('object with allOf and one schema on the allOf', (t) => {
65+
t.plan(1)
66+
67+
const schema = {
68+
title: 'object with allOf and one schema on the allOf',
69+
type: 'object',
70+
allOf: [
71+
{
72+
required: [
73+
'id'
74+
],
75+
type: 'object',
76+
properties: {
77+
id: {
78+
type: 'integer'
79+
}
80+
}
81+
}
82+
]
83+
}
84+
const stringify = build(schema)
85+
86+
try {
87+
const value = stringify({
88+
id: 1
89+
})
90+
t.is(value, '{"id":1}')
91+
} catch (e) {
92+
t.fail()
93+
}
94+
})
95+
96+
test('object with allOf and no schema on the allOf', (t) => {
97+
t.plan(1)
98+
99+
const schema = {
100+
title: 'object with allOf and no schema on the allOf',
101+
type: 'object',
102+
allOf: []
103+
}
104+
105+
try {
106+
build(schema)
107+
t.fail()
108+
} catch (e) {
109+
t.is(e.message, 'schema is invalid: data.allOf should NOT have less than 1 items')
110+
}
111+
})

0 commit comments

Comments
 (0)