update_spec.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::Ticket::SharedDraft::Start::Update, type: :graphql do
  4. let(:group) { create(:group) }
  5. let(:new_group) { group }
  6. let(:shared_draft) { create(:ticket_shared_draft_start, group:) }
  7. let(:new_content) { { content: 'updated' } }
  8. let(:form_id) { '123' }
  9. let(:variables) do
  10. {
  11. sharedDraftId: gql.id(shared_draft),
  12. input: {
  13. formId: form_id,
  14. groupId: gql.id(new_group),
  15. content: new_content
  16. }
  17. }
  18. end
  19. let(:query) do
  20. <<~QUERY
  21. mutation ticketSharedDraftStartUpdate($input: TicketSharedDraftStartInput!, $sharedDraftId: ID!) {
  22. ticketSharedDraftStartUpdate(input: $input, sharedDraftId: $sharedDraftId) {
  23. sharedDraft {
  24. id
  25. }
  26. errors {
  27. message
  28. field
  29. }
  30. }
  31. }
  32. QUERY
  33. end
  34. context 'with an agent', authenticated_as: :agent do
  35. let(:access) { :create }
  36. let(:agent) do
  37. create(:agent)
  38. .tap { |elem| elem.user_groups.create!(group:, access:) if access }
  39. end
  40. context 'when agent has access to the draft group' do
  41. it 'updates the shared draft' do
  42. gql.execute(query, variables:)
  43. expect(shared_draft.reload)
  44. .to have_attributes(group:, content: new_content)
  45. end
  46. it 'returns itself' do
  47. gql.execute(query, variables:)
  48. expect(gql.result.data)
  49. .to include('sharedDraft' => include('id' => gql.id(shared_draft)))
  50. end
  51. end
  52. end
  53. it_behaves_like 'graphql responds with error if unauthenticated' do
  54. before do
  55. gql.execute(query, variables:)
  56. end
  57. end
  58. end