| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import {expect} from 'chai';
- import {format} from '@e22m4u/js-format';
- import {validateProjectionSchemaDefinition} from './validate-projection-schema-definition.js';
- describe('validateProjectionSchemaDefinition', function () {
- it('should require the first argument to be an object', function () {
- const throwable = v => () => validateProjectionSchemaDefinition(v);
- const error = s =>
- format(
- 'Projection schema definition must be an Object, 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(true)).to.throw(error('true'));
- expect(throwable(false)).to.throw(error('false'));
- expect(throwable([])).to.throw(error('Array'));
- expect(throwable(null)).to.throw(error('null'));
- expect(throwable(undefined)).to.throw(error('undefined'));
- throwable({name: 'mySchema', schema: {}})();
- });
- it('should require the "name" option to be a string', function () {
- const throwable = v => () =>
- validateProjectionSchemaDefinition({name: v, schema: {}});
- const error = s =>
- format(
- 'Projection schema name must be a non-empty String, but %s was given.',
- s,
- );
- 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'));
- expect(throwable(undefined)).to.throw(error('undefined'));
- throwable('mySchema')();
- });
- it('should require the "schema" option to be an object', function () {
- const throwable = v => () =>
- validateProjectionSchemaDefinition({name: 'mySchema', schema: v});
- const error = s =>
- format('Projection schema must be an Object, 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(null)).to.throw(error('null'));
- expect(throwable(undefined)).to.throw(error('undefined'));
- throwable({})();
- });
- it('should validate the projection schema', function () {
- const throwable = () =>
- validateProjectionSchemaDefinition({name: 'mySchema', schema: {foo: 10}});
- expect(throwable).to.throw(
- 'Field options must be a Boolean or an Object, but 10 was given.',
- );
- });
- });
|