mirror of
https://github.com/vale981/grapher
synced 2025-03-05 09:31:42 -05:00
Handle case of nested fields in embedReducerWithLink in tests
This commit is contained in:
parent
84567fc3dc
commit
3253120eaf
3 changed files with 23 additions and 3 deletions
|
@ -95,10 +95,17 @@ Authors.addReducers({
|
|||
authorCached: {
|
||||
name: 1,
|
||||
},
|
||||
metadata: {
|
||||
keywords: 1
|
||||
},
|
||||
}
|
||||
},
|
||||
reduce(object) {
|
||||
return _.first(object.posts).authorCached.name + ' - 2';
|
||||
const firstPost = _.first(object.posts);
|
||||
return {
|
||||
author: firstPost.authorCached,
|
||||
metadata: {...firstPost.metadata},
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
3
lib/query/testing/bootstrap/fixtures.js
Normal file → Executable file
3
lib/query/testing/bootstrap/fixtures.js
Normal file → Executable file
|
@ -53,6 +53,9 @@ _.each(authors, (author) => {
|
|||
_.each(_.range(POST_PER_USER), (idx) => {
|
||||
let post = {
|
||||
title: `User Post - ${idx}`,
|
||||
metadata: {
|
||||
keywords: _.sample(TAGS, _.random(1, 2)),
|
||||
},
|
||||
createdAt: new Date(),
|
||||
};
|
||||
|
||||
|
|
|
@ -254,8 +254,8 @@ describe('Reducers', function() {
|
|||
* Both commentsReducers use Posts link on Authors collection and both use denormalized authorCached link
|
||||
* inside the Posts.
|
||||
*
|
||||
* This necessitates the use of embedReducerWithLink() function while creating reducers
|
||||
* which was failing for denormalized fields.
|
||||
* This necessitates the use of embedReducerWithLink() function while creating reducers,
|
||||
* which was failing for denormalized fields and also for nested fields.
|
||||
*/
|
||||
const query = createQuery({
|
||||
authors: {
|
||||
|
@ -265,7 +265,17 @@ describe('Reducers', function() {
|
|||
});
|
||||
|
||||
const data = query.fetch();
|
||||
|
||||
assert.isTrue(data.length > 0);
|
||||
data.forEach(author => {
|
||||
// check if nested denormalized links are working
|
||||
assert.isObject(author.commentsReducer2.author);
|
||||
assert.isTrue(author.commentsReducer2.author.name.startsWith('Author'));
|
||||
|
||||
// check if nested fields are working
|
||||
assert.isObject(author.commentsReducer2.metadata);
|
||||
assert.isTrue(author.commentsReducer2.metadata.keywords.length > 0);
|
||||
});
|
||||
});
|
||||
|
||||
it('Should allow non-existent nested fields while cleaning', function() {
|
||||
|
|
Loading…
Add table
Reference in a new issue