create_spec.rb 2.0 KB

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