{"size": 1914, "ext": "js", "max_stars_repo_path": "test/index.js", "max_stars_repo_name": "gcanti/redux-tcomb", "max_stars_repo_stars_event_min_datetime": "2015-09-03T15:00:02.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-07T14:08:31.000Z", "max_issues_repo_path": "test/index.js", "max_issues_repo_name": "gcanti/redux-tcomb", "max_issues_repo_issues_event_min_datetime": "2015-09-14T17:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2017-05-07T06:23:58.000Z", "max_forks_repo_path": "test/index.js", "max_forks_repo_name": "gcanti/redux-tcomb", "max_forks_repo_forks_event_min_datetime": "2015-09-27T09:50:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-15T22:12:57.000Z"}
{"max_stars_count": 239, "max_issues_count": 13, "max_forks_count": 11, "avg_line_length": 25.52, "max_line_length": 120, "alphanum_fraction": 0.6567398119}
var tape = require('tape');
var t = require('tcomb');
var reduxTcomb = require('../.');
var createCheckedMiddleware = reduxTcomb.createCheckedMiddleware;
var createCheckedReducer = reduxTcomb.createCheckedReducer;
var createActionType = reduxTcomb.createActionType;
var redux = require('redux');
var createStore = redux.createStore;
var applyMiddleware = redux.applyMiddleware;

var State = t.Integer;
var PositiveInteger = t.refinement(t.Integer, function (n) { return n >= 0 }, 'PositiveInteger');
var Action = createActionType({
  INCREMENT: t.interface({ delta: PositiveInteger }),
  DECREMENT: t.interface({ delta: PositiveInteger })
});

function reducer(state, action) {
  if (typeof state === 'undefined') {
    state = 0;
  }
  switch(action.type) {
    case 'INCREMENT' :
      return state + action.delta;
    case 'DECREMENT' :
      return 'wrong';
  }
  return state;
}

tape('createCheckedMiddleware', function (test) {

  test.test('todo', function (assert) {
    assert.plan(1);

    var store = createStore(
      reducer,
      applyMiddleware(
        createCheckedMiddleware(Action)
      )
    )

    store.dispatch({ type: 'INCREMENT', delta: 2 })
    store.dispatch(Action.INCREMENT({ delta: 2 }))
    store.dispatch({ type: 'DECREMENT', delta: 2 })
    try {
      store.dispatch(1)
    } catch (e) {
      assert.strictEqual(e.message, '[tcomb] Invalid value 1 supplied to Action (no constructor returned by dispatch)');
    }
  });

});

tape('createCheckedReducer', function (test) {

  test.test('todo', function (assert) {
    assert.plan(1);

    var store = createStore(
      createCheckedReducer(reducer, State),
      applyMiddleware(
        createCheckedMiddleware(Action)
      )
    )

    try {
      store.dispatch({ type: 'DECREMENT', delta: 2 })
    } catch (e) {
      assert.strictEqual(e.message, '[tcomb] Invalid value "wrong" supplied to Integer');
    }
  });

});
