change_visibility_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::Ticket::Article::ChangeVisibility, :aggregate_failures, type: :graphql do
  4. let(:article) { create(:ticket_article) }
  5. let(:agent) { create(:agent, groups: [article.ticket.group]) }
  6. let(:query) do
  7. <<~QUERY
  8. mutation ticketArticleChangeVisibility($articleId: ID!, $internal: Boolean!) {
  9. ticketArticleChangeVisibility(articleId: $articleId, internal: $internal) {
  10. article {
  11. id
  12. }
  13. errors {
  14. message
  15. field
  16. }
  17. }
  18. }
  19. QUERY
  20. end
  21. let(:variables) do
  22. {
  23. articleId: gql.id(article),
  24. internal: true
  25. }
  26. end
  27. context 'when logged in as an agent', authenticated_as: :agent do
  28. it 'delegates to the service' do
  29. log = []
  30. allow_any_instance_of(Service::Ticket::Article::ChangeVisibility)
  31. .to receive(:execute) do |article:, internal:|
  32. log << { article: article.id, internal: internal }
  33. end
  34. gql.execute(query, variables: variables)
  35. expect(log).to include(include(article: article.id, internal: true))
  36. end
  37. end
  38. context 'when not logged in' do
  39. before do
  40. gql.execute(query, variables: variables)
  41. end
  42. it_behaves_like 'graphql responds with error if unauthenticated'
  43. end
  44. end