mirror of
https://github.com/vale981/grapher
synced 2025-03-05 09:31:42 -05:00
some cleanups and fixed #161
This commit is contained in:
parent
ec487ee614
commit
63bd6b3e6d
5 changed files with 81 additions and 59 deletions
|
@ -61,7 +61,5 @@ function constructMetadataSchema(field, isMany, metadataSchema) {
|
|||
schemaDefinition[field + suffix + '.' + key] = value;
|
||||
});
|
||||
|
||||
console.log(schemaDefinition);
|
||||
|
||||
return schemaDefinition;
|
||||
}
|
|
@ -116,11 +116,10 @@ function cloneMetaChildren(node, parentResults) {
|
|||
}
|
||||
|
||||
export function assembleMetadata(node, parentResults) {
|
||||
// assembling metadata is depth first
|
||||
node.collectionNodes.forEach(collectionNode => {
|
||||
const linkName = collectionNode.linkName;
|
||||
|
||||
_.each(parentResults, result => {
|
||||
assembleMetadata(collectionNode, result[linkName])
|
||||
assembleMetadata(collectionNode, result[node.linkName])
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -131,7 +130,8 @@ export function assembleMetadata(node, parentResults) {
|
|||
|
||||
_.each(childResult, object => {
|
||||
const storage = object[node.linkStorageField];
|
||||
return storeMetadata(object, parentResult, storage, true);
|
||||
|
||||
storeMetadata(object, parentResult, storage, true);
|
||||
});
|
||||
})
|
||||
} else {
|
||||
|
|
|
@ -8,65 +8,67 @@ import Posts from './posts/collection';
|
|||
import Tags from './tags/collection';
|
||||
import Groups from './groups/collection';
|
||||
|
||||
Authors.remove({});
|
||||
Comments.remove({});
|
||||
Posts.remove({});
|
||||
Tags.remove({});
|
||||
Groups.remove({});
|
||||
Meteor.startup(() => {
|
||||
Authors.remove({});
|
||||
Comments.remove({});
|
||||
Posts.remove({});
|
||||
Tags.remove({});
|
||||
Groups.remove({});
|
||||
|
||||
const AUTHORS = 6;
|
||||
const POST_PER_USER = 6;
|
||||
const COMMENTS_PER_POST = 6;
|
||||
const TAGS = ['JavaScript', 'Meteor', 'React', 'Other'];
|
||||
const GROUPS = ['JavaScript', 'Meteor', 'React', 'Other'];
|
||||
const COMMENT_TEXT_SAMPLES = [
|
||||
'Good', 'Bad', 'Neutral'
|
||||
];
|
||||
const AUTHORS = 6;
|
||||
const POST_PER_USER = 6;
|
||||
const COMMENTS_PER_POST = 6;
|
||||
const TAGS = ['JavaScript', 'Meteor', 'React', 'Other'];
|
||||
const GROUPS = ['JavaScript', 'Meteor', 'React', 'Other'];
|
||||
const COMMENT_TEXT_SAMPLES = [
|
||||
'Good', 'Bad', 'Neutral'
|
||||
];
|
||||
|
||||
console.log('[testing] Loading test fixtures ...');
|
||||
console.log('[testing] Loading test fixtures ...');
|
||||
|
||||
let tags = TAGS.map(name => Tags.insert({name}));
|
||||
let groups = GROUPS.map(name => Groups.insert({name}));
|
||||
let authors = _.range(AUTHORS).map(idx => {
|
||||
return Authors.insert({
|
||||
name: 'Author - ' + idx,
|
||||
profile: {
|
||||
firstName: 'First Name - ' + idx,
|
||||
lastName: 'Last Name - ' + idx
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
_.each(authors, (author) => {
|
||||
const authorPostLink = Authors.getLink(author, 'posts');
|
||||
const authorGroupLink = Authors.getLink(author, 'groups');
|
||||
|
||||
authorGroupLink.add(_.sample(groups), {
|
||||
isAdmin: _.sample([true, false])
|
||||
let tags = TAGS.map(name => Tags.insert({name}));
|
||||
let groups = GROUPS.map(name => Groups.insert({name}));
|
||||
let authors = _.range(AUTHORS).map(idx => {
|
||||
return Authors.insert({
|
||||
name: 'Author - ' + idx,
|
||||
profile: {
|
||||
firstName: 'First Name - ' + idx,
|
||||
lastName: 'Last Name - ' + idx
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
_.each(_.range(POST_PER_USER), (idx) => {
|
||||
let post = {
|
||||
title: `User Post - ${idx}`
|
||||
};
|
||||
_.each(authors, (author) => {
|
||||
const authorPostLink = Authors.getLink(author, 'posts');
|
||||
const authorGroupLink = Authors.getLink(author, 'groups');
|
||||
|
||||
authorPostLink.add(post);
|
||||
const postCommentsLink = Posts.getLink(post, 'comments');
|
||||
const postTagsLink = Posts.getLink(post, 'tags');
|
||||
const postGroupLink = Posts.getLink(post, 'group');
|
||||
postGroupLink.set(_.sample(groups), {random: Random.id()});
|
||||
authorGroupLink.add(_.sample(groups), {
|
||||
isAdmin: _.sample([true, false])
|
||||
});
|
||||
|
||||
postTagsLink.add(_.sample(tags));
|
||||
|
||||
_.each(_.range(COMMENTS_PER_POST), (idx) => {
|
||||
let comment = {
|
||||
text: _.sample(COMMENT_TEXT_SAMPLES)
|
||||
_.each(_.range(POST_PER_USER), (idx) => {
|
||||
let post = {
|
||||
title: `User Post - ${idx}`
|
||||
};
|
||||
|
||||
postCommentsLink.add(comment);
|
||||
Comments.getLink(comment, 'author').set(_.sample(authors));
|
||||
})
|
||||
})
|
||||
});
|
||||
authorPostLink.add(post);
|
||||
const postCommentsLink = Posts.getLink(post, 'comments');
|
||||
const postTagsLink = Posts.getLink(post, 'tags');
|
||||
const postGroupLink = Posts.getLink(post, 'group');
|
||||
postGroupLink.set(_.sample(groups), {random: Random.id()});
|
||||
|
||||
console.log('[ok] fixtures have been loaded.');
|
||||
postTagsLink.add(_.sample(tags));
|
||||
|
||||
_.each(_.range(COMMENTS_PER_POST), (idx) => {
|
||||
let comment = {
|
||||
text: _.sample(COMMENT_TEXT_SAMPLES)
|
||||
};
|
||||
|
||||
postCommentsLink.add(comment);
|
||||
Comments.getLink(comment, 'author').set(_.sample(authors));
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
console.log('[ok] fixtures have been loaded.');
|
||||
})
|
||||
|
|
|
@ -221,6 +221,28 @@ describe('Hypernova', function () {
|
|||
})
|
||||
});
|
||||
|
||||
it('Should fetch direct One Meta links with $metadata that are under a nesting level', function () {
|
||||
let authors = createQuery({
|
||||
authors: {
|
||||
$options: { limit: 1 },
|
||||
posts: {
|
||||
$options: { limit: 1 },
|
||||
group: {
|
||||
name: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}).fetch();
|
||||
|
||||
let data = authors[0];
|
||||
|
||||
_.each(data.posts, post => {
|
||||
assert.isObject(post.group.$metadata);
|
||||
assert.isDefined(post.group.$metadata.random);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('Should fetch Inversed One & Many Meta links with $metadata', function () {
|
||||
let data = createQuery({
|
||||
groups: {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Package.describe({
|
||||
name: 'cultofcoders:grapher',
|
||||
version: '1.2.8',
|
||||
version: '1.2.8_1',
|
||||
// Brief, one-line summary of the package.
|
||||
summary: 'Grapher makes linking collections easily. And fetching data as a graph.',
|
||||
// URL to the Git repository containing the source code for this package.
|
||||
|
|
Loading…
Add table
Reference in a new issue