upsert_spec.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::Ticket::LiveUser::Upsert, :aggregate_failures, type: :graphql do
  4. context 'when visiting a ticket as a user', authenticated_as: :agent do
  5. let(:agent) { create(:agent, groups: [ticket.group]) }
  6. let(:customer) { create(:customer) }
  7. let(:ticket) { create(:ticket, customer: customer) }
  8. let(:editing) { false }
  9. let(:query) do
  10. <<~QUERY
  11. mutation ticketLiveUserUpsert($id: ID!, $app: EnumTaskbarApp!, $editing: Boolean!) {
  12. ticketLiveUserUpsert(id: $id, app: $app, editing: $editing) {
  13. success
  14. errors {
  15. message
  16. field
  17. }
  18. }
  19. }
  20. QUERY
  21. end
  22. let(:variables) do
  23. {
  24. id: gql.id(ticket),
  25. app: 'mobile',
  26. editing: editing,
  27. }
  28. end
  29. before do
  30. freeze_time
  31. create(:taskbar, key: "Ticket-#{ticket.id}", user_id: customer.id, app: 'mobile')
  32. end
  33. context 'without own live user entry' do
  34. context 'without editing the ticket' do
  35. it 'adds the live user entry' do
  36. expect { gql.execute(query, variables: variables) }.to change(Taskbar, :count).by(1)
  37. end
  38. end
  39. context 'with editing the ticket' do
  40. let(:editing) { true }
  41. it 'adds the live user entry' do
  42. expect { gql.execute(query, variables: variables) }.to change(Taskbar, :count).by(1)
  43. end
  44. end
  45. end
  46. context 'with already existing live user entry for own user' do
  47. before do
  48. # Create already existing item.
  49. create(:taskbar, key: "Ticket-#{ticket.id}", user_id: agent.id, app: 'mobile')
  50. travel 30.minutes
  51. end
  52. context 'with editing the ticket' do
  53. let(:editing) { true }
  54. it 'updates the live user entry' do
  55. expect { gql.execute(query, variables: variables) }.not_to change(Taskbar, :count)
  56. end
  57. end
  58. end
  59. end
  60. end