import { fromJS } from 'immutable'

import reducer from '../sharedBanks'

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

describe('sharedBanks reducer', () => {
  describe('shareBanks', () => {
    it('updates state correctly', () => {
      const initialState = fromJS({1: {id: 1, uuid: '1', bankId: '1', permission: 'canEdit'}, 2: {id:2, uuid: '2', bankId: '2', permission: 'canEdit'}})
      const action = actions.addSharedBanks({3: {id: 3, uuid: '3', bankId: '3', permission: 'canEdit'}})
      const nextState = reducer(initialState, action)

      expect(nextState.getIn(['1', 'bankId'])).to.eq('1')
      expect(nextState.getIn(['3', 'bankId'])).to.eq('3')
    })
  })

  describe('removeBanks', () => {
    it('updates state correctly', () => {
      const initialState = fromJS({1: {id: 1, uuid: '1', bankId: '1', permission: 'canEdit'}, 2: {id:2, uuid: '2', bankId: '2', permission: 'canEdit'}})
      const action = actions.removeSharedBank('3')
      const nextState = reducer(initialState, action)

      expect(nextState.getIn(['1', 'bankId'])).to.eq('1')
      expect(nextState.getIn(['3', 'bankId'])).to.be.undefined()
    })
  })
})
