overviews_spec.rb 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::User::Current::Ticket::Overviews, type: :graphql do
  4. context 'when fetching ticket overviews' do
  5. let(:agent) { create(:agent) }
  6. let(:query) do
  7. <<~QUERY
  8. query userCurrentTicketOverviews($ignoreUserConditions: Boolean!, $withTicketCount: Boolean!) {
  9. userCurrentTicketOverviews(ignoreUserConditions: $ignoreUserConditions) {
  10. id
  11. name
  12. link
  13. prio
  14. orderBy
  15. orderDirection
  16. viewColumns {
  17. key
  18. value
  19. }
  20. orderColumns {
  21. key
  22. value
  23. }
  24. active
  25. ticketCount @include(if: $withTicketCount)
  26. }
  27. }
  28. QUERY
  29. end
  30. let(:ignore_user_conditions) { false }
  31. let(:with_ticket_count) { false }
  32. let(:variables) { { withTicketCount: with_ticket_count, ignoreUserConditions: ignore_user_conditions } }
  33. before do
  34. create(:user_overview_sorting, overview: Overview.find_by(name: 'My Assigned Tickets'), prio: 2, user: agent)
  35. create(:user_overview_sorting, overview: Overview.find_by(name: 'Unassigned & Open Tickets'), prio: 1, user: agent)
  36. gql.execute(query, variables: variables)
  37. end
  38. context 'with an agent', authenticated_as: :agent do
  39. it 'has agent overview with personal sorting' do
  40. expect(gql.result.data.first).to include('name' => 'Unassigned & Open Tickets', 'link' => 'all_unassigned', 'prio' => 1010, 'active' => true,)
  41. end
  42. it 'has view and order columns' do
  43. expect(gql.result.data.first).to include(
  44. 'viewColumns' => include({ 'key' => 'title', 'value' => 'Title' }),
  45. 'orderColumns' => include({ 'key' => 'created_at', 'value' => 'Created at' }),
  46. )
  47. end
  48. context 'with object attributes and unknown attributes', db_strategy: :reset do
  49. let(:oa) do
  50. create(:object_manager_attribute_text, :required_screen).tap do
  51. ObjectManager::Attribute.migration_execute
  52. end
  53. end
  54. # Change the overview to include an object attribute column and a column that has an unknown field.
  55. let(:overview) do
  56. Overview.find_by('link' => 'my_assigned').tap do |overview|
  57. overview.view = { 's' => [oa.name, 'unknown_field'] }
  58. overview.save!
  59. end
  60. end
  61. let(:with_ticket_count) do
  62. overview
  63. false
  64. end
  65. it 'lists view colummns correctly' do
  66. expect(gql.result.data.second).to include(
  67. 'viewColumns' => [ { 'key' => oa.name, 'value' => oa.display }, { 'key' => 'unknown_field', 'value' => nil }],
  68. )
  69. end
  70. end
  71. context 'without ticket count' do
  72. it 'does not include ticketCount field' do
  73. expect(gql.result.data.first).not_to have_key('ticketCount')
  74. end
  75. end
  76. context 'with ticket count' do
  77. let(:with_ticket_count) { true }
  78. it 'includes ticketCount field' do
  79. expect(gql.result.data.first['ticketCount']).to eq(0)
  80. end
  81. end
  82. context 'when not ignoring user conditions' do
  83. it 'does not include replacement tickets overview' do
  84. expect(gql.result.data).not_to include(include('name' => 'My Replacement Tickets'))
  85. end
  86. end
  87. context 'when ignoring user conditions' do
  88. let(:ignore_user_conditions) { true }
  89. it 'includes replacement tickets overview' do
  90. expect(gql.result.data).to include(include('name' => 'My Replacement Tickets'))
  91. end
  92. end
  93. end
  94. context 'with a customer', authenticated_as: :customer do
  95. let(:customer) { create(:customer) }
  96. it 'has customer overview' do
  97. expect(gql.result.data.first).to include('name' => 'My Tickets', 'link' => 'my_tickets', 'prio' => 1100, 'active' => true,)
  98. end
  99. end
  100. it_behaves_like 'graphql responds with error if unauthenticated'
  101. end
  102. end