-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from Kashoo/issue-72-type-id-validator
Issue 72: Type identifier property validator
- Loading branch information
Showing
5 changed files
with
105 additions
and
25 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
typeIdDoc: { | ||
channels: { | ||
write: [ 'write' ] | ||
}, | ||
typeFilter: function(doc) { | ||
return doc._id === 'typeIdDoc'; | ||
}, | ||
propertyValidators: { | ||
typeIdProp: typeIdValidator | ||
} | ||
} | ||
} |
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,58 @@ | ||
var expect = require('expect.js'); | ||
var testHelper = require('../etc/test-helper.js'); | ||
var errorFormatter = testHelper.validationErrorFormatter; | ||
|
||
describe('Type identifier validator', function() { | ||
beforeEach(function() { | ||
testHelper.init('build/sync-functions/test-type-id-validator-sync-function.js'); | ||
}); | ||
|
||
it('allows a valid string value', function() { | ||
var doc = { | ||
_id: 'typeIdDoc', | ||
typeIdProp: 'my-doc-type' | ||
}; | ||
|
||
testHelper.verifyDocumentCreated(doc); | ||
}); | ||
|
||
it('rejects a non-string value', function() { | ||
var doc = { | ||
_id: 'typeIdDoc', | ||
typeIdProp: 15 | ||
}; | ||
|
||
testHelper.verifyDocumentNotCreated(doc, 'typeIdDoc', [ errorFormatter.typeConstraintViolation('typeIdProp', 'string') ]); | ||
}); | ||
|
||
it('rejects an empty string value', function() { | ||
var doc = { | ||
_id: 'typeIdDoc', | ||
typeIdProp: '' | ||
}; | ||
|
||
testHelper.verifyDocumentNotCreated(doc, 'typeIdDoc', [ errorFormatter.mustNotBeEmptyViolation('typeIdProp') ]); | ||
}); | ||
|
||
it('rejects a null value', function() { | ||
var doc = { | ||
_id: 'typeIdDoc', | ||
typeIdProp: null | ||
}; | ||
|
||
testHelper.verifyDocumentNotCreated(doc, 'typeIdDoc', [ errorFormatter.requiredValueViolation('typeIdProp') ]); | ||
}); | ||
|
||
it('rejects a value that has been modified', function() { | ||
var doc = { | ||
_id: 'typeIdDoc', | ||
typeIdProp: 'my-modified-doc-type' | ||
}; | ||
var oldDoc = { | ||
_id: 'typeIdDoc', | ||
typeIdProp: 'my-doc-type' | ||
}; | ||
|
||
testHelper.verifyDocumentNotReplaced(doc, oldDoc, 'typeIdDoc', [ errorFormatter.immutableItemViolation('typeIdProp') ]); | ||
}); | ||
}); |