import { expect } from 'chai'
import { fromJS } from 'immutable'
import values from 'lodash/values'
import valMap from '../valMap'

describe('valMap', () => {
  it('applies the given function to the values of a hash without mutation', () => {
    const someHash = {1: 'a', 2: 'b', 3: 'c'}
    const testFn = (s) => {
      return s.toUpperCase()
    }

    const mappedHash = valMap(someHash, testFn)
    const mappedVals = values(mappedHash)
    // check for function application
    expect(
      fromJS(mappedVals)
    ).to.be.deep.equal(
      fromJS(['A', 'B', 'C'])
    )

    // check for no mutation
    const originalVals = values(someHash)
    expect(
      fromJS(originalVals)
    ).to.be.deep.equal(
      fromJS(['a', 'b', 'c'])
    )
  })
})
