|
|
@@ -39,24 +39,24 @@ describe('DataProjector', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('projectData', function () {
|
|
|
+ describe('project', function () {
|
|
|
it('should project the data object by the given schema', function () {
|
|
|
const S = new DataProjector();
|
|
|
- const res = S.projectData({foo: 10, bar: 20}, {foo: true, bar: false});
|
|
|
+ const res = S.project({foo: 10, bar: 20}, {foo: true, bar: false});
|
|
|
expect(res).to.be.eql({foo: 10});
|
|
|
});
|
|
|
|
|
|
it('should project the data object by the schema name', function () {
|
|
|
const S = new DataProjector();
|
|
|
S.defineSchema({name: 'mySchema', schema: {foo: true, bar: false}});
|
|
|
- const res = S.projectData({foo: 10, bar: 20, baz: 30}, 'mySchema');
|
|
|
+ const res = S.project({foo: 10, bar: 20, baz: 30}, 'mySchema');
|
|
|
expect(res).to.be.eql({foo: 10, baz: 30});
|
|
|
});
|
|
|
|
|
|
it('should exclude properties without rules in the strict mode', function () {
|
|
|
const S = new DataProjector();
|
|
|
S.defineSchema({name: 'mySchema', schema: {foo: true, bar: false}});
|
|
|
- const res = S.projectData({foo: 10, bar: 20, baz: 30}, 'mySchema', {
|
|
|
+ const res = S.project({foo: 10, bar: 20, baz: 30}, 'mySchema', {
|
|
|
strict: true,
|
|
|
});
|
|
|
expect(res).to.be.eql({foo: 10});
|
|
|
@@ -71,7 +71,7 @@ describe('DataProjector', function () {
|
|
|
expect(name).to.be.eq(schemaName);
|
|
|
return {foo: true, bar: false};
|
|
|
};
|
|
|
- const res = S.projectData({foo: 10, bar: 20}, 'mySchema', {nameResolver});
|
|
|
+ const res = S.project({foo: 10, bar: 20}, 'mySchema', {nameResolver});
|
|
|
expect(res).to.be.eql({foo: 10});
|
|
|
expect(invoked).to.be.eq(1);
|
|
|
});
|
|
|
@@ -84,7 +84,7 @@ describe('DataProjector', function () {
|
|
|
expect(container).to.be.eq(S.container);
|
|
|
return {foo: true, bar: false};
|
|
|
};
|
|
|
- const res = S.projectData({foo: 10, bar: 20}, factory);
|
|
|
+ const res = S.project({foo: 10, bar: 20}, factory);
|
|
|
expect(res).to.be.eql({foo: 10});
|
|
|
expect(invoked).to.be.eq(1);
|
|
|
});
|
|
|
@@ -98,21 +98,21 @@ describe('DataProjector', function () {
|
|
|
expect(args).to.be.eql(factoryArgs);
|
|
|
return {foo: true, bar: false};
|
|
|
};
|
|
|
- const res = S.projectData({foo: 10, bar: 20}, factory, {factoryArgs});
|
|
|
+ const res = S.project({foo: 10, bar: 20}, factory, {factoryArgs});
|
|
|
expect(res).to.be.eql({foo: 10});
|
|
|
expect(invoked).to.be.eq(1);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('projectInput', function () {
|
|
|
- it('should invoke the "projectData" method with the "input" scope and return its result', function () {
|
|
|
+ it('should invoke the "project" method with the "input" scope and return its result', function () {
|
|
|
const S = new DataProjector();
|
|
|
const schema = {foo: true, bar: false};
|
|
|
const data = {foo: 10, bar: 20};
|
|
|
const options = {extra: true};
|
|
|
const result = {foo: 10};
|
|
|
let invoked = 0;
|
|
|
- S.projectData = (...args) => {
|
|
|
+ S.project = (...args) => {
|
|
|
expect(args).to.be.eql([data, schema, {extra: true, scope: 'input'}]);
|
|
|
invoked++;
|
|
|
return result;
|
|
|
@@ -135,14 +135,14 @@ describe('DataProjector', function () {
|
|
|
});
|
|
|
|
|
|
describe('projectOutput', function () {
|
|
|
- it('should invoke the "projectData" method with the "output" scope and return its result', function () {
|
|
|
+ it('should invoke the "project" method with the "output" scope and return its result', function () {
|
|
|
const S = new DataProjector();
|
|
|
const schema = {foo: true, bar: false};
|
|
|
const data = {foo: 10, bar: 20};
|
|
|
const options = {extra: true};
|
|
|
const result = {foo: 10};
|
|
|
let invoked = 0;
|
|
|
- S.projectData = (...args) => {
|
|
|
+ S.project = (...args) => {
|
|
|
expect(args).to.be.eql([data, schema, {extra: true, scope: 'output'}]);
|
|
|
invoked++;
|
|
|
return result;
|