Skip to content

Instantly share code, notes, and snippets.

@johncrisostomo
Created May 7, 2018 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johncrisostomo/44f444dcfd3a826ad395540bb971a691 to your computer and use it in GitHub Desktop.
Save johncrisostomo/44f444dcfd3a826ad395540bb971a691 to your computer and use it in GitHub Desktop.
gagarin client testing
import { Categories, Products } from '/lib/collections';
import {Meteor} from 'meteor/meteor';
import {check} from 'meteor/check';
export default function () {
Meteor.publish('categoriesList', () => {
return [
Categories.find(),
Products.find(),
];
});
Meteor.publish('categoriesOwnedBy', (ownerId) => {
check(ownerId, String);
return Categories.find({owner: ownerId});
});
Meteor.publish('categoriesSingle', (category_id) => {
check(category_id, String);
return Categories.find({_id:category_id});
});
}
describe('Categories test', function() {
var app = meteor({flavor: "fiber"});
var client = ddp(app, {flavor: "fiber"});
it('should be able to add', function() {
client.subscribe('categoriesList');
var categories = client.collection("categories");
client.call('categoriesAdd', [{name: 'sample from first it'}]);
client.sleep(200);
client.call('categoriesAdd', [{name: 'second from first it'}]);
categories = client.collection("categories");
expect(Object.keys(categories).length).to.equal(1);
});
it('should be able to update', function() {
client.subscribe('categoriesList');
client.call('categoriesAdd', [{name: 'sample from second it'}]);
client.sleep(200);
var categories = client.collection("categories");
var id = Object.keys(categories)[2];
client.call('categoriesUpdate', [{_id:id, name: 'updated sample'}]);
client.sleep(200);
categories = client.collection("categories");
expect(categories[id].name).to.equal('updated sample');
console.log(categories);
});
});
describe('user specific pub/sub', function() {
var app = meteor({flavor: "fiber"});
var client = ddp(app, {flavor: "fiber"});
it('should only get own categories', function() {
app.execute(function() {
var cat1 = { name: 'First Owned by dummy', owner: 'dummy' };
var cat2 = { name: 'Second Owned by someone else', owner: 'someone' };
var cat3 = { name: 'Third Owned by dummy again', owner: 'dummy' };
Meteor.call('categoriesAdd', cat1);
Meteor.call('categoriesAdd', cat2);
Meteor.call('categoriesAdd', cat3);
});
client.subscribe('categoriesOwnedBy', ['dummy']);
var dummysCategories = client.collection('categories');
expect(Object.keys(dummysCategories).length).to.equal(2);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment