grapher/lib/namedQuery/testing/client.test.js

121 lines
3.3 KiB
JavaScript
Raw Normal View History

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();
})
});
2017-11-25 14:45:31 +02:00
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();
}
})
})
});