| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 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 "schemaDef" argument to be an object', function () {
- const throwable = v => () => validateProjectionSchemaDefinition(v);
- const error = s =>
- format('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(undefined)).to.throw(error('undefined'));
- expect(throwable(null)).to.throw(error('null'));
- expect(throwable(() => undefined)).to.throw(error('Function'));
- throwable({name: 'mySchema', schema: {}})();
- });
- it('should require the "name" option to be a non-empty string', function () {
- const throwable = v => () =>
- validateProjectionSchemaDefinition({name: v, schema: {}});
- const error = s =>
- format(
- 'Definition option "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(true)).to.throw(error('true'));
- expect(throwable(false)).to.throw(error('false'));
- 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'));
- expect(throwable(() => ({}))).to.throw(error('Function'));
- throwable('str')();
- });
- it('should require the "schema" option to be a valid value', function () {
- const throwable = v => () =>
- validateProjectionSchemaDefinition({name: 'mySchema', schema: v});
- const error = s =>
- format(
- 'Definition option "schema" must be an Object, a Function ' +
- 'or 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(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('str')();
- throwable({})();
- throwable(() => ({}))();
- });
- });
|