sla_spec.rb 2.0 KB

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