Skip to content

Commit 984bb9c

Browse files
author
Norbert Dopjera
committed
feat: [#631] testCLI.ts added tests for refOptions
1 parent 116708b commit 984bb9c

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

test/resources/refOptions/common.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
$schema: https://json-schema.org/draft/2020-12
2+
$id: test/resources/refOptions/common.yml
3+
type: object
4+
properties:
5+
id:
6+
type: integer
7+
description: The unique identifier of the object
8+
name:
9+
type: string
10+
description: The name of the object
11+
required:
12+
- id
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
$schema: https://json-schema.org/draft/2020-12
2+
$id: test/resources/refOptions/specific/caseA.yml
3+
type: object
4+
allOf:
5+
- $ref: test/resources/refOptions/common.yml
6+
- properties:
7+
module:
8+
type: string
9+
const: caseA
10+
is_old:
11+
type: boolean
12+
description: The age of the object
13+
required:
14+
- module
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
$schema: https://json-schema.org/draft/2020-12
2+
$id: test/resources/refOptions/specific/caseB.yml
3+
type: object
4+
allOf:
5+
- $ref: test/resources/refOptions/common.yml
6+
- properties:
7+
module:
8+
type: string
9+
const: caseB
10+
age:
11+
type:
12+
description: The age of the object
13+
required:
14+
- module
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
$schema: https://json-schema.org/draft/2020-12
2+
$id: test/resources/refOptions/specific/specific.yml
3+
type: object
4+
anyOf:
5+
- $ref: test/resources/refOptions/specific/caseA.yml
6+
- $ref: test/resources/refOptions/specific/caseB.yml

test/testCLI.ts

+24
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,30 @@ export function run() {
137137
})
138138
rimraf.sync('./test/resources/MultiSchema2/out')
139139
})
140+
141+
test('--refOptions - JSON string error', t => {
142+
t.throws(() => execSync('node dist/src/cli.js --refOptions "{invalid}" --input ./test/resources/refOptions'))
143+
})
144+
145+
test('--refOptions - refrenced base URI, default externalReferenceResolution', t => {
146+
t.throws(() => execSync('node dist/src/cli.js --input ./test/resources/refOptions'))
147+
})
148+
149+
test('--refOptions - refrenced base URI, unknown externalReferenceResolution', t => {
150+
t.throws(() =>
151+
execSync(
152+
'node dist/src/cli.js --refOptions "{\\"dereference\\": {\\"externalReferenceResolution\\": \\"...\\"}}" --input ./test/resources/refOptions',
153+
),
154+
)
155+
})
156+
157+
test('--refOptions - refrenced base URI, root externalReferenceResolution', t => {
158+
t.notThrows(() =>
159+
execSync(
160+
'node dist/src/cli.js --refOptions "{\\"dereference\\": {\\"externalReferenceResolution\\": \\"root\\"}}" --input ./test/resources/refOptions',
161+
),
162+
)
163+
})
140164
}
141165

142166
function getPaths(path: string, paths: string[] = []) {

0 commit comments

Comments
 (0)