-
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 #327 from Kashoo/324-any-type
Issue 324: Support for any JSON data type
- Loading branch information
Showing
7 changed files
with
189 additions
and
1 deletion.
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
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,142 @@ | ||
const testFixtureMaker = require('../src/testing/test-fixture-maker'); | ||
const errorFormatter = require('../src/testing/validation-error-formatter'); | ||
|
||
describe('Any validation type:', () => { | ||
const testFixture = testFixtureMaker.initFromSyncFunction('build/sync-functions/test-any-type-sync-function.js'); | ||
|
||
afterEach(() => { | ||
testFixture.resetTestEnvironment(); | ||
}); | ||
|
||
describe('for array elements', () => { | ||
it('allows string, number, boolean, array and object values in an array', () => { | ||
const doc = { | ||
_id: 'my-doc', | ||
type: 'anyTypeDoc', | ||
arrayProp: [ | ||
'a-string', | ||
-117.8, | ||
true, | ||
[ 'foo', 'bar' ], | ||
{ baz: 'qux' } | ||
] | ||
}; | ||
|
||
testFixture.verifyDocumentCreated(doc); | ||
}); | ||
|
||
it('respects universal constraints (e.g. "required")', () => { | ||
const doc = { | ||
_id: 'my-doc', | ||
type: 'anyTypeDoc', | ||
arrayProp: [ | ||
'', | ||
0, | ||
null | ||
] | ||
}; | ||
|
||
testFixture.verifyDocumentNotCreated(doc, 'anyTypeDoc', errorFormatter.requiredValueViolation('arrayProp[2]')); | ||
}); | ||
}); | ||
|
||
describe('for hashtable elements', () => { | ||
it('allows string, number, boolean, array and object values in a hashtable', () => { | ||
const doc = { | ||
_id: 'my-doc', | ||
type: 'anyTypeDoc', | ||
hashtableProp: { | ||
1: 'another-string', | ||
2: 13, | ||
3: false, | ||
4: [ 0, 1, 2 ], | ||
5: { } | ||
} | ||
}; | ||
|
||
testFixture.verifyDocumentCreated(doc); | ||
}); | ||
|
||
it('respects universal constraints (e.g. "immutableWhenSet")', () => { | ||
const oldDoc = { | ||
_id: 'my-doc', | ||
type: 'anyTypeDoc', | ||
hashtableProp: { | ||
1: 1.9, | ||
2: true, | ||
3: 'one-more-string', | ||
4: null // Can be changed since it doesn't have a value yet | ||
} | ||
}; | ||
|
||
const doc = { | ||
_id: 'my-doc', | ||
type: 'anyTypeDoc', | ||
hashtableProp: { | ||
1: 85, // Changed | ||
2: true, | ||
3: 'one-more-string', | ||
4: [ ] | ||
} | ||
}; | ||
|
||
testFixture.verifyDocumentNotReplaced( | ||
doc, | ||
oldDoc, | ||
'anyTypeDoc', | ||
errorFormatter.immutableItemViolation('hashtableProp[1]')); | ||
}); | ||
}); | ||
|
||
describe('for object properties', () => { | ||
it('allows a string value', () => { | ||
const doc = { | ||
_id: 'my-doc', | ||
type: 'anyTypeDoc', | ||
anyProp: 'a-string' | ||
}; | ||
|
||
testFixture.verifyDocumentCreated(doc); | ||
}); | ||
|
||
it('allows a numeric value', () => { | ||
const doc = { | ||
_id: 'my-doc', | ||
type: 'anyTypeDoc', | ||
anyProp: -115.8 | ||
}; | ||
|
||
testFixture.verifyDocumentCreated(doc); | ||
}); | ||
|
||
it('allows a boolean value', () => { | ||
const doc = { | ||
_id: 'my-doc', | ||
type: 'anyTypeDoc', | ||
anyProp: false | ||
}; | ||
|
||
testFixture.verifyDocumentCreated(doc); | ||
}); | ||
|
||
it('allows an array value', () => { | ||
const doc = { | ||
_id: 'my-doc', | ||
type: 'anyTypeDoc', | ||
anyProp: [ 'foo', 'bar' ] | ||
}; | ||
|
||
testFixture.verifyDocumentCreated(doc); | ||
}); | ||
|
||
it('allows an object value', () => { | ||
const doc = { | ||
_id: 'my-doc', | ||
type: 'anyTypeDoc', | ||
anyProp: { foo: 'bar' } | ||
}; | ||
|
||
testFixture.verifyDocumentCreated(doc); | ||
}); | ||
}); | ||
}); |
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,27 @@ | ||
function() { | ||
return { | ||
anyTypeDoc: { | ||
typeFilter: simpleTypeFilter, | ||
channels: { write: 'write' }, | ||
propertyValidators: { | ||
arrayProp: { | ||
type: 'array', | ||
arrayElementsValidator: { | ||
type: 'any', | ||
required: true | ||
} | ||
}, | ||
hashtableProp: { | ||
type: 'hashtable', | ||
hashtableValuesValidator: { | ||
type: 'any', | ||
immutableWhenSet: true | ||
} | ||
}, | ||
anyProp: { | ||
type: 'any' | ||
} | ||
} | ||
} | ||
}; | ||
} |