mirror of
https://github.com/vale981/grapher
synced 2025-03-10 04:46:40 -04:00
121 lines
No EOL
3.3 KiB
JavaScript
121 lines
No EOL
3.3 KiB
JavaScript
import postListExposure from './bootstrap/queries/postListExposure.js';
|
|
import { createQuery } from 'meteor/cultofcoders:grapher';
|
|
|
|
describe('Named Query', function () {
|
|
it('Should return proper values', function (done) {
|
|
const query = createQuery({
|
|
postListExposure: {
|
|
title: 'User Post - 3'
|
|
}
|
|
});
|
|
|
|
query.fetch((err, res) => {
|
|
assert.isUndefined(err);
|
|
assert.isTrue(res.length > 0);
|
|
|
|
_.each(res, post => {
|
|
assert.equal(post.title, 'User Post - 3');
|
|
assert.isObject(post.author);
|
|
assert.isObject(post.group);
|
|
});
|
|
|
|
done();
|
|
})
|
|
});
|
|
|
|
it('Should return proper values using query directly via import', function (done) {
|
|
const query = postListExposure.clone({title: 'User Post - 3'});
|
|
|
|
query.fetch((err, res) => {
|
|
assert.isUndefined(err);
|
|
assert.isTrue(res.length > 0);
|
|
|
|
_.each(res, post => {
|
|
assert.equal(post.title, 'User Post - 3');
|
|
assert.isObject(post.author);
|
|
assert.isObject(post.group);
|
|
});
|
|
|
|
done();
|
|
})
|
|
});
|
|
|
|
it('Should work with count', function (done) {
|
|
const query = postListExposure.clone({title: 'User Post - 3'});
|
|
|
|
query.getCount((err, res) => {
|
|
assert.equal(6, res);
|
|
done();
|
|
})
|
|
});
|
|
|
|
it('Should work with reactive counts', function (done) {
|
|
const query = postListExposure.clone({title: 'User Post - 3'});
|
|
|
|
const handle = query.subscribeCount();
|
|
Tracker.autorun(c => {
|
|
if (handle.ready()) {
|
|
c.stop();
|
|
const count = query.getCount();
|
|
handle.stop();
|
|
|
|
assert.equal(count, 6);
|
|
done();
|
|
}
|
|
});
|
|
});
|
|
|
|
it('Should work with reactive queries', function (done) {
|
|
const query = createQuery({
|
|
postListExposure: {
|
|
title: 'User Post - 3'
|
|
}
|
|
});
|
|
|
|
const handle = query.subscribe();
|
|
|
|
Tracker.autorun(c => {
|
|
if (handle.ready()) {
|
|
c.stop();
|
|
const res = query.fetch();
|
|
handle.stop();
|
|
|
|
assert.isTrue(res.length > 0);
|
|
|
|
_.each(res, post => {
|
|
assert.equal(post.title, 'User Post - 3');
|
|
assert.isObject(post.author);
|
|
assert.isObject(post.group);
|
|
});
|
|
|
|
done();
|
|
}
|
|
})
|
|
});
|
|
|
|
it('Should work with reactive queries via import', function (done) {
|
|
const query = postListExposure.clone({
|
|
title: 'User Post - 3'
|
|
});
|
|
|
|
const handle = query.subscribe();
|
|
|
|
Tracker.autorun(c => {
|
|
if (handle.ready()) {
|
|
c.stop();
|
|
const res = query.fetch();
|
|
handle.stop();
|
|
|
|
assert.isTrue(res.length > 0);
|
|
|
|
_.each(res, post => {
|
|
assert.equal(post.title, 'User Post - 3');
|
|
assert.isObject(post.author);
|
|
assert.isObject(post.group);
|
|
});
|
|
|
|
done();
|
|
}
|
|
})
|
|
})
|
|
}); |