Meteor-Community-Packages/meteor-publication-collector

Can't use on publication of users

jonathan-ek opened this issue · 1 comments

I have a publication that publishes a selection of users and fields depending on the user, but it doesn't work. I get the output below when i try to run it.

TypeError: Cannot read property 'call' of undefined
at PublicationCollector.collect (packages/johanbrook:publication-collector/publication-collector.js:67:28)

My publication looks like this:

Meteor.publish('users', function () {
  const user = Meteor.users.findOne(this.userId);
  if (!user) {
    return this.ready();
  }

  if (Roles.userIsInRole(user._id, ['admin'])) {
    return Meteor.users.find({}, {
      fields: {
        createdAt: 1,
        emails: 1,
        roles: 1,
      },
    });
  }
  return this.ready();
});

I have emptied and populated both the user and role collection and trying just to get the test working like this:

  it('should publish users', function(done) {
    const collector = new PublicationCollector({ userId: 'D9E6CRGLX4Me3p6x9' });
    collector.collect('users', (collections) => {

      done();
    });
  });

Oh, it worked when I imported the file with the publication.
I find it a bit strange that I didn't need to do that with the other collections though.
But I will close this issue.