import { expect } from 'chai'
import Response from '../Response'

describe('Response', () => {
  describe('#constructor', () => {
    it('defaults attempt to null', () => {
      const response = new Response()
      expect(response.attempt).to.be.null()
    })

    it('defaults itemId to null', () => {
      const response = new Response()
      expect(response.itemId).to.be.null()
    })

    it('defaults largeFormatResponse to null', () => {
      const response = new Response()
      expect(response.largeFormatResponse).to.be.null()
    })

    it('defaults position to null', () => {
      const response = new Response()
      expect(response.position).to.be.null()
    })

    it('defaults userResponse to null', () => {
      const response = new Response()
      expect(response.userResponse).to.be.null()
    })

    it('defaults id to null', () => {
      const response = new Response()
      expect(response.id).to.be.null()
    })
  })

  describe('#getItem', () => {
    it('returns nothing if there is no itemId', () => {
      const response = new Response()
      expect(response.getItem()).to.be.undefined()
    })

    it('gets the session item through the helper', () => {
      const response = new Response({itemId: 'item1', id: 'id2'})
      const item = {}
      const getItem = sinon.stub().returns(item)
      const findSessionItem = sinon.stub().returns({ getItem })
      response.stateHelper = () => ({ findSessionItem })
      expect(response.getItem()).to.equal(item)
      expect(findSessionItem.calledWith('id2')).to.be.true()
      expect(getItem.called).to.be.true()
    })
  })
})
