sla_spec.rb 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. require 'rails_helper'
  2. require 'models/application_model_examples'
  3. require 'models/sla/has_escalation_calculation_impact_examples'
  4. RSpec.describe Sla, type: :model do
  5. it_behaves_like 'ApplicationModel', can_assets: { associations: :calendar, selectors: :condition }
  6. it_behaves_like 'HasEscalationCalculationImpact'
  7. context 'when matching Ticket' do
  8. let(:sla) { create(:sla, :condition_title, condition_title: 'matching') }
  9. let(:sla_blank) { create(:sla, :condition_blank) }
  10. let(:ticket_matching) { create(:ticket, title: 'matching title') }
  11. let(:ticket_not_matching) { create(:ticket, title: 'nope') }
  12. describe '#condition_matches?' do
  13. it 'returns true when condition matches ticket' do
  14. expect(sla).to be_condition_matches(ticket_matching)
  15. end
  16. it 'returns false when condition does not match ticket' do
  17. expect(sla).not_to be_condition_matches(ticket_not_matching)
  18. end
  19. it 'returns false when condition does not match ticket while matching tickets exist' do
  20. ticket_matching
  21. expect(sla).not_to be_condition_matches(ticket_not_matching)
  22. end
  23. it 'returns true when SLA condition is blank ticket' do
  24. expect(sla_blank).to be_condition_matches(ticket_not_matching)
  25. end
  26. end
  27. describe '.for_ticket' do
  28. it 'returns matching SLA for the ticket' do
  29. sla
  30. expect(described_class.for_ticket(ticket_matching)).to eq sla
  31. end
  32. it 'returns nil when no SLA matches ticket' do
  33. sla
  34. expect(described_class.for_ticket(ticket_not_matching)).to be_nil
  35. end
  36. it 'returns blank SLA for the ticket' do
  37. sla_blank
  38. expect(described_class.for_ticket(ticket_matching)).to eq sla_blank
  39. end
  40. it 'returns non-blank SLA over blank SLA for the ticket' do
  41. sla
  42. sla_blank
  43. expect(described_class.for_ticket(ticket_matching)).to eq sla
  44. end
  45. end
  46. end
  47. end