2017-11-26 19:15:00 +02:00
|
|
|
import { postList, postListCached } from './bootstrap/server.js';
|
2016-10-07 10:31:58 +03:00
|
|
|
import { createQuery } from 'meteor/cultofcoders:grapher';
|
|
|
|
|
2017-11-26 19:15:00 +02:00
|
|
|
|
2016-10-07 10:31:58 +03:00
|
|
|
describe('Named Query', function () {
|
|
|
|
it('Should return the proper values', function () {
|
|
|
|
const createdQuery = createQuery({
|
|
|
|
postList: {
|
|
|
|
title: 'User Post - 3'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const directQuery = postList.clone({
|
|
|
|
title: 'User Post - 3'
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each([createdQuery, directQuery], (query) => {
|
|
|
|
const data = query.fetch();
|
|
|
|
|
|
|
|
assert.isTrue(data.length > 1);
|
|
|
|
|
|
|
|
_.each(data, post => {
|
|
|
|
assert.equal(post.title, 'User Post - 3');
|
|
|
|
assert.isObject(post.author);
|
|
|
|
assert.isObject(post.group);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Exposure embodyment should work properly', function () {
|
|
|
|
const query = createQuery({
|
|
|
|
postListExposure: {
|
|
|
|
title: 'User Post - 3'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const data = query.fetch();
|
|
|
|
|
|
|
|
assert.isTrue(data.length > 1);
|
|
|
|
|
|
|
|
_.each(data, post => {
|
|
|
|
assert.equal(post.title, 'User Post - 3');
|
|
|
|
assert.isObject(post.author);
|
|
|
|
assert.isObject(post.group);
|
|
|
|
})
|
2017-11-26 19:15:00 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Should properly cache the values', function (done) {
|
|
|
|
const posts = postListCached.fetch();
|
|
|
|
const postsCount = postListCached.getCount();
|
|
|
|
|
|
|
|
const Posts = Mongo.Collection.get('posts');
|
|
|
|
const postId = Posts.insert({title: 'Hello Cacher!'});
|
|
|
|
|
|
|
|
assert.equal(posts.length, postListCached.fetch().length);
|
|
|
|
assert.equal(postsCount, postListCached.getCount());
|
|
|
|
|
|
|
|
Meteor.setTimeout(function () {
|
|
|
|
const newPosts = postListCached.fetch();
|
|
|
|
const newCount = postListCached.getCount();
|
|
|
|
|
|
|
|
Posts.remove(postId);
|
|
|
|
|
|
|
|
assert.isArray(newPosts);
|
|
|
|
assert.isNumber(newCount);
|
|
|
|
|
|
|
|
assert.equal(posts.length + 1, newPosts.length);
|
|
|
|
assert.equal(postsCount + 1, newCount);
|
|
|
|
|
|
|
|
done();
|
2017-11-26 23:52:37 +02:00
|
|
|
}, 400)
|
2017-11-26 19:15:00 +02:00
|
|
|
});
|
2017-11-26 20:18:30 +02:00
|
|
|
|
|
|
|
it('Should allow to securely fetch a subbody of a namedQuery', function () {
|
|
|
|
const query = createQuery({
|
|
|
|
postListExposure: {
|
|
|
|
limit: 5,
|
|
|
|
$body: {
|
|
|
|
title: 1,
|
|
|
|
createdAt: 1, // should fail
|
|
|
|
group: {
|
|
|
|
name: 1,
|
|
|
|
createdAt: 1, // should fail
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const data = query.fetch();
|
|
|
|
|
|
|
|
assert.isTrue(data.length > 1);
|
|
|
|
|
|
|
|
_.each(data, post => {
|
|
|
|
assert.isUndefined(post.createdAt);
|
|
|
|
assert.isUndefined(post.author);
|
|
|
|
assert.isObject(post.group);
|
|
|
|
assert.isUndefined(post.group.createdAt);
|
|
|
|
})
|
|
|
|
})
|
2017-11-26 19:15:00 +02:00
|
|
|
});
|