delete_spec.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::Ticket::Article::Delete, :aggregate_failures, type: :graphql do
  4. let(:ticket) { create(:ticket) }
  5. let(:article) { create(:ticket_article, :internal_note, ticket: ticket, created_by: user) }
  6. let(:user) { create(:agent, groups: [ticket.group]) }
  7. let(:query) do
  8. <<~QUERY
  9. mutation ticketArticleDelete($articleId: ID!) {
  10. ticketArticleDelete(articleId: $articleId) {
  11. success
  12. errors {
  13. message
  14. field
  15. }
  16. }
  17. }
  18. QUERY
  19. end
  20. let(:variables) do
  21. {
  22. articleId: gql.id(article),
  23. }
  24. end
  25. context 'when logged in as an agent', authenticated_as: :user do
  26. before { article }
  27. it 'destroys article' do
  28. expect { gql.execute(query, variables: variables) }
  29. .to change { Ticket::Article.exists? article.id }
  30. .to false
  31. end
  32. context 'when article cannot be destroyed anymore' do
  33. before { travel 1.hour }
  34. it 'fails with Pundit error' do
  35. travel 1.hour
  36. expect { gql.execute(query, variables: variables) }
  37. .not_to change { Ticket::Article.exists? article.id }
  38. expect(gql.result.error_type).to eq(Pundit::NotAuthorizedError)
  39. end
  40. end
  41. end
  42. context 'when not logged in' do
  43. before do
  44. gql.execute(query, variables: variables)
  45. end
  46. it_behaves_like 'graphql responds with error if unauthenticated'
  47. end
  48. end