mockfirebase icon indicating copy to clipboard operation
mockfirebase copied to clipboard

Validate data writes

Open msiebuhr opened this issue 10 years ago • 3 comments
trafficstars

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');
});

msiebuhr avatar Mar 12 '15 11:03 msiebuhr

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 avatar Mar 12 '15 12:03 bendrucker

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 avatar Mar 12 '15 12:03 bendrucker

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.

bendrucker avatar May 28 '15 13:05 bendrucker