manniru
9/30/2015 - 6:33 AM

Test what features firebase-server supports

Test what features firebase-server supports

var Firebase = require('firebase');
var FirebaseServer = require('firebase-server');
var states = require('us-states');
var assert = require('assert');

before(function(done) {
	new FirebaseServer(5000, 'test.firebaseio.com', {
		states: JSON.parse(JSON.stringify(states))
	});

	setTimeout(done, 300);
});

xit('should ', function (done) {
	var ref = new Firebase('ws://test.firebaseio.com:5000');
	var statesRef = ref.child('states');
	var query = statesRef.orderByValue().startAt('Delaware').limitToFirst(10);
	var first = true;

	query.on('value', function(snap) {
		console.log('Got Value: ', snap.val());
		if (first) {
			first = false;
			ref.update({
				'states/FL' : 'Floridadada',
				'states/GA' : 'AAAA'
			})
		} else {
			done();
		}
	});
});

xit('with priority ', function(done) {
	var ref = new Firebase('ws://test.firebaseio.com:5000');
	var statesRef = ref.child('states');
	var query = statesRef.startAt(1);

	var invocation = 0;

	query.on('value', function(snap) {
		var i = invocation;
		console.log('Current Value(%d): ', i, snap.val());
		invocation++;
		switch (i) {
			case 0:
				assert.strictEqual(null, snap.val());
				ref.child('states/AL').setWithPriority('Alabama', 200);
				return;

			case 1:
				assert.deepEqual({AL: 'Alabama'}, snap.val());
				ref.child('states/FL').setPriority(100);
				return;

			case 2:
				assert.deepEqual({FL: 'Florida', AL: 'Alabama'}, snap.val());
				done();
				return;
		}
	});
});

it('demonstrate priority failure ', function(done) {
	var ref = new Firebase('ws://test.firebaseio.com:5000');
	var statesRef = ref.child('states');
	var query = statesRef.startAt(1);

	ref.child('states/AL').setWithPriority('Alabama', 200);
	ref.child('states/FL').setPriority(100);

	setTimeout(function() {
		query.on('value', function(snap) {
			console.log('Current value: ', snap.val());
		});
	}, 100)
});
{
  "name": "firebase-server-test",
  "version": "0.0.0",
  "dependencies": {
    "firebase": "^2.3.0",
    "us-states": "0.0.1"
  },
  "devDependencies": {
    "firebase-server": "^0.3.1",
    "mocha": "^2.2.5"
  }
}

Got Value: { DC: 'District of Columbia', DE: 'Delaware', FL: 'Florida', FM: 'Federated States of Micronesia', GA: 'Georgia', GU: 'Guam', HI: 'Hawaii', ID: 'Idaho', IL: 'Illinois', IN: 'Indiana' }

Got Value: { DC: 'District of Columbia', DE: 'Delaware', FL: 'Floridadada', FM: 'Federated States of Micronesia', GU: 'Guam', HI: 'Hawaii', IA: 'Iowa', ID: 'Idaho', IL: 'Illinois',
IN: 'Indiana' }