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 schema definition 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([])).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 an object', function () { const throwable = v => () => validateProjectionSchemaDefinition({name: 'mySchema', schema: v}); const error = s => format( 'Definition option "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')); expect(throwable(() => ({}))).to.throw(error('Function')); throwable({})(); }); });