import { expect } from 'chai'
import {
  addQuizEntries,
  addQuizEntry,
  deleteQuizEntry,
  deleteStimulusEntry,
  moveQuizEntry
} from '../quizEntries'
import {
  ADD_QUIZ_ENTRIES,
  ADD_QUIZ_ENTRY,
  DELETE_QUIZ_ENTRY,
  DELETE_STIMULUS_ENTRY,
  MOVE_QUIZ_ENTRY
} from '@instructure/quiz-common/lib/constants'

describe('quizzes entries action creators', () => {
  it('returns a well-formed start edit action', () => {
    const setOfQuizEntries = {99: {id: '99'}}
    const addQuizEntriesAction = addQuizEntries(setOfQuizEntries)

    expect(addQuizEntriesAction)
      .to.deep.equal({
        type: ADD_QUIZ_ENTRIES,
        payload: setOfQuizEntries
      })
  })

  it('returns a well-formed action for adding single quizEntry', () => {
    const quizEntryAction = addQuizEntry({id: '99'})

    expect(quizEntryAction).to.deep.eq({
      type: ADD_QUIZ_ENTRY,
      payload: {id: '99'}
    })
  })

  it('returns a well-formed action for deleting a quiz entry', () => {
    const deleteAction = deleteQuizEntry('42')

    expect(deleteAction).to.deep.equal({
      type: DELETE_QUIZ_ENTRY,
      payload: { id: '42' }
    })
  })

  it('returns a well-formed action for deleting a stimulus entry', () => {
    const deleteAction = deleteStimulusEntry('42', ['4', '6'])

    expect(deleteAction).to.deep.equal({
      type: DELETE_STIMULUS_ENTRY,
      payload: {
        id: '42',
        childQuizEntryIds: ['4', '6']
      }
    })
  })

  it('returns a well-formed action for moving an entry', () => {
    const moveAction = moveQuizEntry('42', 3, '7')

    expect(moveAction).to.deep.equal({
      type: MOVE_QUIZ_ENTRY,
      payload: {
        id: '42',
        position: 3,
        stimulusQuizEntryId: '7'
      }
    })
  })
})
