destination_time_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. require 'rails_helper'
  2. RSpec.describe Escalation::DestinationTime do
  3. let(:instance) { described_class.new start_time, span, biz }
  4. let(:start_time) { Time.current }
  5. let(:span) { 30 }
  6. let(:ticket) { create(:ticket) }
  7. let(:calendar) { create(:calendar, :'24/7') }
  8. let(:biz) { calendar.biz breaks: Escalation::TicketBizBreak.new(ticket, calendar).biz_breaks }
  9. describe '#destination_time' do
  10. subject(:result) { instance.send(:destination_time) }
  11. before do
  12. freeze_time
  13. ticket.update! state: Ticket::State.lookup(name: 'new')
  14. travel 1.hour
  15. ticket.update! state: Ticket::State.lookup(name: 'open')
  16. travel 30.minutes
  17. ticket.update! state: Ticket::State.lookup(name: 'pending close')
  18. travel 30.minutes
  19. ticket.update! state: Ticket::State.lookup(name: 'closed'), close_at: Time.current
  20. end
  21. context 'when whole span fits' do
  22. let(:start_time) { ticket.created_at }
  23. it { is_expected.to eq 90.minutes.ago }
  24. end
  25. context 'when timeframe starts before and ends after ticket life' do
  26. let(:start_time) { ticket.created_at + 75.minutes }
  27. it { is_expected.to eq 15.minutes.from_now }
  28. end
  29. context 'when timeframe starts in the middle of ticket life' do
  30. let(:start_time) { Time.current }
  31. it { is_expected.to eq 30.minutes.from_now }
  32. end
  33. end
  34. end