attributes_spec.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe CoreWorkflow::Attributes, type: :model do
  4. let!(:ticket) { create(:ticket, state: Ticket::State.find_by(name: 'pending reminder'), pending_time: 5.days.from_now) }
  5. let!(:base_payload) do
  6. {
  7. 'event' => 'core_workflow',
  8. 'request_id' => 'default',
  9. 'class_name' => 'Ticket',
  10. 'screen' => 'create_middle',
  11. 'params' => {
  12. 'id' => ticket.id,
  13. 'state_id' => Ticket::State.find_by(name: 'open').id,
  14. },
  15. }
  16. end
  17. let(:payload) { base_payload }
  18. let!(:action_user) { create(:agent, groups: [ticket.group]) }
  19. let(:result) { described_class.new(result_object: CoreWorkflow::Result.new(payload: payload, user: action_user)) }
  20. describe '#payload_class' do
  21. it 'returns class' do
  22. expect(result.payload_class).to eq(Ticket)
  23. end
  24. end
  25. describe '#selected_only' do
  26. it 'returns state open' do
  27. expect(result.selected_only.state.name).to eq('open')
  28. end
  29. end
  30. describe '#selected' do
  31. it 'returns state open' do
  32. expect(result.selected.state.name).to eq('open')
  33. end
  34. end
  35. describe '#saved_only' do
  36. it 'returns state pending reminder' do
  37. expect(result.saved_only.state.name).to eq('pending reminder')
  38. end
  39. end
  40. describe '#saved' do
  41. it 'returns state pending reminder' do
  42. expect(result.saved.state.name).to eq('pending reminder')
  43. end
  44. end
  45. describe '#mandatory_default' do
  46. it 'priority should be mandatory by default' do
  47. expect(result.mandatory_default['priority_id']).to be true
  48. end
  49. end
  50. describe '#visibility_default' do
  51. it 'priority should be shown by default' do
  52. expect(result.visibility_default['priority_id']).to eq('show')
  53. end
  54. end
  55. end