describe("Transistor.Radio", function () { var faye = {}, servers = { 'without_collection': 'http://localhost:12001/faye', 'with_collection': 'http://localhost:12002/faye' }; beforeEach(function () { _.each(servers, function (url, key) { faye[key] = new Faye.Client(url); }) }); afterEach(function () { }); describe('subscription to empty collection', function () { var radio, calls; it('triggers an init event', function () { radio = new Transistor.Radio(servers['without_collection'], 'station_uid', 'token'); calls = []; runs(function () { radio.tune('test/channel', function (event, args) { calls.push({ event: event, args: args }); }); }); waits(200); runs(function () { assertEqual(calls.length, 1); assertEqual(calls[0].event, 'init'); assertEqual(calls[0].args, []); }); }); }); describe('subscription to filled collection', function () { var radio, calls; it('triggers an init event', function () { radio = new Transistor.Radio(servers['with_collection'], 'station_uid', 'token'); calls = []; runs(function () { radio.tune('test/channel', function (event, args) { calls.push({ event: event, args: args }); }); }); waits(200); runs(function () { assertEqual(calls.length, 1); assertEqual(calls[0].event, 'init'); assertEqual(calls[0].args, [{abcd: 1}, {efgh: 23}]); }); }); }); describe('channel events', function () { var radio, calls; it('triggers the callback', function () { radio = new Transistor.Radio(servers['with_collection'], 'station_uid', 'token'); calls = []; runs(function () { radio.tune('test/channel', function (event, args) { calls.push({ event: event, args: args }); }); }); waits(200); runs(function () { channel_path = '/station_uid/token/test/channel' message = { event: 'insert', args: { entry: {} } } faye['with_collection'].publish(channel_path, message) }); waits(200); runs(function () { assertEqual(calls.length, 2); assertEqual(calls[1].event, 'insert'); assertEqual(calls[1].args, {entry: {}}); }); }); }); });