|
@@ -3,7 +3,7 @@ import {format} from '@e22m4u/js-format';
|
|
|
import {validateProjectionSchema} from './validate-projection-schema.js';
|
|
import {validateProjectionSchema} from './validate-projection-schema.js';
|
|
|
|
|
|
|
|
describe('validateProjectionSchema', function () {
|
|
describe('validateProjectionSchema', function () {
|
|
|
- it('should require an object', function () {
|
|
|
|
|
|
|
+ it('should require the schema argument to be a object', function () {
|
|
|
const throwable = v => () => validateProjectionSchema(v);
|
|
const throwable = v => () => validateProjectionSchema(v);
|
|
|
const error = s =>
|
|
const error = s =>
|
|
|
format('Projection schema must be an Object, but %s was given.', s);
|
|
format('Projection schema must be an Object, but %s was given.', s);
|
|
@@ -19,6 +19,22 @@ describe('validateProjectionSchema', function () {
|
|
|
throwable({})();
|
|
throwable({})();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ it('should require the shallowMode parameter to be a boolean', function () {
|
|
|
|
|
+ const throwable = v => () => validateProjectionSchema({}, v);
|
|
|
|
|
+ const error = s =>
|
|
|
|
|
+ format('Parameter "shallowMode" must be a Boolean, but %s was given.', s);
|
|
|
|
|
+ expect(throwable('str')).to.throw(error('"str"'));
|
|
|
|
|
+ expect(throwable('')).to.throw(error('""'));
|
|
|
|
|
+ expect(throwable(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(throwable(0)).to.throw(error('0'));
|
|
|
|
|
+ expect(throwable([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(throwable({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(throwable(null)).to.throw(error('null'));
|
|
|
|
|
+ throwable(true)();
|
|
|
|
|
+ throwable(false)();
|
|
|
|
|
+ throwable(undefined)();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
it('should require schema properties to be a boolean or an object', function () {
|
|
it('should require schema properties to be a boolean or an object', function () {
|
|
|
const throwable = v => () => validateProjectionSchema({foo: v});
|
|
const throwable = v => () => validateProjectionSchema({foo: v});
|
|
|
const error = s =>
|
|
const error = s =>
|
|
@@ -158,4 +174,17 @@ describe('validateProjectionSchema', function () {
|
|
|
validateProjectionSchema({foo: {schema: 'mySchema'}});
|
|
validateProjectionSchema({foo: {schema: 'mySchema'}});
|
|
|
validateProjectionSchema({foo: {schema: {bar: {schema: 'mySchema'}}}});
|
|
validateProjectionSchema({foo: {schema: {bar: {schema: 'mySchema'}}}});
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ it('should validate root schema in shallow mode', function () {
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ const throwable = () => validateProjectionSchema({foo: 10}, true);
|
|
|
|
|
+ expect(throwable).to.throw(
|
|
|
|
|
+ 'Property options must be a Boolean or an Object, but 10 was given.',
|
|
|
|
|
+ );
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('should skip nested schema checking in shallow mode', function () {
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ validateProjectionSchema({foo: {schema: {prop: 10}}}, true);
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|