update_spec.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::Ticket::SharedDraft::Zoom::Update do
  4. let(:user) { create(:agent) }
  5. let(:ticket) { create(:ticket) }
  6. let(:shared_draft) { create(:ticket_shared_draft_zoom, ticket: ticket) }
  7. let(:form_id) { 123 }
  8. let(:new_article) { { new_article: false } }
  9. let(:ticket_attributes) { { ticket_attributes: false } }
  10. context 'when user has insufficient acces to the draft related ticket' do
  11. it 'raises an error' do
  12. expect do
  13. described_class
  14. .new(user, form_id, shared_draft, new_article:, ticket_attributes:)
  15. .execute
  16. end.to raise_error(Pundit::NotAuthorizedError)
  17. end
  18. end
  19. context 'when user has sufficient access to the draft related ticket' do
  20. before do
  21. user.user_groups.create! group: ticket.group, access: :full
  22. end
  23. it 'updates the shared draft' do
  24. described_class
  25. .new(user, form_id, shared_draft, new_article:, ticket_attributes:)
  26. .execute
  27. expect(shared_draft.reload.new_article.symbolize_keys).to eq(new_article)
  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, shared_draft, 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