import { fromJS } from 'immutable'

import reducer from '../bankEntries'

import * as actions from '../../actions/bankEntries'

describe('bank entries reducer', () => {
  const initialState = fromJS({1: {id: '1', entry: '399'}, 2: {id: '2', entry: '400'}})

  describe('addBankEntries', () => {
    it('updates state correctly', () => {
      const action = actions.addBankEntries([{id: '3', entry: '401'}])
      const nextState = reducer(initialState, action)

      expect(nextState.getIn(['1', 'entry'])).to.eq('399')
      expect(nextState.getIn(['3', 'entry'])).to.eq('401')
    })
  })

  describe('default', () => {
    it('does not update state', () => {
      const action = { action: 'IRRELEVANT_ACTION', payload: [] }
      const nextState = reducer(initialState, action)

      expect(nextState).to.eq(initialState)
    })
  })

  it('handles ARCHIVE_BANK_ENTRY', () => {
    const nextState = reducer(initialState, actions.archiveBankEntry('2'))
    expect(nextState.get('2').toJS()).to.deep.equal({
      id: '2',
      entry: '400',
      archived: true
    })
  })
})
