Skip to content

Commit

Permalink
feat: [#631] testCLI.ts added tests for refOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbert Dopjera committed Sep 11, 2024
1 parent 116708b commit 984bb9c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/resources/refOptions/common.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$schema: https://json-schema.org/draft/2020-12
$id: test/resources/refOptions/common.yml
type: object
properties:
id:
type: integer
description: The unique identifier of the object
name:
type: string
description: The name of the object
required:
- id
14 changes: 14 additions & 0 deletions test/resources/refOptions/specific/caseA.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$schema: https://json-schema.org/draft/2020-12
$id: test/resources/refOptions/specific/caseA.yml
type: object
allOf:
- $ref: test/resources/refOptions/common.yml
- properties:
module:
type: string
const: caseA
is_old:
type: boolean
description: The age of the object
required:
- module
14 changes: 14 additions & 0 deletions test/resources/refOptions/specific/caseB.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$schema: https://json-schema.org/draft/2020-12
$id: test/resources/refOptions/specific/caseB.yml
type: object
allOf:
- $ref: test/resources/refOptions/common.yml
- properties:
module:
type: string
const: caseB
age:
type:
description: The age of the object
required:
- module
6 changes: 6 additions & 0 deletions test/resources/refOptions/specific/specific.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$schema: https://json-schema.org/draft/2020-12
$id: test/resources/refOptions/specific/specific.yml
type: object
anyOf:
- $ref: test/resources/refOptions/specific/caseA.yml
- $ref: test/resources/refOptions/specific/caseB.yml
24 changes: 24 additions & 0 deletions test/testCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,30 @@ export function run() {
})
rimraf.sync('./test/resources/MultiSchema2/out')
})

test('--refOptions - JSON string error', t => {
t.throws(() => execSync('node dist/src/cli.js --refOptions "{invalid}" --input ./test/resources/refOptions'))
})

test('--refOptions - refrenced base URI, default externalReferenceResolution', t => {
t.throws(() => execSync('node dist/src/cli.js --input ./test/resources/refOptions'))
})

test('--refOptions - refrenced base URI, unknown externalReferenceResolution', t => {
t.throws(() =>
execSync(
'node dist/src/cli.js --refOptions "{\\"dereference\\": {\\"externalReferenceResolution\\": \\"...\\"}}" --input ./test/resources/refOptions',
),
)
})

test('--refOptions - refrenced base URI, root externalReferenceResolution', t => {
t.notThrows(() =>
execSync(
'node dist/src/cli.js --refOptions "{\\"dereference\\": {\\"externalReferenceResolution\\": \\"root\\"}}" --input ./test/resources/refOptions',
),
)
})
}

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

0 comments on commit 984bb9c

Please sign in to comment.