javascript - Only getting partial user publication in Meteor Jasmine test -
i have client integration test ensure admin user can change user roles via user management interface in app. however, when query user want change, query comes empty though has been created in fixture.
describe('admin users', function() { beforeeach(function(done) { meteor.loginwithpassword('admin@gmail.com', '12345678', function(error) { router.go('/users'); tracker.afterflush(done); }); }); beforeeach(waitforrouter); aftereach(function(done) { meteor.logout(function() { done(); }); }); it('should able change user roles', function(done) { var changeuser = meteor.users.findone({ emails: { $elemmatch: { address: 'user@gmail.com' } } }); console.log('changeuser: ', changeuser); console.log('users: ', meteor.users.find().fetch()); $('#user-' + changeuser._id + '-roles').val('manage-users').change(); expect(roles.userisinrole(changeuser, 'manage-users')).tobe(true); expect(roles.userisinrole(changeuser, 'edit-any')).tobe(false); done(); }); });
this test fails following error:
typeerror: cannot read property '_id' of undefined
here's fixture file creates 2 users:
/* globals resetdatabase: true, loaddefaultfixtures: true, */ var future = npm.require('fibers/future'); resetdatabase = function () { console.log('resetting database'); // safety check if (!process.env.is_mirror) { console.error('velocityreset not allowed outside of mirror. has gone wrong.'); return false; } var fut = new future(); var collectionsremoved = 0; var db = meteor.users.find()._mongo.db; db.collections(function (err, collections) { var appcollections = _.reject(collections, function (col) { return col.collectionname.indexof('velocity') === 0 || col.collectionname === 'system.indexes'; }); _.each(appcollections, function (appcollection) { appcollection.remove(function (e) { if (e) { console.error('failed removing collection', e); fut.return('fail: ' + e); } collectionsremoved++; console.log('removed collection'); if (appcollections.length === collectionsremoved) { console.log('finished resetting database'); fut['return']('success'); } }); }); }); return fut.wait(); }; loaddefaultfixtures = function () { console.log('loading default fixtures'); var adminid = accounts.createuser({email: 'admin@gmail.com', password: '12345678'}); var standarduserid = accounts.createuser({email: 'user@gmail.com', password: '12345678'}); console.log('users: ', meteor.users.find().fetch()); console.log('finished loading default fixtures'); }; if (process.env.is_mirror) { resetdatabase(); loaddefaultfixtures(); }
i can see output of fixture console.log
in jasmine logs, , shows both users. log test logs undefined
changeuser , array of current user full collection fetch.
the other problems can imagine publication , subscription. can't see wrong them, missing it. here's publication:
meteor.publish('allusers', function () { if (roles.userisinrole(this.userid, ['manage-users'])) { return meteor.users.find({}, { fields: { emails: true, roles: true, id: true}}); } else { return this.ready(); } });
and subscription:
subscriptions: function() { return [meteor.subscribe('allusers'), meteor.subscribe('allroles')]; },
it seems default meteor users publication containing current user being delivered test, shouldn't waiting on route , route's user subscription mean entire user list being published/subscribed?
Comments
Post a Comment