validator_spec.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::Ticket::Update::Validator, current_user_id: 1 do
  4. subject(:validator) { described_class.new(user: user, ticket: ticket, ticket_data: ticket_data, article_data: article_data, skip_validators: skip_validators) }
  5. let(:user) { create(:agent, groups: [group]) }
  6. let(:ticket) { create(:ticket) }
  7. let(:group) { ticket.group }
  8. let(:new_title) { Faker::Lorem.unique.word }
  9. let(:ticket_data) { { title: new_title } }
  10. let(:article_data) { nil }
  11. let(:skip_validators) { nil }
  12. describe '#validate!' do
  13. it 'does not raise an error' do
  14. expect { validator.validate! }.not_to raise_error
  15. end
  16. context 'when ticket with a checklist is being closed' do
  17. let(:checklist) { create(:checklist, ticket: ticket) }
  18. let(:ticket_data) { { state: Ticket::State.find_by(name: 'closed') } }
  19. before do
  20. checklist
  21. end
  22. it 'raises an error' do
  23. expect { validator.validate! }.to raise_error(Service::Ticket::Update::Validator::ChecklistCompleted::Error, 'The ticket checklist is incomplete.')
  24. end
  25. context 'when validator is being skipped' do
  26. let(:skip_validators) { [Service::Ticket::Update::Validator::ChecklistCompleted::Error] }
  27. it 'does not raise an error' do
  28. expect { validator.validate! }.not_to raise_error
  29. end
  30. end
  31. end
  32. end
  33. end