123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- require 'rails_helper'
- RSpec.describe Gql::Queries::Ticket::Overviews, type: :graphql do
- context 'when fetching ticket overviews' do
- let(:agent) { create(:agent) }
- let(:query) do
- <<~QUERY
- query ticketOverviews($withTicketCount: Boolean!) {
- ticketOverviews {
- edges {
- node {
- id
- name
- link
- prio
- orderBy
- orderDirection
- viewColumns {
- key
- value
- }
- orderColumns {
- key
- value
- }
- active
- ticketCount @include(if: $withTicketCount)
- }
- }
- }
- }
- QUERY
- end
- let(:variables) { { withTicketCount: false } }
- before do
- gql.execute(query, variables: variables)
- end
- context 'with an agent', authenticated_as: :agent do
- it 'has agent overview' do
- expect(gql.result.nodes.first).to include('name' => 'My Assigned Tickets', 'link' => 'my_assigned', 'prio' => 1000, 'active' => true,)
- end
- it 'has view and order columns' do
- expect(gql.result.nodes.first).to include(
- 'viewColumns' => include({ 'key' => 'title', 'value' => 'Title' }),
- 'orderColumns' => include({ 'key' => 'created_at', 'value' => 'Created at' }),
- )
- end
- context 'with object attributes and unknown attributes', db_strategy: :reset do
- let(:oa) do
- create(:object_manager_attribute_text, :required_screen).tap do
- ObjectManager::Attribute.migration_execute
- end
- end
-
- let(:overview) do
- Overview.find_by('link' => 'my_assigned').tap do |overview|
- overview.view = { 's' => [oa.name, 'unknown_field'] }
- overview.save!
- end
- end
- let(:variables) do
- overview
- { withTicketCount: false }
- end
- it 'lists view colummns correctly' do
- expect(gql.result.nodes.first).to include(
- 'viewColumns' => [ { 'key' => oa.name, 'value' => oa.display }, { 'key' => 'unknown_field', 'value' => nil }],
- )
- end
- end
- context 'without ticket count' do
- it 'does not include ticketCount field' do
- expect(gql.result.nodes.first).not_to have_key('ticketCount')
- end
- end
- context 'with ticket count' do
- let(:variables) { { withTicketCount: true } }
- it 'includes ticketCount field' do
- expect(gql.result.nodes.first['ticketCount']).to eq(0)
- end
- end
- end
- context 'with a customer', authenticated_as: :customer do
- let(:customer) { create(:customer) }
- it 'has customer overview' do
- expect(gql.result.nodes.first).to include('name' => 'My Tickets', 'link' => 'my_tickets', 'prio' => 1100, 'active' => true,)
- end
- end
- it_behaves_like 'graphql responds with error if unauthenticated'
- end
- end
|