import TimeRecordingService from '../TimeRecordingService'

describe('TimeRecordingService', () => {
  let timer
  const updateTimeRemainingStub = sinon.stub()

  beforeEach(() => {
    const recordQuizTimeStub = (cb) => {
      cb({ timerRecording: true })
    }
    timer = new TimeRecordingService(
      recordQuizTimeStub,
      updateTimeRemainingStub
    )
  })

  afterEach(() => {
    updateTimeRemainingStub.resetHistory()
  })

  it('performs the API call immediately upon starting', () => {
    expect(updateTimeRemainingStub.callCount).to.eq(0)
    timer.start()
    expect(updateTimeRemainingStub.callCount).to.eq(1)
  })

  it('does not allow restarting', () => {
    timer.start()
    timer.stop()
    expect(() => timer.start()).to.throw(Error)
  })
})
