import {
  CALL_STATUS,
  SET_CALLBACKS_STATUS
} from '@instructure/quiz-common/lib/constants'

import {
  callbacksCompleteForCall,
  errorCallFor,
  startCallFor,
  successCallFor
} from '../callHelpers'

describe('callHelpers', () => {
  function callHelpersTests (
    actionCreator,
    expectedStatus,
    expectedType = CALL_STATUS
  ) {
    const SomeType = 'SomeType'
    const action = actionCreator(SomeType)
    it('creates an action object with type CALL_STATUS', () => {
      expect(action.type).to.be.equal(expectedType)
    })

    it('has a payload with the right call and status', () => {
      expect(action.payload.call).to.be.equal(SomeType)
      expect(action.payload.status).to.be.equal(expectedStatus)
    })
  }

  describe('#startCallFor', () => {
    callHelpersTests(startCallFor, 'calling')
  })
  describe('#successCallFor', () => {
    callHelpersTests(successCallFor, 'success')
  })
  describe('#errorCallFor', () => {
    callHelpersTests(errorCallFor, 'error')
  })
  describe('#callbacksCompleteForCall', () => {
    callHelpersTests(callbacksCompleteForCall, 'complete', SET_CALLBACKS_STATUS)
  })
})
