mirror of
https://github.com/vale981/grapher
synced 2025-03-05 17:41:41 -05:00
Added test for deepReducer 1-direct
This commit is contained in:
parent
d371c3260f
commit
6dcf5e9b7a
1 changed files with 66 additions and 45 deletions
|
@ -2,12 +2,12 @@ import { createQuery } from 'meteor/cultofcoders:grapher';
|
||||||
import Authors from './bootstrap/authors/collection';
|
import Authors from './bootstrap/authors/collection';
|
||||||
import Comments from './bootstrap/comments/collection';
|
import Comments from './bootstrap/comments/collection';
|
||||||
|
|
||||||
describe('Reducers', function () {
|
describe('Reducers', function() {
|
||||||
it('Should work with field only reducers', function () {
|
it('Should work with field only reducers', function() {
|
||||||
const data = createQuery({
|
const data = createQuery({
|
||||||
authors: {
|
authors: {
|
||||||
fullName: 1
|
fullName: 1,
|
||||||
}
|
},
|
||||||
}).fetch();
|
}).fetch();
|
||||||
|
|
||||||
assert.isTrue(data.length > 0);
|
assert.isTrue(data.length > 0);
|
||||||
|
@ -15,15 +15,15 @@ describe('Reducers', function () {
|
||||||
data.forEach(author => {
|
data.forEach(author => {
|
||||||
assert.isString(author.fullName);
|
assert.isString(author.fullName);
|
||||||
assert.isUndefined(author.name);
|
assert.isUndefined(author.name);
|
||||||
assert.isTrue(author.fullName.substr(0, 7) === 'full - ')
|
assert.isTrue(author.fullName.substr(0, 7) === 'full - ');
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should work with nested fields reducers', function () {
|
it('Should work with nested fields reducers', function() {
|
||||||
const data = createQuery({
|
const data = createQuery({
|
||||||
authors: {
|
authors: {
|
||||||
fullNameNested: 1
|
fullNameNested: 1,
|
||||||
}
|
},
|
||||||
}).fetch();
|
}).fetch();
|
||||||
|
|
||||||
assert.isTrue(data.length > 0);
|
assert.isTrue(data.length > 0);
|
||||||
|
@ -33,17 +33,38 @@ describe('Reducers', function () {
|
||||||
assert.isString(author.fullNameNested);
|
assert.isString(author.fullNameNested);
|
||||||
assert.isFalse(author.fullNameNested === 'undefined undefined');
|
assert.isFalse(author.fullNameNested === 'undefined undefined');
|
||||||
assert.isUndefined(author.profile);
|
assert.isUndefined(author.profile);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should work with nested fields reducers', function () {
|
it('Should work with deep reducers', function() {
|
||||||
|
const data = createQuery({
|
||||||
|
posts: {
|
||||||
|
$options: { limit: 5 },
|
||||||
|
author: {
|
||||||
|
fullName: 1,
|
||||||
|
fullNameNested: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}).fetch();
|
||||||
|
|
||||||
|
assert.isTrue(data.length > 0);
|
||||||
|
|
||||||
|
data.forEach(post => {
|
||||||
|
console.log(post);
|
||||||
|
const author = post.author;
|
||||||
|
assert.isUndefined(author.name);
|
||||||
|
assert.isTrue(author.fullName.substr(0, 7) === 'full - ');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should work with nested fields reducers', function() {
|
||||||
const data = createQuery({
|
const data = createQuery({
|
||||||
authors: {
|
authors: {
|
||||||
profile: {
|
profile: {
|
||||||
firstName: 1
|
firstName: 1,
|
||||||
},
|
},
|
||||||
fullNameNested: 1,
|
fullNameNested: 1,
|
||||||
}
|
},
|
||||||
}).fetch();
|
}).fetch();
|
||||||
|
|
||||||
assert.isTrue(data.length > 0);
|
assert.isTrue(data.length > 0);
|
||||||
|
@ -55,14 +76,14 @@ describe('Reducers', function () {
|
||||||
assert.isObject(author.profile);
|
assert.isObject(author.profile);
|
||||||
assert.isString(author.profile.firstName);
|
assert.isString(author.profile.firstName);
|
||||||
assert.isUndefined(author.profile.lastName);
|
assert.isUndefined(author.profile.lastName);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should work with links reducers', function () {
|
it('Should work with links reducers', function() {
|
||||||
const data = createQuery({
|
const data = createQuery({
|
||||||
authors: {
|
authors: {
|
||||||
groupNames: 1
|
groupNames: 1,
|
||||||
}
|
},
|
||||||
}).fetch();
|
}).fetch();
|
||||||
|
|
||||||
assert.isTrue(data.length > 0);
|
assert.isTrue(data.length > 0);
|
||||||
|
@ -70,10 +91,10 @@ describe('Reducers', function () {
|
||||||
data.forEach(author => {
|
data.forEach(author => {
|
||||||
assert.isArray(author.groupNames);
|
assert.isArray(author.groupNames);
|
||||||
assert.isUndefined(author.groups);
|
assert.isUndefined(author.groups);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should work with One link reducers', function () {
|
it('Should work with One link reducers', function() {
|
||||||
const sampleComment = Comments.findOne();
|
const sampleComment = Comments.findOne();
|
||||||
|
|
||||||
const comment = createQuery({
|
const comment = createQuery({
|
||||||
|
@ -82,18 +103,18 @@ describe('Reducers', function () {
|
||||||
_id: sampleComment._id,
|
_id: sampleComment._id,
|
||||||
},
|
},
|
||||||
authorLinkReducer: 1,
|
authorLinkReducer: 1,
|
||||||
}
|
},
|
||||||
}).fetchOne();
|
}).fetchOne();
|
||||||
|
|
||||||
assert.isObject(comment);
|
assert.isObject(comment);
|
||||||
assert.isObject(comment.authorLinkReducer);
|
assert.isObject(comment.authorLinkReducer);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should work with links and nested reducers', function () {
|
it('Should work with links and nested reducers', function() {
|
||||||
const data = createQuery({
|
const data = createQuery({
|
||||||
authors: {
|
authors: {
|
||||||
referenceReducer: 1
|
referenceReducer: 1,
|
||||||
}
|
},
|
||||||
}).fetch();
|
}).fetch();
|
||||||
|
|
||||||
assert.isTrue(data.length > 0);
|
assert.isTrue(data.length > 0);
|
||||||
|
@ -101,16 +122,16 @@ describe('Reducers', function () {
|
||||||
data.forEach(author => {
|
data.forEach(author => {
|
||||||
assert.isString(author.referenceReducer);
|
assert.isString(author.referenceReducer);
|
||||||
assert.isUndefined(author.fullName);
|
assert.isUndefined(author.fullName);
|
||||||
assert.isTrue(author.referenceReducer.substr(0, 9) === 'nested - ')
|
assert.isTrue(author.referenceReducer.substr(0, 9) === 'nested - ');
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should not clean nested reducers if not specified', function () {
|
it('Should not clean nested reducers if not specified', function() {
|
||||||
const data = createQuery({
|
const data = createQuery({
|
||||||
authors: {
|
authors: {
|
||||||
referenceReducer: 1,
|
referenceReducer: 1,
|
||||||
fullName: 1,
|
fullName: 1,
|
||||||
}
|
},
|
||||||
}).fetch();
|
}).fetch();
|
||||||
|
|
||||||
assert.isTrue(data.length > 0);
|
assert.isTrue(data.length > 0);
|
||||||
|
@ -118,19 +139,19 @@ describe('Reducers', function () {
|
||||||
data.forEach(author => {
|
data.forEach(author => {
|
||||||
assert.isString(author.referenceReducer);
|
assert.isString(author.referenceReducer);
|
||||||
assert.isString(author.fullName);
|
assert.isString(author.fullName);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should keep previously used items - Part 1', function () {
|
it('Should keep previously used items - Part 1', function() {
|
||||||
const data = createQuery({
|
const data = createQuery({
|
||||||
authors: {
|
authors: {
|
||||||
fullName: 1,
|
fullName: 1,
|
||||||
name: 1,
|
name: 1,
|
||||||
groupNames: 1,
|
groupNames: 1,
|
||||||
groups: {
|
groups: {
|
||||||
name: 1
|
name: 1,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}).fetch();
|
}).fetch();
|
||||||
|
|
||||||
assert.isTrue(data.length > 0);
|
assert.isTrue(data.length > 0);
|
||||||
|
@ -140,18 +161,18 @@ describe('Reducers', function () {
|
||||||
assert.isDefined(author.groups);
|
assert.isDefined(author.groups);
|
||||||
assert.isArray(author.groupNames);
|
assert.isArray(author.groupNames);
|
||||||
assert.isString(author.fullName);
|
assert.isString(author.fullName);
|
||||||
assert.isTrue(author.fullName.substr(0, 7) === 'full - ')
|
assert.isTrue(author.fullName.substr(0, 7) === 'full - ');
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should keep previously used items - Part 2', function () {
|
it('Should keep previously used items - Part 2', function() {
|
||||||
const data = createQuery({
|
const data = createQuery({
|
||||||
authors: {
|
authors: {
|
||||||
groupNames: 1,
|
groupNames: 1,
|
||||||
groups: {
|
groups: {
|
||||||
_id: 1
|
_id: 1,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}).fetch();
|
}).fetch();
|
||||||
|
|
||||||
assert.isTrue(data.length > 0);
|
assert.isTrue(data.length > 0);
|
||||||
|
@ -169,20 +190,20 @@ describe('Reducers', function () {
|
||||||
author.groups.forEach(group => {
|
author.groups.forEach(group => {
|
||||||
assert.isDefined(group._id);
|
assert.isDefined(group._id);
|
||||||
assert.isUndefined(group.name);
|
assert.isUndefined(group.name);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should work with params reducers', function () {
|
it('Should work with params reducers', function() {
|
||||||
const query = createQuery({
|
const query = createQuery({
|
||||||
authors: {
|
authors: {
|
||||||
$options: {limit: 1},
|
$options: { limit: 1 },
|
||||||
paramBasedReducer: 1,
|
paramBasedReducer: 1,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
query.setParams({
|
query.setParams({
|
||||||
element: 'TEST_STRING'
|
element: 'TEST_STRING',
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = query.fetch();
|
const data = query.fetch();
|
||||||
|
@ -190,6 +211,6 @@ describe('Reducers', function () {
|
||||||
assert.isTrue(data.length > 0);
|
assert.isTrue(data.length > 0);
|
||||||
data.forEach(author => {
|
data.forEach(author => {
|
||||||
assert.equal(author.paramBasedReducer, 'TEST_STRING');
|
assert.equal(author.paramBasedReducer, 'TEST_STRING');
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue