-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for metaschema context support
- Loading branch information
1 parent
0ed4347
commit 5710c76
Showing
13 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
({ | ||
Nomen: { domain: 'Nomen' }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
({ | ||
Nomen: { type: 'string' }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
({ | ||
Nomen: { domain: 'Nomen' }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
({ | ||
Nomen: { domain: 'Nomen' }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
({ | ||
MissingProp: {}, | ||
UnresolvedProp: { category: '__SOME_CATEGORY__' }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
({ | ||
[Symbol.for('additionallyAllowedProperties')]: ['field'], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
({ | ||
type: { domain: 'type' }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
({ | ||
[Symbol.for('additionallyAllowedProperties')]: ['domain'], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
({ | ||
domain: { domain: 'string', required: true }, | ||
required: { domain: 'boolean' }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
({ | ||
string: { type: 'string' }, | ||
boolean: { type: 'boolean' }, | ||
type: Enum( | ||
'string', | ||
'boolean', | ||
), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
({ | ||
Nomen: { domain: 'Nomen', required: true }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
({ | ||
Nomen: { type: 'string' }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use strict'; | ||
|
||
const metaschema = require('metaschema'); | ||
const metatests = require('metatests'); | ||
|
||
const { default: defaultConfig } = metaschema; | ||
const { options, config } = require('../lib/metaschema-config/config'); | ||
|
||
const { | ||
MetaschemaError, | ||
ValidationError, | ||
SchemaValidationError, | ||
} = metaschema.errors; | ||
|
||
metatests.test('metaschema context error on duplicated domains', async test => { | ||
await test.rejects( | ||
metaschema.fs.load('test/fixtures/context/duplicate', options, config), | ||
new MetaschemaError([ | ||
new SchemaValidationError('duplicate', 'duplicateDomain', { | ||
type: 'domain', | ||
value: 'Nomen', | ||
}), | ||
]) | ||
); | ||
}); | ||
|
||
metatests.test('metaschema context error on unresolved domain', async test => { | ||
await test.rejects( | ||
metaschema.fs.load('test/fixtures/context/unresolved', options, config), | ||
new MetaschemaError([ | ||
new SchemaValidationError('unresolved', 'context.Nomen', { | ||
type: 'domain', | ||
value: 'Nomen', | ||
}), | ||
]) | ||
); | ||
}); | ||
|
||
metatests.test('metaschema context validation', async test => { | ||
const schemaConfig = await metaschema.fs.applySystemConfig( | ||
'test/fixtures/context/validation/system', | ||
defaultConfig, | ||
{ options, config } | ||
); | ||
|
||
await test.resolves(async () => { | ||
await metaschema.fs.load( | ||
'test/fixtures/context/validation/valid', | ||
schemaConfig.options, | ||
schemaConfig.config | ||
); | ||
}); | ||
|
||
await test.rejects( | ||
metaschema.fs.load( | ||
'test/fixtures/context/validation/invalid', | ||
schemaConfig.options, | ||
schemaConfig.config | ||
), | ||
new MetaschemaError([ | ||
new ValidationError('notAllowedAdditionalProp', 'context.MissingProp', { | ||
allowed: ['field'], | ||
}), | ||
new ValidationError( | ||
'notAllowedAdditionalProp', | ||
'context.UnresolvedProp', | ||
{ | ||
allowed: ['field'], | ||
} | ||
), | ||
]) | ||
); | ||
}); |