{"size": 1254, "ext": "js", "max_stars_repo_path": "test/create-messages-reducer.test.js", "max_stars_repo_name": "argshook/redux-msg", "max_stars_repo_stars_event_min_datetime": "2017-10-04T12:09:41.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-13T14:44:25.000Z", "max_issues_repo_path": "test/create-messages-reducer.test.js", "max_issues_repo_name": "argshook/redux-msg", "max_issues_repo_issues_event_min_datetime": "2017-09-30T20:11:31.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-04T21:24:54.000Z", "max_forks_repo_path": "test/create-messages-reducer.test.js", "max_forks_repo_name": "argshook/redux-msg", "max_forks_repo_forks_event_min_datetime": "2018-11-08T10:03:13.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-08T10:03:13.000Z"}
{"max_stars_count": 5, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 35.8285714286, "max_line_length": 111, "alphanum_fraction": 0.6427432217}
/* global describe it */
import { expect } from 'chai';

import createMessagesReducer from '../src/create-messages-reducer';
import createMessage from '../src/create-message';


const STATE_NAME = 'test-state-name';
const MODEL = { a: 1, b: '2' };
const stateMessage = createMessage(STATE_NAME);
const message = state => Object.assign({}, state, { a: 2 });
const reducer = createMessagesReducer(STATE_NAME)(MODEL);
const expectedState = { a: 2, b: '2' };

describe('createMessagesReducer', () => {
  describe('given curried stateName and model', () => {
    it('should return reducer that handles function messages', () => {
      expect(reducer(MODEL, stateMessage(message))).to.deep.equal(expectedState);
    });

    it('should return reducer that handles object messages', () => {
      const message = { a: 2 };
      expect(reducer(MODEL, stateMessage(message))).to.deep.equal(expectedState);
    });

    it('should handle messages with extended type', () => {
      expect(reducer(MODEL, stateMessage(message, 'hello'))).to.deep.equal(expectedState);
    });

    it('should concat previous and new states', () => {
      expect(reducer(MODEL, stateMessage(({ a }) => ({ a: a + 2 }), 'hello'))).to.deep.equal({ a: 3, b: '2' });
    });
  });
});
