tickets_by_overview_spec.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::TicketsByOverview, type: :graphql do
  4. context 'when fetching ticket overviews' do
  5. let(:agent) { create(:agent) }
  6. let(:query) do
  7. <<~QUERY
  8. query ticketsByOverview(
  9. $overviewId: ID!
  10. $orderBy: String
  11. $orderDirection: EnumOrderDirection
  12. $cursor: String
  13. $pageSize: Int = 10
  14. ) {
  15. ticketsByOverview(
  16. overviewId: $overviewId
  17. orderBy: $orderBy
  18. orderDirection: $orderDirection
  19. after: $cursor
  20. first: $pageSize
  21. ) {
  22. totalCount
  23. edges {
  24. node {
  25. id
  26. internalId
  27. number
  28. }
  29. }
  30. }
  31. }
  32. QUERY
  33. end
  34. let(:variables) { { overviewId: gql.id(overview), showPriority: true, showUpdatedBy: true } }
  35. let(:overview) { Overview.find_by(link: 'all_unassigned') }
  36. let!(:ticket) { create(:ticket) }
  37. before do
  38. gql.execute(query, variables: variables)
  39. end
  40. context 'with an agent', authenticated_as: :agent do
  41. context 'with visible tickets' do
  42. let(:agent) { create(:agent, groups: [ticket.group]) }
  43. it 'fetches a ticket' do
  44. expect(gql.result.nodes.first).to include('number' => ticket.number)
  45. end
  46. it 'has total_count' do
  47. expect(gql.result.data[:totalCount]).to eq(1)
  48. end
  49. end
  50. context 'without visible tickets' do
  51. it 'fetches no ticket' do
  52. expect(gql.result.nodes).to eq([])
  53. end
  54. it 'has total_count' do
  55. expect(gql.result.data[:totalCount]).to be_zero
  56. end
  57. end
  58. end
  59. context 'with a customer', authenticated_as: :customer do
  60. let(:customer) { create(:customer) }
  61. it 'raises authorization error' do
  62. expect(gql.result.error_type).to eq(Exceptions::Forbidden)
  63. end
  64. end
  65. it_behaves_like 'graphql responds with error if unauthenticated'
  66. end
  67. end