import BankEntry from '../BankEntry'

import {
  TEMPORARY_ITEM_ID,
  TEMPORARY_STIMULUS_ID
} from '@instructure/quiz-common/lib/constants'

describe('BankEntry Record', () => {
  describe('#getEntry', () => {
    const returnsEntryOfType = (constructorType, entryId) => {
      it('returns correct entry', () => {
        const bankEntry = new BankEntry({entryType: constructorType, entry: {get: () => {}}})
        expect(bankEntry.getEntry().constructor.name).to.equal(constructorType)
      })

      it('returns correct temporary entry', () => {
        const tempBankEntry = new BankEntry({entryType: constructorType, entry: entryId})
        expect(tempBankEntry.getEntry().constructor.name).to.equal(constructorType)
      })
    }

    context('item', () => {
      returnsEntryOfType('Item', TEMPORARY_ITEM_ID)
    })

    context('stimulus', () => {
      returnsEntryOfType('Stimulus', TEMPORARY_STIMULUS_ID)
    })
  })

  describe('#isStimulus', () => {
    it('returns true when stimulus entry type', () => {
      const bankEntry = new BankEntry({ entryType: 'Stimulus' })
      expect(bankEntry.isStimulus).to.be.true()
    })

    it('returns false when item entry type', () => {
      const bankEntry = new BankEntry({ entryType: 'Item' })
      expect(bankEntry.isStimulus).to.be.false()
    })
  })
})
