|
@@ -3,7 +3,7 @@ import {format} from '@e22m4u/js-format';
|
|
|
import {projectData} from './project-data.js';
|
|
import {projectData} from './project-data.js';
|
|
|
|
|
|
|
|
describe('projectData', function () {
|
|
describe('projectData', function () {
|
|
|
- it('should require the options argument to be an object', function () {
|
|
|
|
|
|
|
+ it('should require the "options" argument to be an object', function () {
|
|
|
const throwable = v => () => projectData({}, 10, v);
|
|
const throwable = v => () => projectData({}, 10, v);
|
|
|
const error = s =>
|
|
const error = s =>
|
|
|
format('Projection options must be an Object, but %s was given.', s);
|
|
format('Projection options must be an Object, but %s was given.', s);
|
|
@@ -19,7 +19,7 @@ describe('projectData', function () {
|
|
|
throwable(undefined)();
|
|
throwable(undefined)();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('should require the strict option to be a boolean', function () {
|
|
|
|
|
|
|
+ it('should require the "strict" option to be a boolean', function () {
|
|
|
const throwable = v => () => projectData({}, 10, {strict: v});
|
|
const throwable = v => () => projectData({}, 10, {strict: v});
|
|
|
const error = s =>
|
|
const error = s =>
|
|
|
format(
|
|
format(
|
|
@@ -38,7 +38,7 @@ describe('projectData', function () {
|
|
|
throwable(undefined)();
|
|
throwable(undefined)();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('should require the scope option to be a non-empty string', function () {
|
|
|
|
|
|
|
+ it('should require the "scope" option to be a non-empty string', function () {
|
|
|
const throwable = v => () => projectData({}, 10, {scope: v});
|
|
const throwable = v => () => projectData({}, 10, {scope: v});
|
|
|
const error = s =>
|
|
const error = s =>
|
|
|
format(
|
|
format(
|
|
@@ -58,7 +58,7 @@ describe('projectData', function () {
|
|
|
throwable(undefined)();
|
|
throwable(undefined)();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('should require the resolver option to be a function', function () {
|
|
|
|
|
|
|
+ it('should require the "resolver" option to be a function', function () {
|
|
|
const throwable = v => () => projectData({}, 10, {resolver: v});
|
|
const throwable = v => () => projectData({}, 10, {resolver: v});
|
|
|
const error = s =>
|
|
const error = s =>
|
|
|
format(
|
|
format(
|
|
@@ -78,7 +78,26 @@ describe('projectData', function () {
|
|
|
throwable(undefined)();
|
|
throwable(undefined)();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('should project with the schema factory', function () {
|
|
|
|
|
|
|
+ it('should require the "factoryArgs" option to be an Array', function () {
|
|
|
|
|
+ const throwable = v => () => projectData({}, 10, {factoryArgs: v});
|
|
|
|
|
+ const error = s =>
|
|
|
|
|
+ format(
|
|
|
|
|
+ 'Projection option "factoryArgs" must be an Array, 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('Object'));
|
|
|
|
|
+ expect(throwable(null)).to.throw(error('null'));
|
|
|
|
|
+ throwable([1])();
|
|
|
|
|
+ throwable([])();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('should resolve a factory value as the schema object', function () {
|
|
|
let invoked = 0;
|
|
let invoked = 0;
|
|
|
const factory = () => {
|
|
const factory = () => {
|
|
|
invoked++;
|
|
invoked++;
|
|
@@ -89,6 +108,19 @@ describe('projectData', function () {
|
|
|
expect(invoked).to.be.eq(1);
|
|
expect(invoked).to.be.eq(1);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ it('should pass the "factoryArgs" option to the schema factory', function () {
|
|
|
|
|
+ let invoked = 0;
|
|
|
|
|
+ const factoryArgs = [1, 2, 3];
|
|
|
|
|
+ const factory = (...args) => {
|
|
|
|
|
+ invoked++;
|
|
|
|
|
+ expect(args).to.be.eql(factoryArgs);
|
|
|
|
|
+ return {foo: true, bar: false};
|
|
|
|
|
+ };
|
|
|
|
|
+ const res = projectData(factory, {foo: 10, bar: 20}, {factoryArgs});
|
|
|
|
|
+ expect(res).to.be.eql({foo: 10});
|
|
|
|
|
+ expect(invoked).to.be.eq(1);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
it('should require a factory value to be an object or a non-empty string', function () {
|
|
it('should require a factory value to be an object or a non-empty string', function () {
|
|
|
const throwable = v => () => projectData(() => v, {});
|
|
const throwable = v => () => projectData(() => v, {});
|
|
|
const error = s =>
|
|
const error = s =>
|
|
@@ -122,7 +154,7 @@ describe('projectData', function () {
|
|
|
expect(invoked).to.be.eq(1);
|
|
expect(invoked).to.be.eq(1);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('should require the resolver option when the schema name is given', function () {
|
|
|
|
|
|
|
+ it('should require the "resolver" option when the schema name is provided', function () {
|
|
|
const throwable = () => projectData('mySchema', {});
|
|
const throwable = () => projectData('mySchema', {});
|
|
|
expect(throwable).to.throw(
|
|
expect(throwable).to.throw(
|
|
|
'Projection option "resolver" is required to resolve "mySchema" schema.',
|
|
'Projection option "resolver" is required to resolve "mySchema" schema.',
|
|
@@ -147,7 +179,7 @@ describe('projectData', function () {
|
|
|
throwable({})();
|
|
throwable({})();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('should resolver the schema name from the factory function', function () {
|
|
|
|
|
|
|
+ it('should resolve the schema name from the factory function', function () {
|
|
|
let invoked = 0;
|
|
let invoked = 0;
|
|
|
const resolver = name => {
|
|
const resolver = name => {
|
|
|
invoked++;
|
|
invoked++;
|