unsubscribe_spec.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::Mention::Unsubscribe, :aggregate_failures, type: :graphql do
  4. let(:agent) { create(:agent, groups: [object.group]) }
  5. let(:object) { Ticket.first }
  6. let(:query) do
  7. <<~QUERY
  8. mutation mentionUnsubscribe($objectId: ID!) {
  9. mentionUnsubscribe(objectId: $objectId) {
  10. success
  11. errors {
  12. message
  13. field
  14. }
  15. }
  16. }
  17. QUERY
  18. end
  19. let(:variables) do
  20. {
  21. objectId: gql.id(object),
  22. }
  23. end
  24. context 'when logged in as an agent', authenticated_as: :agent do
  25. it 'unsubscribes from a ticket' do
  26. allow(Mention).to receive(:unsubscribe!)
  27. gql.execute(query, variables: variables)
  28. expect(Mention).to have_received(:unsubscribe!).with(object, agent)
  29. end
  30. end
  31. context 'with GQL query' do
  32. before do
  33. gql.execute(query, variables: variables)
  34. end
  35. it_behaves_like 'graphql responds with error if unauthenticated'
  36. end
  37. end