|
|
@@ -58,11 +58,12 @@ describe('projectData', function () {
|
|
|
throwable(undefined)();
|
|
|
});
|
|
|
|
|
|
- it('should require the "resolver" option to be a function', function () {
|
|
|
- const throwable = v => () => projectData({}, 10, {resolver: v});
|
|
|
+ it('should require the "nameResolver" option to be a function', function () {
|
|
|
+ const throwable = v => () => projectData({}, 10, {nameResolver: v});
|
|
|
const error = s =>
|
|
|
format(
|
|
|
- 'Projection option "resolver" must be a Function, but %s was given.',
|
|
|
+ 'Projection option "nameResolver" must be ' +
|
|
|
+ 'a Function, but %s was given.',
|
|
|
s,
|
|
|
);
|
|
|
expect(throwable('str')).to.throw(error('"str"'));
|
|
|
@@ -139,33 +140,34 @@ describe('projectData', function () {
|
|
|
expect(throwable(null)).to.throw(error('null'));
|
|
|
expect(throwable(() => undefined)).to.throw(error('Function'));
|
|
|
projectData(() => ({}), {});
|
|
|
- projectData(() => 'str', {}, {resolver: () => ({})});
|
|
|
+ projectData(() => 'str', {}, {nameResolver: () => ({})});
|
|
|
});
|
|
|
|
|
|
- it('should resolve the schema name by the given resolver', function () {
|
|
|
+ it('should resolve the schema name by the name resolver', function () {
|
|
|
let invoked = 0;
|
|
|
- const resolver = name => {
|
|
|
+ const nameResolver = name => {
|
|
|
invoked++;
|
|
|
expect(name).to.be.eql('mySchema');
|
|
|
return {foo: true, bar: false};
|
|
|
};
|
|
|
- const res = projectData('mySchema', {foo: 10, bar: 20}, {resolver});
|
|
|
+ const res = projectData('mySchema', {foo: 10, bar: 20}, {nameResolver});
|
|
|
expect(res).to.be.eql({foo: 10});
|
|
|
expect(invoked).to.be.eq(1);
|
|
|
});
|
|
|
|
|
|
- it('should require the "resolver" option when the schema name is provided', function () {
|
|
|
+ it('should require the "nameResolver" option when the schema name is provided', function () {
|
|
|
const throwable = () => projectData('mySchema', {});
|
|
|
expect(throwable).to.throw(
|
|
|
- 'Projection option "resolver" is required to resolve "mySchema" schema.',
|
|
|
+ 'Projection option "nameResolver" is required ' +
|
|
|
+ 'to resolve "mySchema" name.',
|
|
|
);
|
|
|
});
|
|
|
|
|
|
- it('should require a resolver result to be an object', function () {
|
|
|
+ it('should require the name resolver to return an object', function () {
|
|
|
const throwable = v => () =>
|
|
|
- projectData('mySchema', {}, {resolver: () => v});
|
|
|
+ projectData('mySchema', {}, {nameResolver: () => v});
|
|
|
const error = s =>
|
|
|
- format('Schema resolver must return an Object, but %s was given.', s);
|
|
|
+ format('Name resolver must return 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'));
|
|
|
@@ -181,19 +183,23 @@ describe('projectData', function () {
|
|
|
|
|
|
it('should resolve the schema name from the factory function', function () {
|
|
|
let invoked = 0;
|
|
|
- const resolver = name => {
|
|
|
+ const nameResolver = name => {
|
|
|
invoked++;
|
|
|
expect(name).to.be.eql('mySchema');
|
|
|
return {foo: true, bar: false};
|
|
|
};
|
|
|
- const res = projectData(() => 'mySchema', {foo: 10, bar: 20}, {resolver});
|
|
|
+ const res = projectData(
|
|
|
+ () => 'mySchema',
|
|
|
+ {foo: 10, bar: 20},
|
|
|
+ {nameResolver},
|
|
|
+ );
|
|
|
expect(res).to.be.eql({foo: 10});
|
|
|
expect(invoked).to.be.eq(1);
|
|
|
});
|
|
|
|
|
|
- it('should resolve the named schema in the the nested object', function () {
|
|
|
+ it('should resolve the schema name in the the nested object', function () {
|
|
|
let invoked = 0;
|
|
|
- const resolver = name => {
|
|
|
+ const nameResolver = name => {
|
|
|
invoked++;
|
|
|
if (name === 'schema1') {
|
|
|
return {foo: true, bar: {schema: 'schema2'}};
|
|
|
@@ -202,7 +208,7 @@ describe('projectData', function () {
|
|
|
}
|
|
|
};
|
|
|
const data = {foo: 10, bar: {baz: 20, qux: 30}};
|
|
|
- const res = projectData('schema1', data, {resolver});
|
|
|
+ const res = projectData('schema1', data, {nameResolver});
|
|
|
expect(res).to.be.eql({foo: 10, bar: {baz: 20}});
|
|
|
expect(invoked).to.be.eq(2);
|
|
|
});
|