destination_time_spec.rb 1.4 KB

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