Skip to content
This repository has been archived by the owner on Aug 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #16 from bigdatr/feature/dont_listen
Browse files Browse the repository at this point in the history
Feature/dont listen
  • Loading branch information
thepont committed Oct 3, 2017
2 parents 1584df7 + 111bdd4 commit 34bcd02
Show file tree
Hide file tree
Showing 43 changed files with 1,442 additions and 295 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/* linguist-generated
3 changes: 1 addition & 2 deletions elephas.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
require('babel-core/register');
module.exports = require('./lib/framework');
module.exports = require('./lib/framework');
15 changes: 6 additions & 9 deletions lib/Service.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 27 additions & 17 deletions lib/__test__/client-test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
import {expect} from 'chai';
import sinon from 'sinon';
import client from '../client';
'use strict';

const payload = 'test';
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

global.Primus = function() {
var _chai = require('chai');

var _sinon = require('sinon');

var _sinon2 = _interopRequireDefault(_sinon);

var _client = require('../client');

var _client2 = _interopRequireDefault(_client);

var payload = 'test';

global.Primus = function () {
return {
on(e, cb) {
on: function on(e, cb) {
return cb('payload');
},
write: sinon.spy()
write: _sinon2['default'].spy()
};
};

const myStore = {
dispatch: sinon.spy()
var myStore = {
dispatch: _sinon2['default'].spy()
};

describe('client', () => {
it('subscribe to redux store', () => {
client.connect(myStore);
describe('client', function () {
it('subscribe to redux store', function () {
_client2['default'].connect(myStore);

expect(myStore.dispatch.called).to.equal(true);
(0, _chai.expect)(myStore.dispatch.called).to.equal(true);
});

it('should dispatch to server and client', () => {
client.dispatch('actionTest');
it('should dispatch to server and client', function () {
_client2['default'].dispatch('actionTest');

expect(myStore.dispatch.calledWith('actionTest')).to.equal(true);
(0, _chai.expect)(myStore.dispatch.calledWith('actionTest')).to.equal(true);
});
});
});
32 changes: 21 additions & 11 deletions lib/__test__/clientSocket-test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import {expect} from 'chai';
import sinon from 'sinon';
import clientSocket from '../clientSocket';

describe('clientSocket', () => {
it('should dispatch to the client', () => {
const spark = {
write: sinon.spy()
'use strict';

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _chai = require('chai');

var _sinon = require('sinon');

var _sinon2 = _interopRequireDefault(_sinon);

var _clientSocket = require('../clientSocket');

var _clientSocket2 = _interopRequireDefault(_clientSocket);

describe('clientSocket', function () {
it('should dispatch to the client', function () {
var spark = {
write: _sinon2['default'].spy()
};

const client = clientSocket(spark);
var client = (0, _clientSocket2['default'])(spark);

client.dispatch('myAction');

expect(spark.write.calledWith('myAction')).to.equal(true);
(0, _chai.expect)(spark.write.calledWith('myAction')).to.equal(true);
});
});
});
55 changes: 31 additions & 24 deletions lib/__test__/wsRouter-test.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
import {expect} from 'chai';
import sinon from 'sinon';
import wsRouter from '../wsRouter';
'use strict';

const _testRoutes = [
{ MY_TEST_ACTION: sinon.spy() },
{ ANOTHER_ACTION: ()=>{
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _chai = require('chai');

var _sinon = require('sinon');

var _sinon2 = _interopRequireDefault(_sinon);

var _wsRouter = require('../wsRouter');

var _wsRouter2 = _interopRequireDefault(_wsRouter);

var _testRoutes = [{ MY_TEST_ACTION: _sinon2['default'].spy() }, { ANOTHER_ACTION: function ANOTHER_ACTION() {
var e = new Error('dummy');
console.log(e.stack);
}

}
];

describe('wsRouter', () => {
it('has no routes by default', () => {
expect(wsRouter.hasRoutes()).to.equal(false);
}

}];

describe('wsRouter', function () {
it('has no routes by default', function () {
(0, _chai.expect)(_wsRouter2['default'].hasRoutes()).to.equal(false);
});

it('can add websocket routes/action handlers', () => {
wsRouter.setActionHandlers(_testRoutes);
it('can add websocket routes/action handlers', function () {
_wsRouter2['default'].setActionHandlers(_testRoutes);

expect(wsRouter.hasRoutes()).to.equal(true);
(0, _chai.expect)(_wsRouter2['default'].hasRoutes()).to.equal(true);
});

it('can route to the correct action', () => {
const client = {};
const action = {type: 'MY_TEST_ACTION', payload: 'test'};
it('can route to the correct action', function () {
var client = {};
var action = { type: 'MY_TEST_ACTION', payload: 'test' };

wsRouter.route(client, action);
_wsRouter2['default'].route(client, action);

const fn = _testRoutes[0].MY_TEST_ACTION;
var fn = _testRoutes[0].MY_TEST_ACTION;

expect(fn.called).to.equal(true);
(0, _chai.expect)(fn.called).to.equal(true);
});

// it('should not execute an action handler if there is no match', () => {
Expand All @@ -43,4 +50,4 @@ describe('wsRouter', () => {

// expect(_testRoutes[1].ANOTHER_ACTION.called).to.equal(false);
// });
});
});
12 changes: 7 additions & 5 deletions lib/client.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 12 additions & 14 deletions lib/clientSocket.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 34bcd02

Please sign in to comment.