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

import sessionItemResultsReducer from '../sessionItemResults'

import {addSessionItemResults} from '../../actions/sessionItemResults'

describe('sessionItemResults reducer', () => {
  describe('add sessionItemResults', () => {
    it('should add sessionItemResults with ADD_SESSION_ITEM_RESULTS action', () => {
      const initialState = Map({})
      const sessionItemResults = [
        {
          position: '1',
          id: '1_1',
          score: 3.5,
          attempt: 1,
          item_id: '1',
          feedback: 'nice shot!'
        },
        {
          position: '2',
          id: '2_2',
          score: 2.5,
          attempt: 1,
          item_id: '2',
          feedback: 'what a save!'
        }
      ]

      const action = addSessionItemResults(sessionItemResults)
      const nextState = sessionItemResultsReducer(initialState, action)

      const firstScore = nextState.getIn(['1_1', 'score'])
      expect(firstScore).to.equal(3.5)

      const secondFeedback = nextState.getIn(['2_2', 'feedback'])
      expect(secondFeedback).to.equal('what a save!')
    })
  })
})
