delete_spec.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::Ticket::LiveUser::Delete, :aggregate_failures, type: :graphql do
  4. context 'when deleting live user entry', authenticated_as: :agent do
  5. let(:agent) { create(:agent, groups: [ticket.group]) }
  6. let(:ticket) { create(:ticket) }
  7. let(:live_user_entry) { create(:taskbar, key: "Ticket-#{ticket.id}", user: agent, app: 'mobile') }
  8. let(:query) do
  9. <<~QUERY
  10. mutation ticketLiveUserDelete($id: ID!, $app: EnumTaskbarApp!) {
  11. ticketLiveUserDelete(id: $id, app: $app) {
  12. success
  13. errors {
  14. message
  15. field
  16. }
  17. }
  18. }
  19. QUERY
  20. end
  21. let(:variables) { { id: gql.id(ticket), app: 'mobile' } }
  22. before do
  23. live_user_entry
  24. gql.execute(query, variables: variables)
  25. end
  26. context 'when live user entry does exist' do
  27. it 'does delete' do
  28. expect(live_user_entry.class).not_to exist(live_user_entry.id)
  29. end
  30. it 'returns success' do
  31. expect(gql.result.data['success']).to be true
  32. end
  33. end
  34. context 'when live user entry does not exist (user id mismatch)' do
  35. let(:live_user_entry) { create(:taskbar, key: "Ticket-#{ticket.id}", user: User.find(1)) }
  36. it 'does not delete' do
  37. expect(live_user_entry.class).to exist(live_user_entry.id)
  38. end
  39. end
  40. context 'when live user entry does not exist (app mismatch)' do
  41. let(:live_user_entry) { create(:taskbar, key: "Ticket-#{ticket.id}", user: agent, app: 'desktop') }
  42. it 'does not delete' do
  43. expect(live_user_entry.class).to exist(live_user_entry.id)
  44. end
  45. end
  46. it_behaves_like 'graphql responds with error if unauthenticated'
  47. end
  48. end