create_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::Ticket::SharedDraft::Zoom::Create do
  4. let(:user) { create(:agent) }
  5. let(:ticket) { create(:ticket) }
  6. let(:form_id) { 123 }
  7. let(:new_article) { { new_article: true } }
  8. let(:ticket_attributes) { { ticket_attributes: true } }
  9. context 'when user has insufficient acces to the draft related ticket' do
  10. it 'raises an error' do
  11. expect do
  12. described_class
  13. .new(user, form_id, ticket:, new_article:, ticket_attributes:)
  14. .execute
  15. end.to raise_error(Pundit::NotAuthorizedError)
  16. end
  17. end
  18. context 'when user has sufficient access to the draft related ticket' do
  19. before do
  20. user.user_groups.create! group: ticket.group, access: :full
  21. end
  22. it 'creates a shared draft' do
  23. expect do
  24. described_class
  25. .new(user, form_id, ticket:, new_article:, ticket_attributes:)
  26. .execute
  27. end.to change(Ticket::SharedDraftZoom, :count).by(1)
  28. end
  29. it 'copies attachments from the given form' do
  30. create(:store, o_id: form_id)
  31. draft = described_class
  32. .new(user, form_id, ticket:, new_article:, ticket_attributes:)
  33. .execute
  34. expect(Store.list(object: draft.class.name, o_id: draft.id))
  35. .to contain_exactly(have_attributes(filename: 'test.txt'))
  36. end
  37. end
  38. end