-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(decorator-validation): add more tests
Signed-off-by: Dan Selman <[email protected]>
- Loading branch information
Showing
7 changed files
with
86 additions
and
29 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
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
6 changes: 6 additions & 0 deletions
6
packages/concerto-core/test/data/decoratorcommands/validated.cto
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,6 @@ | ||
namespace [email protected] | ||
|
||
concept Person { | ||
o String firstName | ||
o String lastName | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/concerto-core/test/data/decoratorcommands/validated.json
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,37 @@ | ||
{ | ||
"$class" : "[email protected]", | ||
"name" : "validated", | ||
"version": "1.0.0", | ||
"commands" : [ | ||
{ | ||
"$class" : "[email protected]", | ||
"type" : "UPSERT", | ||
"target" : { | ||
"$class" : "[email protected]", | ||
"type" : "[email protected]" | ||
}, | ||
"decorator" : { | ||
"$class" : "[email protected]", | ||
"name" : "Form", | ||
"arguments" : [ | ||
{ | ||
"$class" : "[email protected]", | ||
"value" : "inputType" | ||
}, | ||
{ | ||
"$class" : "[email protected]", | ||
"value" : "text" | ||
}, | ||
{ | ||
"$class" : "[email protected]", | ||
"type" : { | ||
"$class" : "[email protected]", | ||
"name" : "HR", | ||
"namespace" : "[email protected]" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
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 |
---|---|---|
|
@@ -160,40 +160,43 @@ describe('DecoratorManager', () => { | |
// create a model manager with decorator validation ON | ||
const testModelManager = new ModelManager({strict:true, decoratorValidation: {missingDecorator: 'error', invalidDecorator: 'error'} }); | ||
|
||
// add a model that defines types that are *referenced* by decorators | ||
// declared in the decorator command set web.json | ||
testModelManager.addCTOModel(`namespace [email protected] | ||
abstract concept Category {} | ||
concept HR extends Category {} | ||
`, 'categories.cto'); | ||
|
||
// add the model that declares the decorators we can use | ||
// in the model and in decorator command sets | ||
testModelManager.addCTOModel(`namespace [email protected] | ||
import [email protected] | ||
concept PII extends Decorator {} | ||
concept Form extends Decorator { | ||
o String key | ||
o String value | ||
o Concept category | ||
} | ||
concept New extends Decorator {} | ||
concept UnversionedNamespace extends Decorator {} | ||
concept Address extends Decorator {} | ||
concept IsValid extends Decorator {} | ||
`, 'decorators.cto'); | ||
|
||
// add the domain model | ||
const modelText = fs.readFileSync(path.join(__dirname,'/data/decoratorcommands/test.cto'), 'utf-8'); | ||
testModelManager.addCTOModel(modelText, 'test.cto'); | ||
const modelText = fs.readFileSync(path.join(__dirname,'/data/decoratorcommands/validated.cto'), 'utf-8'); | ||
testModelManager.addCTOModel(modelText, 'validated.cto'); | ||
|
||
const cat = testModelManager.getType('[email protected]'); | ||
cat.should.not.be.null; | ||
|
||
// load the decorator command set | ||
const dcs = fs.readFileSync(path.join(__dirname,'/data/decoratorcommands/web.json'), 'utf-8'); | ||
const dcs = fs.readFileSync(path.join(__dirname,'/data/decoratorcommands/validated.json'), 'utf-8'); | ||
|
||
// decorator the models, using the default namespace [email protected] for decorator | ||
// commands that do not supply an explicit namespaces for their decorators | ||
const decoratedModelManager = DecoratorManager.decorateModels( testModelManager, JSON.parse(dcs), | ||
{validate: true, validateCommands: true, migrate: true, defaultNamespace: '[email protected]'}); | ||
|
||
const ssnDecl = decoratedModelManager.getType('[email protected]'); | ||
ssnDecl.should.not.be.null; | ||
ssnDecl.getDecorator('PII').should.not.be.null; | ||
|
||
const decl = decoratedModelManager.getType('[email protected]'); | ||
decl.should.not.be.null; | ||
decl.getDecorator('Editable').should.not.be.null; | ||
const personDecl = decoratedModelManager.getType('[email protected]'); | ||
personDecl.should.not.be.null; | ||
personDecl.getProperty('firstName').getDecorator('Form').should.not.be.null; | ||
}); | ||
|
||
/* | ||
|
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
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