jeudi 29 janvier 2015

Testing meteor - testing allow / deny with a unit test instead of integration test

I have an application code that restricts documents in the following manner



Docs.allow({
insert: function(userId, doc){
return !!userId
},
update: function(userId, doc){
return userId && doc.owner == userId;
}
})


Currently, I can only run an integration test which makes actual http calls. I am not able to stub the components (Meteor current user) outside the system under test (allow / deny rules).



it("should succeed if user is authenticated", function(done) {
Meteor.loginWithPassword(’shawn@abc.com', ‘hahaha', function(err){
expect(err).toBe(undefined);
Doc = Docs.insert({title: 'abc', category: 'Finance'}, function(err, id){
expect(err).toBeUndefined();
expect(id).not.toBeUndefined();
done();
});
});
});

it("should fail if user is not authenticated", function(done) {
Meteor.logout(function(){
doc = Docs.insert({title: 'abc', category: 'Finance', owner: '1232131'}, function(err, id){
expect(err).not.toBeUndefined();
done();
});
});
});


This makes my test incredibly slow, especially if there are many paths I want to test. Is there a way for me to move this test to a lower level unit test instead?


Aucun commentaire:

Enregistrer un commentaire