{"size": 1422, "ext": "js", "max_stars_repo_path": "unlock-app/src/__tests__/reducers/accountReducer.test.js", "max_stars_repo_name": "zoek1/unlock", "max_stars_repo_stars_event_min_datetime": "2019-07-02T03:20:42.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-02T19:12:31.000Z", "max_issues_repo_path": "unlock-app/src/__tests__/reducers/accountReducer.test.js", "max_issues_repo_name": "zoek1/unlock", "max_issues_repo_issues_event_min_datetime": "2021-05-11T20:59:20.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-09T01:46:43.000Z", "max_forks_repo_path": "unlock-app/src/__tests__/reducers/accountReducer.test.js", "max_forks_repo_name": "zoek1/unlock", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 23.3114754098, "max_line_length": 82, "alphanum_fraction": 0.5956399437}
import reducer from '../../reducers/accountReducer'
import { SET_ACCOUNT, UPDATE_ACCOUNT } from '../../actions/accounts'
import { SET_PROVIDER } from '../../actions/provider'
import { SET_NETWORK } from '../../actions/network'

describe('account reducer', () => {
  const account = {
    address: '0xdeadbeaf',
    balance: '0',
  }

  it('should return the initial state', () => {
    expect.assertions(1)
    expect(reducer(undefined, {})).toEqual(null)
  })

  it('should return the initial state when receveing SET_PROVIDER', () => {
    expect.assertions(1)
    expect(
      reducer(account, {
        type: SET_PROVIDER,
      })
    ).toEqual(null)
  })

  it('should return the initial state when receveing SET_NETWORK', () => {
    expect.assertions(1)
    expect(
      reducer(account, {
        type: SET_NETWORK,
      })
    ).toEqual(null)
  })

  it('should set the account accordingly when receiving SET_ACCOUNT', () => {
    expect.assertions(1)
    expect(
      reducer(undefined, {
        type: SET_ACCOUNT,
        account,
      })
    ).toEqual(account)
  })

  it('should update an account accordingly when receiving UPDATE_ACCOUNT', () => {
    expect.assertions(1)
    const update = {
      balance: '1337',
    }
    expect(
      reducer(account, {
        type: UPDATE_ACCOUNT,
        update,
      })
    ).toEqual({
      address: account.address,
      balance: '1337',
    })
  })
})
