import { fromJS } from 'immutable'
import { expect } from 'chai'

import stimuliReducer from '../stimuli'
import { addStimuli } from '../../actions/stimuli'

import Stimulus from '../../records/Stimulus'

describe('stimuli reducer', () => {
  describe('addStimulus', () => {
    it('should add new stimuli with ADD_STIMULI action', () => {
      const initialState = fromJS({})
      const action = addStimuli([{id: '1', title: 'hello'}])
      const nextState = stimuliReducer(initialState, action)

      const nextStimulus = nextState.get('1').get('title')
      expect(nextStimulus).to.equal('hello')
    })

    it('should replace stimuli with ADD_STIMULI action', () => {
      const initialState = fromJS({
        1: new Stimulus({id: '1', title: 'hello'})
      })
      const action = addStimuli([
        {id: '1', stimulusBody: 'hi'},
        {id: '2', stimulusBody: 'world'}
      ])
      const nextState = stimuliReducer(initialState, action)

      const nextStimulusOne = nextState.get('1').get('stimulusBody')
      expect(nextStimulusOne).to.equal('hi')

      const nextStimulusTwo = nextState.get('2').get('stimulusBody')
      expect(nextStimulusTwo).to.equal('world')
    })
  })
})
