-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfind-from-publication_tests.js
More file actions
57 lines (49 loc) · 1.88 KB
/
find-from-publication_tests.js
File metadata and controls
57 lines (49 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// TODO -- make a package out of this, reuse together with publications package
import { Meteor } from 'meteor/meteor';
import { FindFromPublication } from 'meteor/percolate:find-from-publication';
import Future from 'fibers/future';
const runPublication = function(user, name, ...args) {
const pub = Meteor.server.publish_handlers[name];
const future = new Future;
const results = {};
// NOTE: changed/removed not implemented, will throw error
const sub = {
userId: user._id,
ready: function() {
future.return(results);
},
added: function(collectionName, id, doc) {
results[collectionName] = results[collectionName] || {};
results[collectionName][id] = doc;
},
removed: function(collectionName, id) {
delete results[collectionName][id];
}
}
pub.apply(sub, args);
return future.wait();
}
FindFromPublication.publish('tracked', function() {
this.added('posts', 'post-1', {foo: 'bar'});
this.added('posts', 'post-2', {foo: 'bar'});
this.added('comments', 'comments-1', {});
this.ready();
});
Meteor.publish('not-tracked', function() {
this.added('posts', 'post-1', {foo: 'bar'});
this.added('posts', 'post-2', {foo: 'bar'});
this.added('comments', 'comments-1', {});
this.ready();
});
Tinytest.add('FindFromPublication - publish - correct metadata is published', function(test) {
var records = runPublication({}, 'tracked');
test.equal(Object.keys(records.posts).length, 2);
test.equal(Object.keys(records.comments).length, 1);
test.equal(Object.keys(records.subscriptionMetadata).length, 3);
});
Tinytest.add('FindFromPublication - publish - metadata is not published for default pubs', function(test) {
var records = runPublication({}, 'not-tracked');
test.equal(Object.keys(records.posts).length, 2);
test.equal(Object.keys(records.comments).length, 1);
test.isUndefined(records.subscriptionMetadata);
});