I've updated my allow and deny rules from the client. No inserts, updates or removes should work on the client side. Previously this test (listed below) passed because it tested to see if the client could insert into the collection. Now I want to switch this to test make sure the test only passes when the client can't insert into the collection.
How is this done?
//tests/tests.js
var assert = require('assert');
suite('Donate', function() {
test('in the server', function(done, server) {
server.eval(function() {
Donate.insert({fname: 'George'});
var docs = Donate.find().fetch();
emit('docs', docs);
});
server.once('docs', function(docs) {
assert.equal(docs.length, 1);
done();
});
});
});
test('using both client and the server', function(done, server, client) {
server.eval(function() {
Donate.find().observe({
added: addedNewDonate
});
function addedNewDonate(donate) {
emit('donate', donate);
}
}).once('donate', function(donate) {
assert.equal(donate.fname, 'George');
done();
});
client.eval(function() {
Donate.insert({fname: 'George'});
});
});
You might be going about this in the wrong way. Testing to see if an insert is denied as expected is actually testing the Meteor core which is already tested. Put another way, you should be testing the method that returns false for the insert deny property. If all you are doing is:
Donate.deny({
insert: function(){
return false;
}
)};
then you don't need to test for this since the Meteor core is tested enough for you to know that this will work.
On the other hand if you have something like
function complexDenyFunction(){
//perform complex actions
//if all complex conditions are satisfied
//return true
//else return false
return result;
}
Donate.deny({
insert: complexDenyFunction
});
Then what you want to do is create the scenarios where complexDenyFunction
would return true
and false
and test complexDenyFunction
to see if if returns the expected results