update_spec.rb 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::Ticket::SharedDraft::Zoom::Update, type: :graphql do
  4. let(:agent) { create(:agent) }
  5. let(:ticket) { create(:ticket) }
  6. let(:shared_draft) { create(:ticket_shared_draft_zoom, ticket:) }
  7. let(:form_id) { '123' }
  8. let(:new_article) { { new_article: true } }
  9. let(:ticket_attributes) { { ticket_attributes: true } }
  10. let(:variables) do
  11. {
  12. sharedDraftId: gql.id(shared_draft),
  13. input: {
  14. formId: form_id,
  15. ticketId: gql.id(ticket),
  16. newArticle: new_article,
  17. ticketAttributes: ticket_attributes
  18. }
  19. }
  20. end
  21. let(:query) do
  22. <<~QUERY
  23. mutation ticketSharedDraftZoomUpdate($input: TicketSharedDraftZoomInput!, $sharedDraftId: ID!) {
  24. ticketSharedDraftZoomUpdate(sharedDraftId: $sharedDraftId, input: $input) {
  25. sharedDraft {
  26. id
  27. }
  28. errors {
  29. message
  30. field
  31. }
  32. }
  33. }
  34. QUERY
  35. end
  36. before do
  37. gql.execute(query, variables:)
  38. end
  39. it_behaves_like 'graphql responds with error if unauthenticated'
  40. context 'with an agent', authenticated_as: :agent do
  41. context 'with insufficient access to the draft related ticket' do
  42. it 'fails with error message' do
  43. expect(gql.result.error_message).to eq('Access forbidden by Gql::Types::TicketType')
  44. end
  45. it 'fails with error type' do
  46. expect(gql.result.error_type).to eq(Exceptions::Forbidden)
  47. end
  48. end
  49. context 'with sufficient access to the draft related ticket' do
  50. let(:agent) do
  51. create(:agent).tap do |agent|
  52. agent.user_groups.create! group: ticket.group, access: :full
  53. end
  54. end
  55. it 'updates the shared draft' do
  56. expect(shared_draft.reload).to have_attributes(new_article:, ticket_attributes:)
  57. end
  58. end
  59. end
  60. end