-
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 #238 from Kashoo/issue-237-release-2.0.1
Issue 237: Release of 2.0.1
- Loading branch information
Showing
11 changed files
with
121 additions
and
20 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,66 @@ | ||
const testHelper = require('../src/testing/test-helper.js'); | ||
|
||
describe('Custom validation constraint:', () => { | ||
beforeEach(() => { | ||
testHelper.initSyncFunction('build/sync-functions/test-custom-validation-sync-function.js'); | ||
}); | ||
|
||
it('allows a document if custom validation succeeds', () => { | ||
const doc = { | ||
_id: 'my-doc', | ||
type: 'customValidationDoc', | ||
baseProp: { | ||
failValidation: false, | ||
customValidationProp: 'foo' | ||
} | ||
}; | ||
|
||
testHelper.verifyDocumentCreated(doc); | ||
}); | ||
|
||
it('blocks a document if custom validation fails', () => { | ||
const oldDoc = { | ||
_id: 'my-doc', | ||
type: 'customValidationDoc', | ||
baseProp: { } | ||
}; | ||
|
||
const doc = { | ||
_id: 'my-doc', | ||
type: 'customValidationDoc', | ||
baseProp: { | ||
failValidation: true, | ||
customValidationProp: 'foo' | ||
} | ||
}; | ||
|
||
const expectedCurrentItemEntry = { | ||
itemValue: doc.baseProp.customValidationProp, | ||
oldItemValue: null, | ||
itemName: 'customValidationProp' | ||
}; | ||
const expectedValidationItemStack = [ | ||
{ // The document (root) | ||
itemValue: doc, | ||
oldItemValue: oldDoc, | ||
itemName: null | ||
}, | ||
{ // The parent of the property with the customValidation constraint | ||
itemValue: doc.baseProp, | ||
oldItemValue: oldDoc.baseProp, | ||
itemName: 'baseProp' | ||
} | ||
]; | ||
|
||
testHelper.verifyDocumentNotReplaced( | ||
doc, | ||
oldDoc, | ||
'customValidationDoc', | ||
[ | ||
'doc: ' + JSON.stringify(doc), | ||
'oldDoc: ' + JSON.stringify(oldDoc), | ||
'currentItemEntry: ' + JSON.stringify(expectedCurrentItemEntry), | ||
'validationItemStack: ' + JSON.stringify(expectedValidationItemStack) | ||
]); | ||
}); | ||
}); |
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,34 @@ | ||
function() { | ||
return { | ||
customValidationDoc: { | ||
typeFilter: simpleTypeFilter, | ||
channels: { write: 'write' }, | ||
propertyValidators: { | ||
baseProp: { | ||
type: 'object', | ||
propertyValidators: { | ||
failValidation: { | ||
type: 'boolean' | ||
}, | ||
customValidationProp: { | ||
type: 'string', | ||
customValidation: function(doc, oldDoc, currentItemEntry, validationItemStack) { | ||
var parentItemValue = validationItemStack[validationItemStack.length - 1].itemValue; | ||
if (parentItemValue && parentItemValue.failValidation) { | ||
return [ | ||
'doc: ' + jsonStringify(doc), | ||
'oldDoc: ' + jsonStringify(oldDoc), | ||
'currentItemEntry: ' + jsonStringify(currentItemEntry), | ||
'validationItemStack: ' + jsonStringify(validationItemStack) | ||
]; | ||
} else { | ||
return [ ]; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} |
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