Meteor-Community-Packages / meteor-publication-collector

Test a Meteor publication by collecting its output.
https://atmospherejs.com/johanbrook/publication-collector
MIT License
33 stars 20 forks source link

Can't use on publication of users #33

Closed jonathan-ek closed 7 years ago

jonathan-ek commented 7 years ago

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();
    });
  });
jonathan-ek commented 7 years ago

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.