katowulf / mockfirebase

Firebase mock library for writing unit tests (experimental)
157 stars 40 forks source link

Validate data writes #79

Open msiebuhr opened 9 years ago

msiebuhr commented 9 years ago

If setting undefined as a value in a transaction, Firebase will throw an error transaction failed: Data returned contains undefined in property 'data'. If the same code is run through MockFirebase, no such error is thrown.

var Firebase = require('firebase');
var FirebaseTokenGenerator = require('firebase-token-generator');

var fbClient = new Firebase(process.env.FIREBASE_URL);
var fbTokenGenerator = new FirebaseTokenGenerator(process.env.FIREBASE_SECRET);

// Uncomment these and it will print 'FIREBASE NEVER GETS HERE');
//fbClient = new (require('mockfirebase').MockFirebase)();
//fbClient.autoFlush();

fbClient.child('deleteme').transaction(function (cur) {
    return {data: undefined}; // Big no-no
}, function (err, comitted, snap) {
    console.log('FIREBASE NEVER GETS HERE');
});
bendrucker commented 9 years ago

Yeah, Firebase has a ton of validation logic that we're never going to fully replicate. Not that I'm not willing to try to create parity where possible. Just that you should be doing integration tests with the real SDK as well.

The logic that handles that validate is here:

https://github.com/firebase/firebase-bower/blob/6c7b6b95039622197aa52bf20959f4be87bd60f0/firebase-debug.js#L8578-L8615

bendrucker commented 9 years ago

This isn't going to happen right away because I'm not willing to patch this for transactions and ignore every other write method that validates its inputs.

bendrucker commented 9 years ago

This will be implemented in 1.0 by running user inputs through to-firebase. If you really want this now, I'll take a PR to master that runs all write method input through to-firebase.