create_spec.rb 1.5 KB

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