overviews_spec.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::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 ticketOverviews($withTicketCount: Boolean!) {
  9. ticketOverviews {
  10. edges {
  11. node {
  12. id
  13. name
  14. link
  15. prio
  16. orderBy
  17. orderDirection
  18. viewColumns {
  19. key
  20. value
  21. }
  22. orderColumns {
  23. key
  24. value
  25. }
  26. active
  27. ticketCount @include(if: $withTicketCount)
  28. }
  29. }
  30. }
  31. }
  32. QUERY
  33. end
  34. let(:variables) { { withTicketCount: false } }
  35. before do
  36. gql.execute(query, variables: variables)
  37. end
  38. context 'with an agent', authenticated_as: :agent do
  39. it 'has agent overview' do
  40. expect(gql.result.nodes.first).to include('name' => 'My Assigned Tickets', 'link' => 'my_assigned', 'prio' => 1000, 'active' => true,)
  41. end
  42. it 'has view and order columns' do
  43. expect(gql.result.nodes.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(:variables) do
  62. overview
  63. { withTicketCount: false }
  64. end
  65. it 'lists view colummns correctly' do
  66. expect(gql.result.nodes.first).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.nodes.first).not_to have_key('ticketCount')
  74. end
  75. end
  76. context 'with ticket count' do
  77. let(:variables) { { withTicketCount: true } }
  78. it 'includes ticketCount field' do
  79. expect(gql.result.nodes.first['ticketCount']).to eq(0)
  80. end
  81. end
  82. end
  83. context 'with a customer', authenticated_as: :customer do
  84. let(:customer) { create(:customer) }
  85. it 'has customer overview' do
  86. expect(gql.result.nodes.first).to include('name' => 'My Tickets', 'link' => 'my_tickets', 'prio' => 1100, 'active' => true,)
  87. end
  88. end
  89. it_behaves_like 'graphql responds with error if unauthenticated'
  90. end
  91. end